You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
For example, Python foreign function ImagingCore.isblock() takes no arguments, as in its C implementation, arguments passed from the Python side will not be used:
However, its calling convention given by Python/C API when declaring the foreign function is METH_VARARGS (0x0001), which should be METH_NOARGS instead in this case:
This mismatch makes parameter of any type can be passed to this foreign function designed to be parameter free without getting a TypeError:
fromPILimportImageim=Image.open("./test.png")
ic=im.getdata()
ic.isblock('str', 1) # passing anything is legal because of the mismatch
The same mismatch can be found for foreign functions ImagingCore.split(), ImagingCore.getbbox(), ImagingCore.chop_invert(), ImagingCore.getextrema(), ImagingCore.getpalettemode(), ImagingCore.getprojection().
We also found a mismatch in NumPy, which has been fixed in numpy/numpy#18679.
Please let me know if I miss something or get something wrong here.
The text was updated successfully, but these errors were encountered:
radarhere
changed the title
Calling conventions of some Python foreign functions mismatch with their C implementations.
Calling conventions of some Python foreign functions mismatch with their C implementations
May 11, 2021
For example, Python foreign function
ImagingCore.isblock()
takes no arguments, as in its C implementation, arguments passed from the Python side will not be used:Pillow/src/_imaging.c
Lines 2097 to 2100 in d393cfb
parameter
args
is not used in the function body.However, its calling convention given by Python/C API when declaring the foreign function is
METH_VARARGS (0x0001)
, which should beMETH_NOARGS
instead in this case:Pillow/src/_imaging.c
Line 3460 in d393cfb
This mismatch makes parameter of any type can be passed to this foreign function designed to be parameter free without getting a TypeError:
The same mismatch can be found for foreign functions
ImagingCore.split()
,ImagingCore.getbbox()
,ImagingCore.chop_invert()
,ImagingCore.getextrema()
,ImagingCore.getpalettemode()
,ImagingCore.getprojection()
.We also found a mismatch in NumPy, which has been fixed in numpy/numpy#18679.
Please let me know if I miss something or get something wrong here.
The text was updated successfully, but these errors were encountered: