Skip to content

gh-113318: Fix @getter and @setter in Argument Clinic - #155778

Open
serhiy-storchaka wants to merge 1 commit into
python:mainfrom
serhiy-storchaka:gh-113318-getset-bugfix
Open

gh-113318: Fix @getter and @setter in Argument Clinic#155778
serhiy-storchaka wants to merge 1 commit into
python:mainfrom
serhiy-storchaka:gh-113318-getset-bugfix

Conversation

@serhiy-storchaka

Copy link
Copy Markdown
Member

Three fixes for the accessors generated by Argument Clinic:

  • Generating a @getter or a @setter in a preprocessor conditional block failed with KeyError: 'methoddef_name', because the fallback definition was emitted for the METHODDEF symbol instead of the GETSETDEF one.
  • The entry of PyGetSetDef is identified by the C basename shared by the accessors, so defining them with different C basenames (Foo.p as foo_get and Foo.p as foo_set), or defining the same accessor twice, silently generated invalid or duplicated entries. It is now an error.
  • The setter was called with NULL to delete the attribute. Implementations which did not check for it crashed -- frame.f_trace_opcodes and the context, owner and session attributes of _ssl._SSLSocket -- or reported a confusing SystemError. Deletion is now rejected with AttributeError, unless the new directive @deleter is applied to the setter, which is then called with NULL as before.

@deleter is applied to the 22 setters whose implementation is written to accept NULL, so deleting these attributes works as before. Only three generated files change: the setters of _ssl, _sqlite3.Cursor.arraysize and frame.f_trace_opcodes gain the deletion check.

Fix generating an accessor in a preprocessor conditional block.
Reject the accessors of the same attribute with different C basenames and
the same accessor defined twice.
Reject deletion of the attribute, which crashed the setter, unless the new
directive @deleter is applied to it.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

awaiting core review needs backport to 3.14 bugs and security fixes needs backport to 3.15 pre-release feature fixes, bugs and security fixes

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant