Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

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

Merged
vstinner merged 3 commits intopython:masterfromvstinner:ctypes_struct_param
Aug 30, 2019
Merged

bpo-37140: Fix StructUnionType_paramfunc()#15612

vstinner merged 3 commits intopython:masterfromvstinner:ctypes_struct_param
Aug 30, 2019

Conversation

vstinner
Copy link
Member

@vstinnervstinner commentedAug 30, 2019
edited by bedevere-bot
Loading

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

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.
@vstinner
Copy link
MemberAuthor

I wrote an unit test. I made sure that the unit test fails without the fix:

FAIL: test_pass_by_value_finalizer (ctypes.test.test_structures.StructureTestCase)----------------------------------------------------------------------Traceback (most recent call last):  File "/home/vstinner/python/master/Lib/ctypes/test/test_structures.py", line 449, in test_pass_by_value_finalizer    self.assertEqual(finalizer_calls, [])AssertionError: Lists differ: ['called'] != []First list contains 1 additional elements.First extra element 0:'called'- ['called']+ []

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);
Copy link
Contributor

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 ?

Copy link
MemberAuthor

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 :-)

s = None
support.gc_collect()
self.assertEqual(finalizer_calls, ["called"])

Copy link
Contributor

Choose a reason for hiding this comment

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

<3 the test case

@vstinnervstinner merged commit96b4087 intopython:masterAug 30, 2019
@vstinnervstinner deleted the ctypes_struct_param branchAugust 30, 2019 12:30
@miss-islington
Copy link
Contributor

Thanks@vstinner for the PR 🌮🎉.. I'm working now to backport this PR to: 3.8.
🐍🍒⛏🤖

@bedevere-bot
Copy link

GH-15613 is a backport of this pull request to the3.8 branch.

miss-islington pushed a commit to miss-islington/cpython that referenced this pull requestAug 30, 2019
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>
miss-islington added a commit that referenced this pull requestAug 30, 2019
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>
lisroach pushed a commit to lisroach/cpython that referenced this pull requestSep 10, 2019
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.
DinoV pushed a commit to DinoV/cpython that referenced this pull requestJan 14, 2020
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.
websurfer5 pushed a commit to websurfer5/cpython that referenced this pull requestJul 20, 2020
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.
Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment
Reviewers

@serge-sans-pailleserge-sans-pailleserge-sans-paille left review comments

Assignees
No one assigned
Labels
None yet
Projects
None yet
Milestone
No milestone
Development

Successfully merging this pull request may close these issues.

5 participants
@vstinner@miss-islington@bedevere-bot@serge-sans-paille@the-knights-who-say-ni

[8]ページ先頭

©2009-2025 Movatter.jp