Issue 1723338: Crash in ctypes callproc function with unicode string arg (original) (raw)

Issue1723338

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:24 admin set github: 44986
2007-05-22 10:43:09 claplace create