-
Notifications
You must be signed in to change notification settings - Fork 87
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Introducing logical collection pointers #393
Merged
Merged
Conversation
This file contains 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
Merged
11 tasks
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 does few things:
1. Introduce
Hook
andBranchID
While shared collections are all represented by
BranchPtr
, this is basically an unsafe wrapper around branch reference. In case when the underlying block is deleted and garbage collected (like in case when a nested type or entire document is dropped), this pointer is no longer valid and attempt to using it would result in segfault.Important
While eventually we want to get rid of this behaviour properly, at the current stage this change would be even bigger and more invasive in the library API. For this reason we have an intermediary solution described bellow.
We exposed a new logical accessors, that don't issue segfaults at the cost of longer access. They are called hooks:
Hooks also expose so-called
BranchID
which is basically an identifier od a reference, but unlikeHook
it doesn't carry shared collection type info.2. Rewrite of
ywasm
Ywasm (yrs-based JS variant using WebAssembly) has been rewritten to accommodate new
Hook
API, this way we don't have to worry about segfaults inside of WASM virtual machine. There's also a number of other improvements:YXmlElement
/YXmlFragment
/YXmlText
now have preliminary type representation. Methods likexmlElem.insertXmlText
have been removed - now you can just usexmlElem.insert(new YXmlText(''))
.type
andid
properties, which inform about the type ID andBranchID
of a current type.Doc.getXmlElement
andDoc.getXmlText
methods have been removed - they never worked right as root level types in the first place due to limitations of lib0 encoding. If you need, useDoc.getXmlFragment
and nest your XML nodes inside of it instead.3. Updates to
yffi
yxmlelem
andyxmltext
methods have been removed - they never worked right as root level types in the first place due to limitations of lib0 encoding. If you need, useyxmlfragment
and nest your XML nodes inside of it instead.yunobserve(Subscription*)
.ytransaction_alive
is replaced byybranch_alive(Branch*)
.Hooks
andBranchID
s are especially important from the PoV of unmanaged C code, they have been exposed:YBranchID
is a C-compatible logical identifier of aBranch*
. Just like described above it works across different docs. It's standard struct so it doesn't need manual memory freeing, however since root-level type identification is string-based, the YBranchID name pointer is valid as long as the document from which it has been generated from is alive. You could work around that by constructingYBranchID
manually.YBranchID
can be obtained from any alive branch viaybranch_id(Branch*)
Branch*
can be resolved viaybranch_get(YBranchId*, YTransaction*)
. If branch ID points to a collection which has been already garbage collected, aNULL
will be returned.