classification
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
process
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 2020-08-30 16:36 by facundobatista. 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?

Thanks!
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.
History
Date User Action Args
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