Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Automatic type conversion (to c_double) #34

Open
ebranlard opened this issue Apr 13, 2019 · 1 comment
Open

Automatic type conversion (to c_double) #34

ebranlard opened this issue Apr 13, 2019 · 1 comment

Comments

@ebranlard
Copy link

ebranlard commented Apr 13, 2019

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?

@MatthieuDartiailh
Copy link
Owner

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 ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants