Skip to content

bpo-45315: PyType_FromSpec: Copy spec->name and have the type own the memory for its name - #29103

Merged
encukou merged 3 commits into
python:mainfrom
encukou:bpo-45315-pytypespec-copy-name
Oct 21, 2021
Merged

encukou merged 3 commits into
python:mainfrom
encukou:bpo-45315-pytypespec-copy-name

Conversation

@encukou

@encukou encukou commented Oct 20, 2021 •

Copy link
Copy Markdown
Member

Also includes a test for a type created from an ephemeral PyType_Spec.
(The original design assumed PyType_Spec structs would be static, but dynamic ones are useful and used in the wild.)

https://bugs.python.org/issue45315

@seberg seberg left a comment •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

For what its worth: These changes look good to me (and a very nice test!). I could wonder if it may still be sensible to point into ht_name since the name is probably identical except that it starts after the first .? (EDIT: Sorry wrong way around of course)
(My first thought was also a flag, but if we have to worry about users mutating it, that is indeed not an option.)

Comment thread Modules/_testcapimodule.c Resolved

@erlend-aasland erlend-aasland left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

LGTM! I left some minor remarks. The added refactoring also looks good.

Comment thread Objects/typeobject.c Resolved
Comment thread Objects/typeobject.c Resolved
Co-authored-by: Erlend Egeberg Aasland <erlend.aasland@innova.no>
Co-authored-by: Sebastian Berg <sebastian@sipsolutions.net>
@encukou

encukou commented Oct 21, 2021

Copy link
Copy Markdown
Member Author

Thank you for the reviews!

@seberg You're retracing my thoughts :) I tried both pointing into ht_name and a flag, and it's very frustrating that they don't work :)

@encukou
encukou merged commit 8a310dd into python:main Oct 21, 2021
@encukou
encukou deleted the bpo-45315-pytypespec-copy-name branch October 21, 2021 09:46
shihai1991 added a commit to shihai1991/cpython that referenced this pull request Oct 21, 2021
* main: (263 commits)
  bpo-45521: Fix a bug in the obmalloc radix tree code. (pythonGH-29051)
  bpo-45522: Allow to disable freelists on build time (pythonGH-29056)
  bpo-34451: Document prompt and output toggle feature in html tutorial (pythonGH-27105)
  bpo-44019: Add operator.call() to __all__ for the operator module (pythonGH-29110)
  bpo-45315: PyType_FromSpec: Copy spec->name and have the type own the memory for its name (pythonGH-29103)
  bpo-44220: Export PyStructSequence_UnnamedField in the limited API (pythonGH-26331)
  bpo-44174: [Enum] add reference to name mangling (pythonGH-29116)
  bpo-45548: add some missing entries to `Modules/Setup` (pythonGH-29115)
  bpo-35673: Add a public alias for namespace package __loader__ attribute (python#29049)
  bpo-45192: Fix a bug that infers the type of an os.PathLike[bytes] object as str (pythonGH-28323)
  bpo-45527: Don't count cache hits, just misses. (pythonGH-29092)
  bpo-45320: Remove long-deprecated inspect methods (pythonGH-28618)
  bpo-41374: Remove obsolete exclusion of netinet/tcp.h on Cygwin (pythonGH-21649)
  bpo-45532: Replace 'default' with 'main' as default in sys.version (pythonGH-29100)
  bpo-45464: [doc] Explain that subclassing multiple exceptions is fragile (pythonGH-29094)
  Cleanup a couple of comments left on PR 28775 post-merge. (pythonGH-29079)
  bpo-45536: Check OpenSSL APIs in configure (pythonGH-29088)
  Add PEPs 593 & 647 to list of PEPs at top of typing docs (pythonGH-29097)
  Add a comment about how to fix bogus test_host_resolution_bad_address failures (python#29085)
  bpo-44525: Specialize simple Python calls. (pythonGH-29033)
  ...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

5 participants