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

HPyBytes_AsString should return const char pointer. #383

Merged
merged 8 commits into from
Nov 28, 2022

Conversation

fangerer
Copy link
Contributor

Resolves #183 .

I've also implemented data pointer usage verification in debug mode. If the data pointer is written or used after the handle was closed, the process will crash because we protect the pages appropriately (just line we do for HPyUnicode_AsUTF8AndSize.

I also took the opportunity to implement the functionality on Windows as well.

Copy link
Contributor

@mattip mattip left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A few small nits, but looks good to me, thanks

@@ -145,7 +145,7 @@ typedef struct {

#define HPyDef_METH_IMPL(SYM, NAME, IMPL, SIG, ...) \
HPyFunc_DECLARE(IMPL, SIG); \
HPyFunc_TRAMPOLINE(SYM##_trampoline, IMPL, SIG); \
HPyFunc_TRAMPOLINE(SYM##_trampoline, IMPL, SIG) \
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this on purpose? Even though it is not needed, I think it improves code readability

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, that's on purpose. I sometimes add -pedantic to tests compilation to spot possible problems and this was one of the warnings since the macro expands to several statements and this semicolon is not necessary.
But I don't have a strong opinion. If you want to keep it, I can re-introduce it but I would like to do it in a follow-up PR to save CI time.

assert b"UnicodeDecodeError" in result.stderr
content = "'use after close me!'"
bcontent = "b" + content
for mode, msg in enumerate((content, bcontent, bcontent)):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This could be a paramterize() decorator, but then the test would compile the module three times, so better as-is.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, that was basically the intention. Whenever I write new tests, I try to group conceptually equal tests to reduce compilation since that seems to increase test time significantly.
It would be nice if we could use parameterize. Maybe we can have a fixture or closure such that the module is compiled just once per session.

@@ -64,6 +64,7 @@ static DHPy _DHPy_open(HPyContext *dctx, UHPy uh, bool is_immortal)
handle->is_closed = 0;
handle->is_immortal = is_immortal;
handle->associated_data = NULL;
handle->associated_data_size = 0;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This wasn't zeroed out before? Good catch.

@mattip
Copy link
Contributor

mattip commented Nov 28, 2022

I also took the opportunity to implement the functionality on Windows as well.

nice

@fangerer fangerer merged commit c04c33b into hpyproject:master Nov 28, 2022
@fangerer fangerer deleted the fa/bytes_asstring_const_charptr branch November 28, 2022 15:58
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.

HPyBytes_AsString should return const char*
2 participants