Enhance by-ref struct argument reference API#741
Open
zvirja wants to merge 8 commits intocastleproject:masterfrom
Open
Enhance by-ref struct argument reference API#741zvirja wants to merge 8 commits intocastleproject:masterfrom
zvirja wants to merge 8 commits intocastleproject:masterfrom
Conversation
Do not use Volatile anymore, as code is single-threaded now. Also use void* to simplify code
By it's nature Unsafe methods are not a part of the "client" API, so we just provide it on a side and should no longer hide methods/constructors from user. Also unsafe API is internal on the original class, so it's not immediately visible to the users.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This PR follows up and addresses the issues discussed in #663. I implemented the last proposal and suggest to incorporate it to the initial API. It all looks good to me and I don't see any safety issues with this revision of the API.
Tasks:
scopedlifetime arguments and track it.I expose flag via
ByRefLikeReferenceUnsafe, as libraries might be interested in checking it. I hide it from "main" API as it's a very niche check and it might be confusing to the direct consumers.GetValue/UseValueandSetValueUseValue()could be used for any reference. It's just a bit inconvenient and more restrictiveGetValue()could be used only if value is notscoped(which shall be vast majority of the cases)SetValue()requires a lambda, so that we could be sure that local stack-based value could not be leaked. Compiler will guarantee safety, as lambda could be invoked at any time.ByRefLikeReferenceUnsafeclass and hide all the unawanted API there, while making the original API internal. It allows to get rid of public IDE-hidden API with warnings in the doc, as now the API is simply not immediately visible. If you are usingUnsafeclass - the name kind of implies that you are knowing what you are doing.I also applied a few cosmetic changes:
void*type to store theptr- looks nicerInvalidate()toDispose()- as that's exactly what it isGetPtrNocheck()and useGetPtr()- simpler code + adds better visibilityFeel free to play with the code and apply the necessary changes. My PR is just a proposal.
I could help with the documentation before merge if we agree what it's what we are going with. Didn't want to invest time if we decide to discard it all (which would be sad :-/).
FYI @stakx
P.S.
MethodInvocationExpressionAPI is really confusing. I would expect that ctor overload withoutinstancewould imply a static method call - not the implicitthiscall. Took me quite a while to figure out what's going on.