ASPN ActiveState Programmer Network
ActiveState
/ Home / Perl / PHP / Python / Tcl / XSLT /
/ Safari / My ASPN /
Cookbooks | Documentation | Mailing Lists | Modules | News Feeds | Products | User Groups


Recent Messages
List Archives
About the List
List Leaders
Subscription Options

View Subscriptions
Help

View by Topic
ActiveState
.NET Framework
Open Source
Perl
PHP
Python
Tcl
Web Services
XML & XSLT

View by Category
Database
General
SOAP
System Administration
Tools
User Interfaces
Web Programming
XML Programming


MyASPN >> Mail Archive >> python-list
python-list
Re: how to pass a file descriptor in a swig module
by Pierre Schnizer other posts by this author
Jul 4 2003 6:58AM messages near this date
how to pass a file descriptor in a swig module | Re: how to pass a file descriptor in a swig module
Pierre Schnizer <P.Schnizer@[...].de>  writes:

>  "kj.kjn" <kj.kjn@[...].fr> writes:
>  
>  > My function func(File * des) is embedded in a module swig.
>  > 
>  > I would to know how to call this function from python script and if it's
>  > necessay
>  > 
>  > to declare a typemaps ?
>  > 
>  > Thank you

Sorry I think I misunderstood you. In case you want to pass a file to swig you
need a typemap:
<snip> 
/* 
 * Type mapping for grabbing a FILE * from Python
 * Taken from the Swig documentation ... 
 */
%typemap(python,in) FILE * {
  if (!PyFile_Check($input)) {
      PyErr_SetString(PyExc_TypeError, "Need a file!");
      goto fail;
  }
  $1 = PyFile_AsFile($input);
}
</snip> 

Please note that this typemap is for swig1.3. In case you are using swig1.1
you should replace $1 with $result and "goto fail" with return NULL (which can
leak memory ).

Pierre
-- 
http://mail.python.org/mailman/listinfo/python-list
Thread:
kj.kjn
Pierre Schnizer
Pierre Schnizer
=?ISO-8859-1?Q?Gerhard_H=E4ring?=

Privacy Policy | Email Opt-out | Feedback | Syndication
© ActiveState Software Inc. All rights reserved