classification
Title: ctypes not converting None to Null in 64-bit system
Type: crash Stage: test needed
Components: ctypes Versions: Python 2.5
process
Status: closed Resolution: out of date
Dependencies: Superseder:
Assigned To: theller Nosy List: brian.curtin, pitrou, skrah, theller, wenkat_s
Priority: normal Keywords:

Created on 2009-12-14 17:10 by wenkat_s, last changed 2010-08-04 03:40 by terry.reedy. This issue is now closed.

Files
File name Uploaded Description Edit
test.py wenkat_s, 2009-12-14 17:10
Messages (5)
msg96385 - (view) Author: Venkateswaran (wenkat_s) Date: 2009-12-14 17:10
The attached code is failing to convert None to Null. It is successful 
if the int* is shifted towards the beginning of argument list. The bug 
is actually in 32/64 bit pointers as the code works on a 32 bit system.

The bug disappears if I reduce the number of arguments to less than 10.

I created the so using the command - "gcc  -shared -fPIC  -o libtest.so 
libtest.c", (gcc (Debian 4.3.2-1.1) 4.3.2) 

The c file is as follows:

libtest.c
#include <stdint.h>
#include <stdio.h>


int32_t where ( int32_t a, int32_t c, int32_t d, int32_t e, int32_t f, 
int32_t g, int32_t h, int32_t *b, int32_t i, int32_t j, int32_t k, 
int32_t l)
{
    printf("b = %p\n", (void *)b);
    printf("a = %d, c = %d, d = %d, e = %d, f = %d, g = %d, h = %d, i = 
%d, j = %d, k = %d,  l = %d", a,c,d,e,f,g,h,i,j,k,l);

    return 100;

} /* where() */

Python Code:
import ctypes

libtest = ctypes.CDLL('./libtest.so')
where = libtest.where
where.restype = ctypes.c_int
where.argtypes = [ 
                    ctypes.c_int32, ctypes.c_int32, ctypes.c_int32,          
ctypes.c_int32, ctypes.c_int32, ctypes.c_int32, ctypes.c_int32,
                    ctypes.POINTER(ctypes.c_int32),
                    ctypes.c_int32, ctypes.c_int32, ctypes.c_int32, 
ctypes.c_int32,
                 ]


a = 7
b = None

status = where(a,a,a,a,a,a,a,b,a,a,a,a)
msg99127 - (view) Author: Brian Curtin (brian.curtin) * (Python committer) Date: 2010-02-09 17:05
What is the output of your example? I'm not on Linux at the moment, but I'm trying to see if this is actually a crash.
msg99134 - (view) Author: Venkateswaran (wenkat_s) Date: 2010-02-09 18:04
The output was a valid pointer which was not null. I did not investigate further on this issue, because I had a work around i.e I used ctypes.POINTER(ctypes.c_cint)() instead of None.
msg99162 - (view) Author: Antoine Pitrou (pitrou) * (Python committer) Date: 2010-02-10 12:03
It works in 64-bit mode under Mandriva Linux (gcc 4.4.1), with Python 2.6, 2.7 and 3.2.

$ python issue7505.py 
b = (nil)
a = 7, c = 7, d = 7, e = 7, f = 7, g = 7, h = 7, i = 7, j = 7, k = 7,  l = 7

I also works with a hand-compiled Python (2.6, 2.7, 3.2) under a 64-bit Ubuntu box. However, it fails with the system Python 2.5 shipped with Ubuntu. So perhaps this has to do with how Debian/Ubuntu compile their Pythons, or their libffi.

$ python issue7505.py 
b = 0x7f5300000000
a = 7, c = 7, d = 7, e = 7, f = 7, g = 7, h = 7, i = 7, j = 7, k = 7,  l = 7
msg99286 - (view) Author: Stefan Krah (skrah) * (Python committer) Date: 2010-02-12 20:25
Confirm that 2.5 is the only troublesome version, but also when compiled from source (Ubuntu 64-bit, 2.5.5).
History
Date User Action Args
2010-08-04 03:40:25terry.reedysetstatus: open -> closed
resolution: out of date
2010-02-12 20:25:10skrahsetnosy: + skrah

messages: + msg99286
versions: + Python 2.5, - Python 2.6
2010-02-10 12:03:05pitrousetnosy: + pitrou
messages: + msg99162
2010-02-09 18:04:04wenkat_ssetmessages: + msg99134
2010-02-09 17:05:24brian.curtinsetpriority: normal
versions: - Python 2.5
nosy: + brian.curtin

messages: + msg99127

stage: test needed
2009-12-14 17:10:40wenkat_screate