-
-
Notifications
You must be signed in to change notification settings - Fork 31k
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 our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
ctypes pointer not always keeping target alive #46376
Comments
It's hard to tell for sure, given the lack of precise definition, but I |
May I ask: do you have a real use case for this, or is it a carefully Of course I take all the blame for not defining/documenting this Python code C code ptr = POINTER(c_long)() int *ptr = NULL;
x = c_long(42) int x = 42;
ptr.contents = x ptr = &x;
a = ptr[0] int a = *ptr;
b = ptr[n] int b = ptr[n]; Assigning to .contents changes 'where the pointer points to'. Having said that, it is no longer clear to me what reading the |
We're finding such bugs because we are trying to reimplement ctypes in PyPy. I guess your last question was "is it impossible to construct this 'bug' |
Thomas, do you accept this as a bug or should the issue be closed as |
I accept this as a bug; however I don't have time now to work on it. |
This looks like it works as expected at least as of Python 3.7 where c_long(20) is indeed preserved and p1.contents removes 20 as expected. |
Original examples would pass, but only because of gc delay. Here's fun way to demonstrate that the problem still exists (and can be converted to a test): import ctypes
import weakref
p1 = ctypes.pointer(ctypes.c_long(10))
w = weakref.WeakValueDictionary()
ctypes.pointer(p1).contents.contents = w.setdefault(
1, ctypes.c_long(-1),
)
assert p1.contents.value == -1
assert 1 in w |
pythonGH-107131) (cherry picked from commit 08447b5) Co-authored-by: Konstantin <[email protected]>
pythonGH-107131) (cherry picked from commit 08447b5) Co-authored-by: Konstantin <[email protected]>
…107131) (#107487) (cherry picked from commit 08447b5) Co-authored-by: Konstantin <[email protected]>
…107131) (#107488) (cherry picked from commit 08447b5) Co-authored-by: Konstantin <[email protected]>
This ancient issue is now fixed. Thanks, Konstantin! ✨ 🍰 ✨ |
…in ctypes (pythonGH-107131) (python#107488)" This reverts commit 57f27e4.
…in ctypes (pythonGH-107131) (python#107487)" This reverts commit 54aaaad.
…in ctypes (pythonGH-107131) (python#107488)" This reverts commit 57f27e4.
Previous attempt to fix pythongh-46376 was incomplete and overall it didn't succeed, and was reverted. However, we have discovered some dangerous issues with ctypes, that aren't fixed or documented anywhere. This commit adds tests (@expectedfailure) so at least developers are aware of situations where memory might be corrupted, leaked or when changing a pointer value might have no effect. Hopefully, we should be able to remove @expectedfailure in the future, with new shiny ctypes implementation or at least a bugfix.
Previous attempt to fix pythongh-46376 was incomplete and overall it didn't succeed, and was reverted. However, we have discovered some dangerous issues with ctypes, that aren't fixed or documented anywhere. This commit adds tests (@expectedfailure) so at least developers are aware of situations where memory might be corrupted, leaked or when changing a pointer value might have no effect. Hopefully, we should be able to remove @expectedfailure in the future, with new shiny ctypes implementation or at least a bugfix.
Previous attempt to fix pythongh-46376 was incomplete and overall it didn't succeed, and was reverted. However, we have discovered some dangerous issues with ctypes, that aren't fixed or documented anywhere. This commit adds tests (@expectedfailure) so at least developers are aware of situations where memory might be corrupted, leaked or when changing a pointer value might have no effect. Hopefully, we should be able to remove @expectedfailure in the future, with new shiny ctypes implementation or at least a bugfix.
This should be re-opened, as fix in 3.11 was reverted and the one in 3.12/3.13/main isn't working always |
Previous attempt to fix pythongh-46376 was incomplete and overall it didn't succeed, and was reverted. However, we have discovered some dangerous issues with ctypes, that aren't fixed or documented anywhere. This commit adds tests (@expectedfailure) so at least developers are aware of situations where memory might be corrupted, leaked or when changing a pointer value might have no effect. Hopefully, we should be able to remove @expectedfailure in the future, with new shiny ctypes implementation or at least a bugfix.
Previous attempt to fix pythongh-46376 was incomplete and overall it didn't succeed, and was reverted in 3.11. However, we have discovered some dangerous issues with ctypes, that aren't fixed or documented anywhere. This commit adds tests (@expectedfailure) so at least developers are aware of situations where memory might be corrupted, leaked or when changing a pointer value might have no effect. Hopefully, we should be able to remove @expectedfailure in the future, with new shiny ctypes implementation or at least a bugfix.
Previous attempt to fix pythongh-46376 was incomplete and overall it didn't succeed, and was reverted in 3.11. However, we have discovered some dangerous issues with ctypes, that aren't fixed or documented anywhere. This commit adds tests (@expectedfailure) so at least developers are aware of situations where memory might be corrupted, leaked or when changing a pointer value might have no effect. Hopefully, we should be able to remove @expectedfailure in the future, with new shiny ctypes implementation or at least a bugfix.
Previous attempt to fix pythongh-46376 was incomplete and overall it didn't succeed, and was reverted in 3.11. However, we have discovered some dangerous issues with ctypes, that aren't fixed or documented anywhere. This commit adds tests (@expectedfailure) so at least developers are aware of situations where memory might be corrupted, leaked or when changing a pointer value might have no effect. Hopefully, we should be able to remove @expectedfailure in the future, with new shiny ctypes implementation or at least a bugfix.
Previous attempt to fix pythongh-46376 was incomplete and overall it didn't succeed, and was reverted in 3.11. However, we have discovered some dangerous issues with ctypes, that aren't fixed or documented anywhere. This commit adds tests (@expectedfailure) so at least developers are aware of situations where memory might be corrupted, leaked or when changing a pointer value might have no effect. Hopefully, we should be able to remove @expectedfailure in the future, with new shiny ctypes implementation or at least a bugfix.
…es (python#107131)" This reverts commit 08447b5. Revert also _ctypes.c changes of the PyDict_ContainsString() change, commit 6726626.
Please, take a look at |
…in ctypes (pythonGH-107131) (python#107487)" This reverts commit 54aaaad.
…es (#1… (python#108688) This reverts commit 08447b5. Revert also _ctypes.c changes of the PyDict_ContainsString() change, commit 6726626.
…pes (GH-107131) (GH-107487)" (#108864) This reverts commit 54aaaad. Co-authored-by: T. Wouters <[email protected]>
Previous attempt to fix pythongh-46376 was incomplete and overall it didn't succeed, and was reverted in 3.11. However, we have discovered some dangerous issues with ctypes, that aren't fixed or documented anywhere. This commit adds tests (@expectedfailure) so at least developers are aware of situations where memory might be corrupted, leaked or when changing a pointer value might have no effect. Hopefully, we should be able to remove @expectedfailure in the future, with new shiny ctypes implementation or at least a bugfix.
Previous attempt to fix pythongh-46376 was incomplete and overall it didn't succeed, and was reverted in 3.11. However, we have discovered some dangerous issues with ctypes, that aren't fixed or documented anywhere. This commit adds tests (@expectedfailure) so at least developers are aware of situations where memory might be corrupted, leaked or when changing a pointer value might have no effect. Hopefully, we should be able to remove @expectedfailure in the future, with new shiny ctypes implementation or at least a bugfix.
Previous attempt to fix pythongh-46376 was incomplete and overall it didn't succeed, and was reverted in 3.11. However, we have discovered some dangerous issues with ctypes, that aren't fixed or documented anywhere. This commit adds tests (@expectedfailure) so at least developers are aware of situations where memory might be corrupted, leaked or when changing a pointer value might have no effect. Hopefully, we should be able to remove @expectedfailure in the future, with new shiny ctypes implementation or at least a bugfix.
Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.
Show more details
GitHub fields:
bugs.python.org fields:
Linked PRs
The text was updated successfully, but these errors were encountered: