Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #37223

Re: handling return codes from CTYPES

Date 2013-01-21 20:21 +0000
From MRAB <python@mrabarnett.plus.com>
Subject Re: handling return codes from CTYPES
References <50FD1C6F.6030801@gmail.com> <50FD5B47.8030807@vrplumber.com> <50FD7255.3010206@gmail.com>
Newsgroups comp.lang.python
Message-ID <mailman.762.1358799685.2939.python-list@python.org> (permalink)

Show all headers | View raw


On 2013-01-21 16:52, Steve Simmons wrote:
> Mike,
>
> Thanks for your response - I was puzzled by one part of it though...
>
>      On 21/01/2013 15:14, Mike C. Fletcher wrote:
>>     That's because you've just discarded the object you created
>
> I (mis?)understood from the ctypes documentation that '>>> initResult =
> c_short(0)' would result in the creation of a ctypes 'short' called
> initResult and that this object would be mutable.  On that basis, I
> expected the following statement '>>> initResult = initScanLib( ... )'
> would assign the result of the call to initResult.
>
> So, I can understand that I am not using the correct approach but I
> don't understand how I discarded the object I created.  Can you clarify
> please?
>
This:

initResult = initScanLib( ... )

will make initResult refer to whatever initScanLib(...) returned, just
as this:

initResult = c_short(0)

will make initResult refer to whatever c_short(0) returned.

What you were doing was this:

1. You created a c_short object and bound initResult to it.

2. You called a function and bound initResult to its result, unbinding
the c_short object in the process.

3. There were no other references to the c_short object, therefore it 
could be discarded by the garbage collector.

Back to comp.lang.python | Previous | Next | Find similar | Unroll thread


Thread

Re: handling return codes from CTYPES MRAB <python@mrabarnett.plus.com> - 2013-01-21 20:21 +0000

csiph-web