Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork32.1k
bpo-37140: Fix StructUnionType_paramfunc()#15612
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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
Uh oh!
There was an error while loading.Please reload this page.
Conversation
Fix a ctypes regression of Python 3.8. When a ctypes.Structure ispassed by copy to a function, ctypes internals created a temporaryobject which had the side effect of calling the structure finalizer(__del__) twice. The Python semantics requires a finalizer to becalled exactly once. Fix ctypes internals to no longer call thefinalizer twice.Create a new internal StructParam_Type which is only used by_ctypes_callproc() to call PyMem_Free(ptr) on Py_DECREF(argument).StructUnionType_paramfunc() creates such object.
I wrote an unit test. I made sure that the unit test fails without the fix:
Without the fix, Test.del() is called once internally during the call to the C function ("func()"), and then a second time when the object is destroyed (s = None). |
(PyObject *)Py_TYPE(self), new_ptr); | ||
copied_self->b_needsfree = 1; | ||
obj = (&StructParam_Type)->tp_alloc(&StructParam_Type, 0); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
s/obj/arg_obj/ to increase readability ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
I chose "obj" name to get "parg->obj = obj" which looks nice to me :-)
Uh oh!
There was an error while loading.Please reload this page.
s = None | ||
support.gc_collect() | ||
self.assertEqual(finalizer_calls, ["called"]) | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
<3 the test case
Thanks@vstinner for the PR 🌮🎉.. I'm working now to backport this PR to: 3.8. |
bedevere-bot commentedAug 30, 2019
GH-15613 is a backport of this pull request to the3.8 branch. |
Fix a ctypes regression of Python 3.8. When a ctypes.Structure ispassed by copy to a function, ctypes internals created a temporaryobject which had the side effect of calling the structure finalizer(__del__) twice. The Python semantics requires a finalizer to becalled exactly once. Fix ctypes internals to no longer call thefinalizer twice.Create a new internal StructParam_Type which is only used by_ctypes_callproc() to call PyMem_Free(ptr) on Py_DECREF(argument).StructUnionType_paramfunc() creates such object.(cherry picked from commit96b4087)Co-authored-by: Victor Stinner <vstinner@redhat.com>
Fix a ctypes regression of Python 3.8. When a ctypes.Structure ispassed by copy to a function, ctypes internals created a temporaryobject which had the side effect of calling the structure finalizer(__del__) twice. The Python semantics requires a finalizer to becalled exactly once. Fix ctypes internals to no longer call thefinalizer twice.Create a new internal StructParam_Type which is only used by_ctypes_callproc() to call PyMem_Free(ptr) on Py_DECREF(argument).StructUnionType_paramfunc() creates such object.(cherry picked from commit96b4087)Co-authored-by: Victor Stinner <vstinner@redhat.com>
Fix a ctypes regression of Python 3.8. When a ctypes.Structure ispassed by copy to a function, ctypes internals created a temporaryobject which had the side effect of calling the structure finalizer(__del__) twice. The Python semantics requires a finalizer to becalled exactly once. Fix ctypes internals to no longer call thefinalizer twice.Create a new internal StructParam_Type which is only used by_ctypes_callproc() to call PyMem_Free(ptr) on Py_DECREF(argument).StructUnionType_paramfunc() creates such object.
Fix a ctypes regression of Python 3.8. When a ctypes.Structure ispassed by copy to a function, ctypes internals created a temporaryobject which had the side effect of calling the structure finalizer(__del__) twice. The Python semantics requires a finalizer to becalled exactly once. Fix ctypes internals to no longer call thefinalizer twice.Create a new internal StructParam_Type which is only used by_ctypes_callproc() to call PyMem_Free(ptr) on Py_DECREF(argument).StructUnionType_paramfunc() creates such object.
Fix a ctypes regression of Python 3.8. When a ctypes.Structure ispassed by copy to a function, ctypes internals created a temporaryobject which had the side effect of calling the structure finalizer(__del__) twice. The Python semantics requires a finalizer to becalled exactly once. Fix ctypes internals to no longer call thefinalizer twice.Create a new internal StructParam_Type which is only used by_ctypes_callproc() to call PyMem_Free(ptr) on Py_DECREF(argument).StructUnionType_paramfunc() creates such object.
Uh oh!
There was an error while loading.Please reload this page.
Fix a ctypes regression of Python 3.8. When a ctypes.Structure is
passed by copy to a function, ctypes internals created a temporary
object which had the side effect of calling the structure finalizer
(del) twice. The Python semantics requires a finalizer to be
called exactly once. Fix ctypes internals to no longer call the
finalizer twice.
Create a new internal StructParam_Type which is only used by
_ctypes_callproc() to call PyMem_Free(ptr) on Py_DECREF(argument).
StructUnionType_paramfunc() creates such object.
https://bugs.python.org/issue37140