Win32 Extensions From C module

Mark Hammond mhammond at skippinet.com.au
Sun Feb 16 20:26:12 EST 2003


Dale Hirt wrote:
> -----BEGIN PGP SIGNED MESSAGE-----
> Hash: SHA1
> 
> Hi all,
> 
> I am currently working on the subversion (http://subversion.tigris.org) python bindings.  It utilizes swig to help build some of the code, however, that is not a main concern.
> 
> I have a function that can take in a PyObject *, and I have figured out how it can determine if the type is a string, a FILE *, or an int.  What I currently cannot do is check, when only compiling on Win32, if it's type is a HANDLE.  The Win32 extensions define a PyHANDLE object, yet short of keeping a copy of his source code tree around, I don't know how I can say PyHANDLE_Check(), or get out the underlying HANDLE.
> 
> Here is a brief outline of how I would like the function to look.  I've cut out all the extraneous code.:
> 
> apr_file_t *svn_swig_py_make_file (PyObject *py_file)
> {
> ...
>   if (py_file == NULL || py_file == Py_None)
>     return NULL;
> 
>   if (PyString_Check (py_file))
>     {
> ...
>     }
>   else
>     {
>       if (PyFile_Check (py_file))
>         {
>           file = PyFile_AsFile (py_file);
> ...
>         }
> #ifdef WIN32
>       else if(PyHANDLE_Check (py_file))
>         {
>         	handle = PyHANDLE_AsHANDLE(py_file);
>         }
> #endif
>       else if (PyInt_Check (py_file))
>         {
>           fd = PyInt_AsLong (py_file);
> ...
>         }
>       else
>         {
>           return NULL;
>         }
> ...  
>   return apr_file;
> }
> 
> 
> Has anyone else done something like this?  Is there something that I'm missing?  Is there a mailing list specifically for Win32 extensions, or is this the right list?  I appreciate any and all help, and pointers.  
> 

Do a LoadLibrary of the function pointers at runtime.  Alternatively, do 
a Python level import of "pywintypes", and if it works, use 
PyObject_GetAttr() to get the functions you need, then 
PyEval_CallObject() to perform the conversions or the type checks.

Mark.





More information about the Python-list mailing list