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.

classification
Title: TypeError: string or integer address expected instead of str instance
Type: enhancement Stage: resolved
Components: ctypes Versions: Python 3.2, Python 3.3
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: ezio.melotti Nosy List: amaury.forgeotdarc, ezio.melotti, jaraco, meador.inge, python-dev
Priority: low Keywords: patch

Created on 2011-12-26 17:50 by jaraco, last changed 2022-04-11 14:57 by admin. This issue is now closed.

Files
File name Uploaded Description Edit
issue13665.diff ezio.melotti, 2012-01-16 06:00 Patch against 3.2
Messages (4)
msg150271 - (view) Author: Jason R. Coombs (jaraco) * (Python committer) Date: 2011-12-26 17:50
When constructing a ctypes.c_char_p with a unicode string, a confusing error message is reported:

> python -c "import ctypes; ctypes.c_char_p('foo')"
Traceback (most recent call last):
  File "<string>", line 1, in <module>
TypeError: string or integer address expected instead of str instance

Since "string" and "str" seem like essentially the same thing, the error message doesn't make sense.

This message is obviously due to the change to unicode as the default string instance in Python 3. The error message should probably be updated to read "bytes or integer address expected instead of a str instance".

It's probably also worth scanning through the ctypes codebase for similar messages.
msg151324 - (view) Author: Ezio Melotti (ezio.melotti) * (Python committer) Date: 2012-01-16 06:00
Here's a patch.
I found a similar instance that says "unicode string or integer address expected instead of %s instance", but it's inside an "if (!PyUnicode_Check(value)) {}" so it should be ok ("unicode string" could be replaced to 'str' though).
msg151372 - (view) Author: Meador Inge (meador.inge) * (Python committer) Date: 2012-01-16 15:14
LGTM.  Thanks for fixing this.
msg151514 - (view) Author: Roundup Robot (python-dev) (Python triager) Date: 2012-01-18 03:43
New changeset b4d9243d16c9 by Ezio Melotti in branch '3.2':
#13665: s/string/bytes/ in error message.
http://hg.python.org/cpython/rev/b4d9243d16c9

New changeset 0c0ffebfccb0 by Ezio Melotti in branch 'default':
#13665: merge with 3.2.
http://hg.python.org/cpython/rev/0c0ffebfccb0
History
Date User Action Args
2022-04-11 14:57:25adminsetgithub: 57874
2012-01-18 03:44:15ezio.melottisetstatus: open -> closed
assignee: ezio.melotti
resolution: fixed
stage: commit review -> resolved
2012-01-18 03:43:37python-devsetnosy: + python-dev
messages: + msg151514
2012-01-16 15:14:36meador.ingesetmessages: + msg151372
2012-01-16 06:00:52ezio.melottisetfiles: + issue13665.diff
keywords: + patch
messages: + msg151324

stage: needs patch -> commit review
2012-01-02 17:36:15ezio.melottisetnosy: + ezio.melotti

type: enhancement
stage: needs patch
2011-12-30 21:13:18terry.reedysetnosy: + amaury.forgeotdarc, meador.inge
2011-12-26 17:50:34jaracocreate