This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Title: Assigning new values to instance of pointer types does not check validity
Type: behavior Stage: resolved
Components: ctypes Versions: Python 3.4, Python 3.5
Status: closed Resolution:
Dependencies: Superseder:
Assigned To: Nosy List: amaury.forgeotdarc, belopolsky, facundobatista, meador.inge
Priority: normal Keywords:

Created on 2012-09-15 14:41 by facundobatista, last changed 2022-04-11 14:57 by admin. This issue is now closed.

Messages (3)
msg170518 - (view) Author: Facundo Batista (facundobatista) * (Python committer) Date: 2012-09-15 14:41
In the doc it says:

Assigning a new value to instances of the pointer types c_char_p, c_wchar_p, and c_void_p changes the memory location they point to, not the contents of the memory block [...].

>>> s = "Hello, World"
>>> c_s = c_wchar_p(s)
>>> print(c_s)
c_wchar_p('Hello, World')
>>> c_s.value = "Hi, there"
>>> print(c_s)
c_wchar_p('Hi, there')
>>> print(s)                 # first object is unchanged
Hello, World

However, c_s it's not getting "Hi, there" as "the memory location it points to", otherwise next access will surely segfault.

OTOH, if it *does* change the memory location, but the value is cached locally, which is the point of letting it change the memory location? Shouldn't it raise AttributeError or something?

msg222973 - (view) Author: Mark Lawrence (BreamoreBoy) * Date: 2014-07-13 21:17
@Facundo please accept our apologies for the delay in getting back to you.
msg376113 - (view) Author: Facundo Batista (facundobatista) * (Python committer) Date: 2020-08-30 16:36
I'm closing this, it looks to me that behaviour changed and this is safe now.
Date User Action Args
2022-04-11 14:57:36adminsetgithub: 60151
2020-08-30 16:36:20facundobatistasetstatus: open -> closed

messages: + msg376113
stage: resolved
2019-04-26 19:12:05BreamoreBoysetnosy: - BreamoreBoy
2014-07-13 21:17:33BreamoreBoysetnosy: + amaury.forgeotdarc, BreamoreBoy, meador.inge, belopolsky

messages: + msg222973
versions: + Python 3.4, Python 3.5, - Python 3.2
2012-09-15 14:41:46facundobatistacreate