Am I using ctypes correctly? Where are fprints going?

T

TP

From the Cplusplus-sig, I gathered that instead of Boost.Python I
should use ctypes for the following problem. But let me make sure I'm
using it correctly.

I am calling the C Leptonica Image Processing C Library
(http://leptonica.com) from python.

Within its leptprotos.h file are functions like this:

extern PIX * pixRead ( const char *filename );
extern void pixDestroy ( PIX **ppix );

Using Windows XP, and within a Command Prompt I do this:

python26
c_void_p(12310144)
1553 #this is the correct width
c_void_p(None) #This look right, pixDestroy() sets the pointer to NULL.

Is this the proper way you are supposed to supply the address of a
pointer that is returned by a C function? Is there a better way?

Should I have done the following also?

Now that the pix has been destroyed, you shouldn't be able to get its width:
-1

This is correct but there also should have been an error message printed out.

The C library is doing this (I think, I haven't actually used the
debugger on it):

sprintf(charbuf, "Error in %s: %s\n", procname, msg);
fprintf(stderr, charbuf, ival);

But I don't see any error message appear in my console window?

Finally, the documentation states for ctypes.util.find_msvcrt():

Windows only: return the filename of the VC runtype library used by
Python, and by the extension modules. If the name of the library
cannot be determined, None is returned.

If you need to free memory, for example, allocated by an extension
module with a call to the free(void *), it is important that you use
the function in the same library that allocated the memory.
'msvcr90.dll'

Does this mean that if I build a Debug version of the Leptonica DLL
(which will use the Debug version of the runtime library,
msvcr90d.dll), that I also have to build and use a Debug version of
Python26?

I tried using leptonlibd.dll with the ActiveState release version of
Python26 and didn't see any immediate error.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,756
Messages
2,569,540
Members
45,025
Latest member
KetoRushACVFitness

Latest Threads

Top