Python C/API Problem

Philip Semanchuk philip at semanchuk.com
Fri Sep 11 16:16:36 EDT 2009


On Sep 11, 2009, at 2:10 PM, Gianfranco Murador wrote:

> Hi to all python fans,
> i'm trying to run this C source file:
> [code]
>
> #include <Python.h>
> #include <structmember.h>
> #include <compile.h>
> #include <dirent.h>
> #include <node.h>
>
>
> int main(int argc, char *argv[]) {
> 	Py_Initialize();
>
> 	struct _node *node = PyParser_SimpleParseString("from time import
> time,ctime\n"
>                     					"print 'Today is',ctime(time())\n",0);
> 	if(node == NULL)
> 	{
> 	printf("Errore nel parsing");
> 	}else{
> 	PyNode_Compile(node, "./prova.pyc");
> 	PyNode_Free(node);
> 	}
>
> 	Py_Finalize();
> 	return 0;
> }
>
> [/code]
>
> I compile the file without errors, but when i launch the executable i
> have a Segmentation Fault. I'm using the shared library of python
> 2.5.2 under linux.. Any ideas? It's clear that i do some mistakes, but
> where?

Hi G,
With some basic debugging you should at least be able to figure out on  
which line the segfault happens. Have you done that?


bye
Philip



More information about the Python-list mailing list