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: Crash in ctypes callproc function with unicode string arg
Type: Stage:
Components: Extension Modules Versions: Python 2.5
process
Status: closed Resolution: works for me
Dependencies: Superseder:
Assigned To: theller Nosy List: claplace, nnorwitz, theller
Priority: normal Keywords:

Created on 2007-05-22 10:43 by claplace, last changed 2022-04-11 14:56 by admin. This issue is now closed.

Files
File name Uploaded Description Edit
inotify.py claplace, 2007-05-22 10:43 crash proof
Messages (5)
msg32105 - (view) Author: Colin Laplace (claplace) Date: 2007-05-22 10:43
I've recently came to a bug using ctypes.
I was using ctypes to call a syscall and and passing it
a string argument, which was in fact in unicode.
This resulted in a python crash in the callproc function.

You can easily reproduce the crash by launching the attached python file (or at this link: https://core.fluendo.com/elisa/trac/browser/branches/rewrite-1/elisa/extern/inotify.py 
)

tested with python 2.5
msg32106 - (view) Author: Neal Norwitz (nnorwitz) * (Python committer) Date: 2007-05-23 04:06
Thomas, could you take a look?
msg32107 - (view) Author: Thomas Heller (theller) * (Python committer) Date: 2007-05-23 18:35
Unfortunately your test script does not run for me (I don't have twisted installed on Linux).

I fear this is not a bug.  When the .argtypes attribute for a foreign function is not set, you can pass (among others) Python strings *and* Python unicode strings to the function.  The foreign function will receive a 'char *' in the former case, and a 'wchar_t *' in the latter case - the unicode string will *not* be converted.

If this is your problem, and the foreign function expects a 'char *', you have several choices:

1. You can convert the unicode string to an ascii string in the Python code yourself.
2. You can wrap the unicode string in a c_char_p instance, and ctypes will do the conversion for you.
3. You can set the correct .argtypes attribute on the function, and ctypes will do the conversion for you.

If this is not your problem, please provide a self-contained test case.
msg32108 - (view) Author: Colin Laplace (claplace) Date: 2007-05-28 09:58
The argtypes thing fixed my problem, thank you.
msg32109 - (view) Author: Thomas Heller (theller) * (Python committer) Date: 2007-05-28 15:39
Thanks, closing then.
History
Date User Action Args
2022-04-11 14:56:24adminsetgithub: 44986
2007-05-22 10:43:09claplacecreate