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

Fix handling of invalid utf-8 sequences in PyString::to_string_lossy #642

Merged
merged 1 commit into from
Oct 25, 2019

Conversation

Alexander-N
Copy link
Member

See discussion in #479 and #634.

// Since we have a valid PyString and replace any surrogates, assume success.
debug_assert!(!py_bytes.is_null());
// ensure DECREF will be called
self.py().from_owned_ptr::<PyBytes>(py_bytes);
Copy link
Member

Choose a reason for hiding this comment

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

How about crate::gil::register_pointer?(My snippet was incorrect, sorry)

Copy link
Member Author

Choose a reason for hiding this comment

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

Ok, done. What's the difference?

Copy link
Member

Choose a reason for hiding this comment

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

  1. Less overhead.
  2. Our GIL pool has 3 types of buffer(owned ref, borrowed ref, pointer).
    In this case, we can use both owned and pointer buffer.
    But pointer buffer is preferable for the case GILGuard drops earlier(I'll add an example but have no time now 😓 ).

@kngwyu
Copy link
Member

kngwyu commented Oct 24, 2019

Thanks!

@kngwyu kngwyu merged commit 30485f3 into PyO3:master Oct 25, 2019
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