pyclibrary icon indicating copy to clipboard operation
pyclibrary copied to clipboard

Automatic type conversion (to c_double)

Open ebranlard opened this issue 6 years ago • 1 comments

Hi, first of all, thank you for your work! I was about to start a similar project but found your work that seems to perform what I wanted. There are still a couple of type conversions that I believe could be automated, but maybe I'm just missing something...

Given the following signature (for a fortran dll):

double testlib_add(double* x, double* y);

Any of the following python calls

add = lib.testlib_add(1.0,2.0)
# OR:
x,y =1.0 , 2.0
add = lib.testlib_add(x,y)

will fail with the error:

_library.py", line 498, in __call__ 
 res = self.func(*arg_list)
types.ArgumentError: argument 1: <type 'exceptions.TypeError'>: expected LP_c_double instance instead of float

Yet it will work if I explicit convert them:

x=ctypes.c_double(1.0)
y=ctypes.c_double(2.0)
add = lib.testlib_add(x,y)

Is there any way we can avoid the explicit type conversion by the user?

ebranlard avatar Apr 13 '19 19:04 ebranlard

Sorry for the slow response. I believe that this is not the default bahavior since usually one expects an array rather than a single value. But we can probably cover this case too. Could you make a PR ?

MatthieuDartiailh avatar Apr 18 '19 01:04 MatthieuDartiailh