Skip to content

Hide JanetMarshalContext implementation details#1747

Merged
bakpakin merged 1 commit into
janet-lang:masterfrom
iceghost:push-vopsuxmnlwwz
May 16, 2026
Merged

Hide JanetMarshalContext implementation details#1747
bakpakin merged 1 commit into
janet-lang:masterfrom
iceghost:push-vopsuxmnlwwz

Conversation

@iceghost

Copy link
Copy Markdown
Contributor

This hides JanetMarshalContext behind an opaque pointer, and splits it into two separate Context type for marshal and unmarshal.

The motivation was my confusion while working with this type because the same context type was used for both marshal/unmarshal context, despite containing almost nothing in common, and you cannot certainly use a context that was created for marshal operation for unmarshalling.

This will break current users with compile errors due to the different pointer type on the vtable now, but the ABI should remain the same with the pointer argument.


I hope this is not a very controversal change :D I noticed this when trying to stub out the implementation in my Zig port, so thought I would try to also upstream this while I can

@bakpakin

Copy link
Copy Markdown
Member

So this looks functionally fine, but I don't want to break backwards compatibility at the API level. I think some kind of migration at the API level would be desirable to enable this though, perhaps an alias like typedef JanetUnmarshalContext JanetMarshalContext for the meantime. Essentially, I want a simple way to write C that will compile correctly for all recent Janet versions.

This hides JanetMarshalContext behind an opaque pointer. User of this
struct should use the public API instead of using those internal
implementation details.
@iceghost

Copy link
Copy Markdown
Contributor Author

I see, then I think I will revert my MarshalContext/UnmarshalContext switch, and only keep the opaque MarshalContext part. Making MarshalContext no longer part of the ABI is valuable enough for me.

@iceghost iceghost force-pushed the push-vopsuxmnlwwz branch from ba52600 to 7e17376 Compare May 15, 2026 02:10
@iceghost iceghost changed the title Makes marshal/unmarshal more type safe Hide JanetMarshalContext implementation details May 15, 2026
@bakpakin bakpakin merged commit e663aa9 into janet-lang:master May 16, 2026
18 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants