473,395 Members | 1,495 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 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 4775
>>>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 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
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

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.