FAQ
hi ..

I was reading the tutorial "Extending and Embedding
the python interpreter" available with python ..

http://www.python.org/doc/2.2.3/ext/ext.html

As per given in the tutorial i created an interface to
the system() system call.

this is the code of my module


Code:
#include<Python.h>

static PyObject * spam_system(self,args)
{
PyObject * self;
PyObject * args;
char * command;
int sts;

if ( !PyArg_ParseTuple(args, "s" , &command))
return NULL;

sts = system(command);
return Py_BuildValue("i",sts);
}

static PyMethodDef SpamMethods[] = {
{ "system", spam_system , METH_VARARGS,"Execute a
shell command"},
{NULL,NULL,0,NULL}
};

void initspam(void){
(void) Py_InitModule("spam", SpamMethods);
}


int main(int argc,char **argv)
{
// Py_SetProgName(argv[0]);

/* I COMMENTED THE ABOVE CALL AS IT GAVE ME SOME WIERD
ERROR */

Py_Initialize();

initspam();
}

i was able to compile the above code using disutils
package available with python .

http://www.python.org/doc/2.2.3/ext/building.html

I was even able to import the module into the python
interpreter but caling the function gave me the
following error


Code:
import spam
spam.system("ls -l")
python: Python/getargs.c:90: vgetargs1: Assertion
`compat || (args != (PyObject*)((void *)0))' failed.
Aborted
[haynes at fosters:~/python]
whaaaaattttt????

any idea?

thnks

Haynes Mathew


Send instant messages to your online friends http://in.messenger.yahoo.com

Search Discussions

  • Fredrik Lundh at Jan 9, 2006 at 4:25 pm

    "haynes george" wrote:

    I was reading the tutorial "Extending and Embedding
    the python interpreter" available with python ..

    http://www.python.org/doc/2.2.3/ext/ext.html

    As per given in the tutorial i created an interface to
    the system() system call.

    this is the code of my module
    your code doesn't compile:

    spam.c(5) : error C2082: redefinition of formal parameter 'self'
    spam.c(6) : error C2082: redefinition of formal parameter 'args'
    spam.c(10) : warning C4047: 'function' : 'struct _object *' differs in levels of in
    direction from 'int '
    spam.c(10) : warning C4024: 'PyArg_ParseTuple' : different types for formal and
    actual parameter 1
    spam.c(18) : warning C4113: 'struct _object *(__cdecl *)()' differs in parameter
    lists from 'struct _object *(__cdecl *)(struct _object *,struct _object *)'

    if I fix the argument stuff so that the code matches the example in
    the extending/embedding manual, the spam.system() call works just
    fine over here.
    int main(int argc,char **argv)
    umm.

    what made you think it was a good idea to put a main() function in
    an extension ? the interpreter (or embedding application) already has
    one, so you don't need to add another one...
    {
    // Py_SetProgName(argv[0]);

    /* I COMMENTED THE ABOVE CALL AS IT GAVE ME SOME WIERD
    ERROR */
    weird as in

    unresolved external symbol _Py_SetProgName

    ? (it's Py_SetProgramName, not Py_SetProgName).
    I was even able to import the module into the python
    interpreter but caling the function gave me the
    following error

    Code:
    import spam
    spam.system("ls -l")
    python: Python/getargs.c:90: vgetargs1: Assertion
    `compat || (args != (PyObject*)((void *)0))' failed.
    Aborted
    [haynes at fosters:~/python]
    whaaaaattttt????

    any idea?
    did you look for warnings from your compiler ?

    </F>

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
grouppython-list @
categoriespython
postedJan 9, '06 at 3:58p
activeJan 9, '06 at 4:25p
posts2
users2
websitepython.org

2 users in discussion

Haynes george: 1 post Fredrik Lundh: 1 post

People

Translate

site design / logo © 2022 Grokbase