ctypes details was: Re: syntax for code blocks

Kiuhnm kiuhnm03.4t.yahoo.it
Mon Apr 30 11:54:40 EDT 2012


On 4/30/2012 17:42, mwilson at the-wire.com wrote:
>> On 4/30/2012 17:02, Kiuhnm wrote:
>>> BignumTypePtr = ctypes.POINTER(BignumType)
>>>
>>> for op, op_word in ((libbnem.BN_add, libbnem.BN_add_word),
>>> (libbnem.BN_sub, libbnem.BN_sub_word)):
>>> op.argtypes = [BignumTypePtr] * 3
>>> op_word.argtypes = [BignumTypePtr, ctypes.c_ulong]
>>> op.restype = op_word.restype = ctypes.c_int
>>
>> On second thought, BignumPtrType is probably the right name.
>
> (Way off the original topic, aren't we?)  I haven't looked inside ctypes,
> and don't know what kind of thing ctypes.POINTER actually constructs.  I was
> worried about falling into a [[a]]*3 kind of error -- unwittingly sharing a
> mutable object.  I guess I really should look.

Better off topic than uninterestingly in topic, IMHO.

Regarding ctypes, try this to convince yourself that there's no problem 
in reusing BignumPtrType:
     from ctypes import POINTER, c_int
     assert POINTER(c_int) is POINTER(c_int)

Kiuhnm



More information about the Python-list mailing list