Skip to content

MNT: migrate away from deprecated c-api #17680

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

Merged
merged 1 commit into from
Jun 20, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 2 additions & 3 deletions src/ft2font_wrapper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -635,11 +635,10 @@ static PyObject *PyFT2Font_set_text(PyFT2Font *self, PyObject *args, PyObject *k
size_t size;

if (PyUnicode_Check(textobj)) {
size = PyUnicode_GET_SIZE(textobj);
size = PyUnicode_GET_LENGTH(textobj);
codepoints.resize(size);
Copy link
Contributor

@anntzer anntzer Jun 18, 2020

Choose a reason for hiding this comment

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

maybe simpler and more efficient to just use https://docs.python.org/3/c-api/unicode.html#c.PyUnicode_AsUCS4 or https://docs.python.org/3/c-api/unicode.html#c.PyUnicode_AsUCS4Copy instead of managing and additional temporay buffer ourselves?
Edit: Bah, it's too complicated given that we also support bytes input.

Copy link
Member Author

Choose a reason for hiding this comment

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

My goal here was the minimal fix to get us off to non-deprecated API. There is some discussion of removing the deprecated macros in 3.11 so I would rather get something in ASAP.

Py_UNICODE *unistr = PyUnicode_AsUnicode(textobj);
for (size_t i = 0; i < size; ++i) {
codepoints[i] = unistr[i];
codepoints[i] = PyUnicode_ReadChar(textobj, i);
}
} else if (PyBytes_Check(textobj)) {
size = PyBytes_Size(textobj);
Expand Down