This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: ctypes: support double for calling function
Type: enhancement Stage:
Components: Extension Modules Versions: Python 2.5
process
Status: closed Resolution: rejected
Dependencies: Superseder:
Assigned To: theller Nosy List: theller, vstinner
Priority: normal Keywords:

Created on 2008-02-20 01:55 by vstinner, last changed 2022-04-11 14:56 by admin. This issue is now closed.

Files
File name Uploaded Description Edit
ctypes_callproc_double.patch vstinner, 2008-02-20 01:55 Patch proposition to implement the feature
Messages (3)
msg62581 - (view) Author: STINNER Victor (vstinner) * (Python committer) Date: 2008-02-20 01:55
ctypes doesn't support transparent conversion of double arguments. 
Example code:

from ctypes import cdll, c_double
libm = cdll.LoadLibrary("libm.so")
sqrt = libm.sqrt
sqrt.argstype = (c_double,)
sqrt.restype = c_double
print sqrt(4.0)

I wrote a patch to fix it: see attached patch
msg62588 - (view) Author: STINNER Victor (vstinner) * (Python committer) Date: 2008-02-20 12:03
Ooops, I had a typo in my code! Argument types argument name 
is "argtypes" and not "argstype". But well, the ticket is still 
valid :-) But it's more an enhancement than a bugfix ;-) So the right 
code is :

from ctypes import cdll, c_double
libm = cdll.LoadLibrary("libm.so")
sqrt = libm.sqrt
sqrt.restype = c_double
print sqrt(4.0)

The patch is useful when argstype is not set.
msg62597 - (view) Author: Thomas Heller (theller) * (Python committer) Date: 2008-02-20 20:15
I reject this patch.  It would be an arbitrary decision whether a Python
float should be passed as a C float or as a C double, and the docs
explicitely mention which native Python types can be passed to function
calls when argtypes is not set; see the bottom of the page at
http://docs.python.org/lib/ctypes-calling-functions.html
History
Date User Action Args
2022-04-11 14:56:31adminsetgithub: 46399
2008-02-20 20:15:45thellersetstatus: open -> closed
resolution: rejected
messages: + msg62597
2008-02-20 12:03:37vstinnersetmessages: + msg62588
2008-02-20 04:04:50loewissetassignee: theller
nosy: + theller
2008-02-20 01:55:13vstinnercreate