Skip to content

Switch PyArg_ParseTupleAndKeywords from "es" to "s". #13866

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
Apr 22, 2019

Conversation

anntzer
Copy link
Contributor

@anntzer anntzer commented Apr 3, 2019

This avoids having to call PyMem_Free ourselves.

Note that all call sites either already use utf-8 (which "s" does), or
use ascii but then match the string against some ascii-only strings (or
glyph names), so the change is fine encoding-wise.

Perhaps this will fix #13865? (which fails with a MemoryError in get_sfnt_table)

edit: well no, this segfaults the doc build.
edit: duh, should be fixed now.

PR Summary

PR Checklist

  • Has Pytest style unit tests
  • Code is Flake 8 compliant
  • New features are documented, with examples if plot related
  • Documentation is sphinx and numpydoc compliant
  • Added an entry to doc/users/next_whats_new/ if major new feature (follow instructions in README.rst there)
  • Documented in doc/api/api_changes.rst if API changed in a backward-incompatible way

This avoids having to call PyMem_Free ourselves.

Note that all call sites either already use utf-8 (which "s" does), or
use ascii but then match the string against some ascii-only strings (or
glyph names), so the change is fine encoding-wise.
@timhoffm
Copy link
Member

timhoffm commented Apr 14, 2019

The documentation of es says (https://docs.python.org/3/c-api/arg.html#strings-and-buffers):

The caller is responsible for calling PyMem_Free() to free the allocated buffer after use.

How does this match with your statement

This avoids having to call PyMem_Free ourselves.

@anntzer
Copy link
Contributor Author

anntzer commented Apr 14, 2019

This PR switches from using "es" (which requires manual deallocation) to "s" (which doesn't).

@timhoffm
Copy link
Member

Sorry, I was confused.

@@ -1066,15 +1066,10 @@ static PyObject *PyFT2Font_get_name_index(PyFT2Font *self, PyObject *args, PyObj
{
char *glyphname;
Copy link
Member

Choose a reason for hiding this comment

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

No const here in this file?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

FT_Get_Name_Index takes a non-const char* as argument (so we'd need a const_cast... not really worth it IMO? can add it if you prefer), even though it does not actually modify it. See also thread starting at http://lists.nongnu.org/archive/html/freetype/2019-04/msg00004.html.

@tacaswell tacaswell added this to the v3.2.0 milestone Apr 22, 2019
@tacaswell tacaswell merged commit 1f4b3bd into matplotlib:master Apr 22, 2019
@anntzer anntzer deleted the argparse branch April 22, 2019 21:36
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.

Appveyor broken
4 participants