Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

noobie needs help with ctypes

30 views
Skip to first unread message

Sells, Fred

unread,
Dec 9, 2013, 2:24:22 PM12/9/13
to pytho...@python.org
I'm using python 2.6 on Linux/CentOs 6.x

I'm getting ctypes to work, but getting stuck on the use of .argtypes. Can someone point out what I'm doing. This is my first use of ctypes and it looks like I'm getting different definitions in stackoverflow that may correspond to different version of python.

Here is my code. Without the restype/argtypes it works, but I cannot figure out how to define argtypes to match the data.
mylibrary = ctypes.CDLL(LIBRARY_PATH)
mdsconvert = mylibrary.RugVersionConverter
mdsconvert.restype = ctypes.c_int
mdsconvert.argtypes = [ charptr, #flat buffer of mds 3.0 data
ctypes.c_buffer, #computed flat buffer of mds 2.0 data
ctypes.c_buffer #version set to "1.00.4" in c++, never used
]

def convertMds2to3(mds30buffer):
mds20 = ctypes.create_string_buffer('\000'*3000)
t = ctypes.create_string_buffer('\000'*30)
success = mdsconvert(mds30buffer, ctypes.byref(mds20), ctypes.byref(t) )
print 'convert %s to %s success=%s version=%s' % (len(mds30buffer), len(mds20.value), success, t.value)
return mds20.value

------------------------------- C++ code looks like this -------------------------------------------------------
extern "C"
int RugVersionConverter( char * sInputRecord, char * MDS2_Rec, char * Version );

where sInputRecord is input and MDS2_Rec and Version are output.

Terry Reedy

unread,
Dec 9, 2013, 3:15:09 PM12/9/13
to pytho...@python.org
On 12/9/2013 2:24 PM, Sells, Fred wrote:
> I'm using python 2.6 on Linux/CentOs 6.x

I would use the latest 2.7 (or 3.3) for a new project if at all possible.

> I'm getting ctypes to work, but getting stuck on the use of .argtypes. Can someone point out what I'm doing. This is my first use of ctypes and it looks like I'm getting different definitions in stackoverflow that may correspond to different version of python.

In particular, I am sure that there have been bugfixes for ctypes.


--
Terry Jan Reedy

Joel Goldstick

unread,
Dec 9, 2013, 3:22:08 PM12/9/13
to Terry Reedy, pytho...@python.org
On Mon, Dec 9, 2013 at 3:15 PM, Terry Reedy <tjr...@udel.edu> wrote:
On 12/9/2013 2:24 PM, Sells, Fred wrote:
I'm using python 2.6 on Linux/CentOs 6.x

I would use the latest 2.7 (or 3.3) for a new project if at all possible.

I seem to recall that Centos needs 2.6 as default python for its own purposes, so you need to install another version without messing with 2.6.  VirtualEnv might help.
 
I'm getting ctypes to work, but getting stuck on the use of  .argtypes.  Can someone point out what I'm doing.  This is my first use of ctypes and it looks like I'm getting different definitions in stackoverflow that may correspond to different version of python.

In particular, I am sure that there have been bugfixes for ctypes.

Sells, Fred

unread,
Dec 9, 2013, 9:27:28 PM12/9/13
to Joel Goldstick, Terry Reedy, pytho...@python.org

My management requires that we stick with the version that comes with CentOs which is 2.6.   I know that it’s possible to have multiple versions co-resident with or without virtualenv, but policy is policy L

Steven D'Aprano

unread,
Dec 9, 2013, 10:27:47 PM12/9/13
to
On Tue, 10 Dec 2013 02:27:28 +0000, Sells, Fred wrote:

> My management requires that we stick with the version that comes with
> CentOs which is 2.6. I know that it’s possible to have multiple
> versions co-resident with or without virtualenv, but policy is policy ☹

And a perfectly reasonable policy it is too. Python 2.6 is still
supported by Centos and RedHat, so it's not obsolete yet.

What's not reasonable though is this gunk in your post:

> <html xmlns:v="urn:schemas-microsoft-com:vml"
> xmlns:o="urn:schemas-microsoft-com:office:office"
> xmlns:w="urn:schemas-microsoft-com:office:word"
> xmlns:m="http://schemas.microsoft.com/office/2004/12/omml"
> xmlns="http://www.w3.org/TR/REC-html40"> <head>
> <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
> <meta name="Generator" content="Microsoft Word 14 (filtered medium)">
> <style><!--

[ delete about three pages of HTML ]

This forum is in part a text-only newsgroup and mailing list. Please
respect the conventions of the newsgroup by only sending plain text
messages rather than so-called "Rich Text" (HTML) messages, if at all
possible.


Thank you.


--
Steven

Sells, Fred

unread,
Dec 10, 2013, 8:14:53 AM12/10/13
to Steven D'Aprano, pytho...@python.org
Mucho apologies for rich text, I think I picked that up when replying to a post without properly checking. Thanks for heads up.

Fred.

0 new messages