Skip to content
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

File IO incompatible with custom context #110

Open
Dolkar opened this issue Apr 21, 2024 · 2 comments
Open

File IO incompatible with custom context #110

Dolkar opened this issue Apr 21, 2024 · 2 comments

Comments

@Dolkar
Copy link

Dolkar commented Apr 21, 2024

All of the functions that operate on files, such as mpack_reader_init_filename store the file handle in the custom context. This means that the context can't be set by the user to anything else, like for use in error handlers.

I feel like either the file IO helpers should use their own, separate context, or it should be documented that calling mpack_reader_set_context and similar is not allowed when file IO is used.

@ludocode
Copy link
Owner

The only purpose of the context is for callbacks like fill, flush, etc. mpack_reader_init_filename() installs its own fill and destroy callbacks so it uses the context. The documentation of mpack_reader_set_context() does indeed say that the context is for callbacks.

I suppose I could clarify the documentation of functions like mpack_reader_init_filename() to say that they install callbacks and use the context so you can't use your own callbacks and context with them.

Is the problem that you are trying to use an error callback with your own context? It occurred to me that the reader doesn't install an error callback; that's the only reason I can think of to want to use your own context. In that case you're probably right, and I should make these functions use their own context.

As a workaround you could wrap the reader in a struct with your context. You could then cast a pointer from the reader to the containing struct.

@Dolkar
Copy link
Author

Dolkar commented Apr 24, 2024

Yes, my intention was to have error callbacks with my own context while reading out of a file. I suppose you're right that there isn't much of a need to set your own context otherwise, so apologies for overgeneralizing the problem.

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

No branches or pull requests

2 participants