[New-bugs-announce] [issue5880] Remove unneeded "context" pointer from getters and setters

Larry Hastings report at bugs.python.org
Wed Apr 29 18:15:24 CEST 2009

New submission from Larry Hastings <larry at hastings.org>:

PyGetSetDef has a "void *context" field.  This field is passed in to the
get and set functions implementing the property.  The field is almost
never used, so it adds unnecessary complexity.  Clearly, YAGNI.

There are two places in CPython where it got used: both in PyLongObject,
both using long_getN(), where it's used to store an integer constant
(not a pointer!) that is converted to a Long object and returned.  Since
there are only two of these, this was easy to fix: split long_getN()
into two functions returning a hard-coded number, long_get0() and

The attached patch removes the "void *context" field of PyGetSetDef,
removes the almost universally ignored context arguments to the getters
and setters, and removes the data declarations for the context pointer
in static PyGetSetDef structs.  With the patch applied py3k/trunk passes
all expected regression tests.

Martin: I added you to the nosy list 'cause we looked in to this at the
sprints, so I figured you'd be interested.

files: lch.getset.r72081.diff
keywords: patch
messages: 86812
nosy: larry, loewis
severity: normal
status: open
title: Remove unneeded "context" pointer from getters and setters
Added file: http://bugs.python.org/file13817/lch.getset.r72081.diff

Python tracker <report at bugs.python.org>

More information about the New-bugs-announce mailing list