472,368 Members | 2,541 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,368 software developers and data experts.

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 4610
>>>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. Lwis" <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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Thomas Heller | last post by:
It's release day ;-) ctypes 0.6.3 released ===================== Overview 'ctypes' is a Python package to create and manipulate C data types in Python, and to call functions in dynamic...
1
by: Thomas Heller | last post by:
ctypes 0.9.1 released - Sept 14, 2004 ===================================== Overview ctypes is a ffi (Foreign Function Interface) package for Python 2.3 and higher. ctypes allows to call...
19
by: Thomas Heller | last post by:
ctypes 0.9.2 released - Oct 28, 2004 ==================================== Overview ctypes is a ffi (Foreign Function Interface) package for Python 2.3 and higher. ctypes allows to call...
3
by: Lenard Lindstrom | last post by:
Posted in a previous thread was some Python code for accessing Window's Simple MAPI api using the ctypes module. http://groups-beta.google.com/group/comp.lang.python/msg/56fa74cdba9b7be9 This...
21
by: codergem | last post by:
One common answer is that all compilers keep the size of integer the same as the size of the register on a particular architecture. Thus, to know whether the machine is 32 bit or 64 bit, just see...
2
by: cantankerousoldgit | last post by:
I am trying to call a DLL with a function like this: """DESCRIPTION: Get a list of objects attributes matching attribute values ARGUMENTS: session : the current session classId :...
12
by: p.lavarre | last post by:
Q: The C idea of (pv != NULL) is said most directly in Python ctypes how? A: We are of course supposed to write something like: def c_not_null(pv): return (ctypes.cast(pv,...
3
by: p.lavarre | last post by:
Subject: Python CTypes translation of (pv != NULL) And so then the next related Faq is: Q: How should I test for ((void *) -1)? A: (pv == 0xffffFFFF) works often.
0
by: Egor Zindy | last post by:
Egor Zindy wrote: #!/usr/bin/env python """ A generic chipid library based on ctypes This module handles most of the functions in FTChipID.dll
2
by: Kemmylinns12 | last post by:
Blockchain technology has emerged as a transformative force in the business world, offering unprecedented opportunities for innovation and efficiency. While initially associated with cryptocurrencies...
0
by: Naresh1 | last post by:
What is WebLogic Admin Training? WebLogic Admin Training is a specialized program designed to equip individuals with the skills and knowledge required to effectively administer and manage Oracle...
0
by: antdb | last post by:
Ⅰ. Advantage of AntDB: hyper-convergence + streaming processing engine In the overall architecture, a new "hyper-convergence" concept was proposed, which integrated multiple engines and...
0
by: Arjunsri | last post by:
I have a Redshift database that I need to use as an import data source. I have configured the DSN connection using the server, port, database, and credentials and received a successful connection...
0
hi
by: WisdomUfot | last post by:
It's an interesting question you've got about how Gmail hides the HTTP referrer when a link in an email is clicked. While I don't have the specific technical details, Gmail likely implements measures...
0
Oralloy
by: Oralloy | last post by:
Hello Folks, I am trying to hook up a CPU which I designed using SystemC to I/O pins on an FPGA. My problem (spelled failure) is with the synthesis of my design into a bitstream, not the C++...
2
by: Ricardo de Mila | last post by:
Dear people, good afternoon... I have a form in msAccess with lots of controls and a specific routine must be triggered if the mouse_down event happens in any control. Than I need to discover what...
1
by: ezappsrUS | last post by:
Hi, I wonder if someone knows where I am going wrong below. I have a continuous form and two labels where only one would be visible depending on the checkbox being checked or not. Below is the...
0
by: jack2019x | last post by:
hello, Is there code or static lib for hook swapchain present? I wanna hook dxgi swapchain present for dx11 and dx9.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.