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 >> image-sig
image-sig
[PYTHON IMAGE-SIG] passing tuple to c and back
by Dirk Engelmann other posts by this author
Feb 13 1997 1:16AM messages near this date
RE: [PYTHON IMAGE-SIG] passing tuple to c and back | Re: [PYTHON IMAGE-SIG] writing windows icon files?
Hi,

I would like to pass a tuple from python to a C-array. 
Then after some calculations in C a tuple should be returned to the
calling  python program.

I tried to do like this:

The Python calling sequence looks like

  x = ( 1, 2, 3 ) 
  y = c_module( x ) 
  print y


The C-module makes some trouble.

(my attempts to pass simple objects as intergers and floats
are OK)

PySequence_SetItem(vec, i, newobj) returns -1 , obviously 
vec is not a seqence object ?!


Is there any proposition to get it working?


Thanks for help!

regards,

Dirk Engelmann

--------------------------------------------------------------


Here is the module in C:

static PyObject *c_module( PyObject *self, PyObject *args )  
{  
    PyObject *vec, *obj[N],*newobj ; 
    int x[N]; 
    int   i, n;


    if ( !PyArg_ParseTuple( args, "O", &vec ) ) 
       return NULL; 

    if (!PySequence_Check(vec)) 
      return NULL; 
 
    n=PyObject_Length(vec); 
 
    for (i = 0; i < n; i++) 
    {
      obj[i] = PySequence_GetItem(vec, i); 
      PyArg_Parse(obj[i],"i",&x[i]); 
    }

    /* here: insert calculations on x */
    
    for (i = 0; i < n; i++) 
    {
         newobj = PyFloat_FromDouble( x[i] );
         PySequence_SetItem(vec, i, newobj); 
    }

    return Py_BuildValue("O",vec);  
}





_______________
IMAGE-SIG - SIG on Image Processing with Python

send messages to: image-sig@[...].org
administrivia to: image-sig-request@[...].org
_______________

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