Issue 5074: python3 and ctypes, script causes crash (original) (raw)
Issue5074
Created on 2009-01-27 03:02 by pooryorick, last changed 2022-04-11 14:56 by admin. This issue is now closed.
Messages (3) | ||
---|---|---|
msg80611 - (view) | Author: Poor Yorick (pooryorick) * | Date: 2009-01-27 03:02 |
the following script causes python3 to crash on my Windows XP Pro Machine: import ctypes b = ctypes.windll.Kernel32 var1 = 'TEMP' out = ctypes.create_string_buffer(40) c = b.GetEnvironmentVariableW(var1,out,40) print('ones', c, out, out.raw) print('two: ', dir(out)) | ||
msg80628 - (view) | Author: Gabriel Genellina (ggenellina) | Date: 2009-01-27 07:01 |
3rd argument to GetEnvironmentVariableW is the buffer size in *characters*, not bytes. Your buffer has room for 20 characters only, not 40. You should use create_unicode_buffer instead. Probably the names create_unicode_buffer/create_string_buffer should be revised in 3.x | ||
msg80629 - (view) | Author: Martin v. Löwis (loewis) * ![]() |
Date: 2009-01-27 07:19 |
Why do you think this is a bug in ctypes? *Of course* it is possible to crash Python by using ctypes incorrectly. |
History | |||
---|---|---|---|
Date | User | Action | Args |
2022-04-11 14:56:44 | admin | set | github: 49324 |
2009-01-27 07:19:54 | loewis | set | status: open -> closednosy: + loewisresolution: not a bugmessages: + |
2009-01-27 07:01:48 | ggenellina | set | nosy: + ggenellinamessages: + |
2009-01-27 03:02:24 | pooryorick | create |