>> libc.printf("%c\n", 104) h 2 >>> ...">

Wrong result when using clow

>>> from ctypes import *
>>> import ctypes.util
>>> libc = CDLL("libc.so.6")
>>> libc.printf("%c\n", 104)
h
2
>>> libc.islower(104) # Works fine
512
>>> libc.islower.restype = c_bool # But when i do this...
>>> libc.islower(104)
False
>>> c_bool(512)
c_bool(True)

personally, I think that "h" is lowercase.

Is this a bug in ctypes, or am I doing something wrong?

+4
source share
1 answer

restypenot just specify the type of Python output, but, most importantly, tell you what type C is to be expected, and therefore how to marshal it. islowerreturns int, which is usually 4 bytes wide; if you say it returns bool(usually 1 byte), you violate the expectations of the marshaling code.

(, , , 8 ), , , , .

: . API C .

+7

Source: https://habr.com/ru/post/1547277/


All Articles