-
-
Notifications
You must be signed in to change notification settings - Fork 30.6k
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
Passing 'None' if argtype is set to POINTER(...) doesn't always result in NULL #48856
Comments
Consider the library 'c_lib.so' consisting of a single function 'c_func' int c_func ( double *arg0, double *arg1, double *arg2, double *arg3,
double *arg4, double *arg5, double *arg6) {
printf("Value of arg0 is %p\n", arg0);
printf("Value of arg1 is %p\n", arg1);
printf("Value of arg2 is %p\n", arg2);
printf("Value of arg3 is %p\n", arg3);
printf("Value of arg4 is %p\n", arg4);
printf("Value of arg5 is %p\n", arg5);
printf("Value of arg6 is %p\n", arg6);
return 0;
} and the following snippet: from ctypes import *
c_lib = CDLL('c_lib.so')
t = POINTER(c_double)
c_lib.c_func.argtypes = [t,t,t,t,t,t,t]
def call_c_func():
nptr = None
c_lib.c_func(nptr, nptr, nptr, nptr, nptr, nptr, nptr) The output I get from call_c_func() with Python 2.6 and Python 2.5 on a Value of arg0 is (nil) The reason appears to be that in 'PointerType_from_param' (_ctypes.c) I propose to remove NULL pointer handling from the above from_param |
Thomas, is there any chance of getting your attention for this one? |
I ran into this problem, too. It took me a long time to track down the I looked at the attached patch, and it seems to me the only alternative This patch is a one-line fix (plus tests and documentation), and it It would be great if this patch could be applied quickly and added to |
Thanks for bringing my attention to this problem again, and for the review. Andrew McNabb schrieb:
Using PyLong_FromLong doesn't make a difference at all, if you look into
The problem is that the patch changes the behaviour of the
The patch is missing a 'Py_INCREF(value)' before the 'return value;',
It could (on 32-bit systems), although I'm not sure if there is code
|
Here's a corrected patch against svn trunk. |
On Thu, Jul 30, 2009 at 07:14:56PM +0000, Thomas Heller wrote:
I'm just glad to help.
Hmm. So you're saying that someone could be calling from_param() and I just looked at ConvParam in a little more detail, and it seems that
Thanks for pointing that out. I'm still getting familiar with reference |
Andrew McNabb schrieb:
Zeroing out higher order bits wouldn't help because the parameter would However, after thinking the whole issue over for some time I'm now So I will apply the patch to trunk and 2.6, and forward port to the |
Python 3.0 is dead ;-). |
Comitted as trunk: 74921, py3k: 74922, release31-maint: 74923, release26-maint: 74924 |
For anyone that has to use a Python version where this bug is present, it is possible to manually create a NULL pointer. For the example: POINTER(c_double)() This works, at least in my case. |
Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.
Show more details
GitHub fields:
bugs.python.org fields:
The text was updated successfully, but these errors were encountered: