469,609 Members | 1,689 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,609 developers. It's quick & easy.

CTypes on a 64 bit machine truncates pointers to 32 bits?

CTypes on a 64-bit machine appears to be truncating pointers to 32 bits:

[ron@monster1:~]$ uname -a
Linux monster1 2.6.18-6-amd64 #1 SMP Mon Jun 16 22:30:01 UTC 2008 x86_64
GNU/Linux
[ron@monster1:~]$ cat foo.c
void* foo(void* x) { return x; }
[ron@monster1:~]$ gcc -fPIC -shared foo.c -o foo.so
[ron@monster1:~]$ file foo.so
foo.so: ELF 64-bit LSB shared object, AMD x86-64, version 1 (SYSV), not
stripped
[ron@monster1:~]$ python
Python 2.5 (release25-maint, Jul 23 2008, 18:15:29)
[GCC 4.1.2 20061115 (prerelease) (Debian 4.1.1-21)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>from ctypes import *
foolib = cdll.LoadLibrary('foo.so')
foolib.foo(0xF00000000)
0
>>sizeof(c_void_p)
8
>>>
I am aware of http://bugs.python.org/issue1703286 but I get the same
result in Python2.5.2:

[ron@monster1:~]$ py252/bin/python
Python 2.5.2 (r252:60911, Sep 18 2008, 10:48:29)
[GCC 4.1.2 20061115 (prerelease) (Debian 4.1.1-21)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>from ctypes import *
foolib = cdll.LoadLibrary('foo.so')
foolib.foo(0xF00000000)
0
>>sizeof(c_void_p)
8
>>>
Sep 19 '08 #1
3 4306
>>>foolib = cdll.LoadLibrary('foo.so')
>>>foolib.foo(0xF00000000)
0
Shouldn't you tell ctypes that the argument and the result
of foo is a pointer?

Regards,
Martin
Sep 19 '08 #2
In article <48**********************@news.freenet.de>,
"Martin v. Löwis" <ma****@v.loewis.dewrote:
>>foolib = cdll.LoadLibrary('foo.so')
foolib.foo(0xF00000000)
0

Shouldn't you tell ctypes that the argument and the result
of foo is a pointer?
Yeah... that's it. Default return type is int, which I assumed would be
64 bits on a 64 bit machine, but turns out it's 32. Stupid.

rg
Sep 19 '08 #3
In message <rN*****************************@news.gha.charterm i.net>, Ron
Garret wrote:
Default return type is int, which I assumed would be
64 bits on a 64 bit machine, but turns out it's 32. Stupid.
I think preferred ABIs these days are LP64, not ILP64 or LLP64.
Sep 21 '08 #4

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

2 posts views Thread by Thomas Heller | last post: by
1 post views Thread by Thomas Heller | last post: by
19 posts views Thread by Thomas Heller | last post: by
2 posts views Thread by cantankerousoldgit | last post: by
12 posts views Thread by p.lavarre | last post: by
reply views Thread by Solution2021 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.