Python C/API Problem

G

Gianfranco Murador

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;
}

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?
Thanks.
greetings, G.
 
P

Philip Semanchuk

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;
}

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
 
G

Gabriel Genellina

En Fri, 11 Sep 2009 15:10:45 -0300, Gianfranco Murador
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;
}
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

The second argument to PyParser_SimpleParseString must be one of
Py_eval_input, Py_file_input or Py_single_input - not 0.
Anyway, if this is the actual cause of your segfault, seems that a
validation should be added somewhere...
 
G

Gianfranco Murador

Yes, i've done some debugging and the error is on
PyParser_SimpleParseString(..) call. I'll try to change the second
arguments..
Thank to all.
 
G

Gianfranco Murador

Ok, I solved the previous error changing the second argument , but i
have another question. Does PyNode_Compile function store the object
code in the file passed as argument? And it will be execute by python?
I mean, it works if i type 'python prova.pyc'?
Thank.
 
G

Gabriel Genellina

En Sat, 12 Sep 2009 07:37:18 -0300, Gianfranco Murador
Ok, I solved the previous error changing the second argument , but i
have another question. Does PyNode_Compile function store the object
code in the file passed as argument? And it will be execute by python?
I mean, it works if i type 'python prova.pyc'?

No; the filename you pass in is just to set the co_filename attribute of
code objects, and such things.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,070
Latest member
BiogenixGummies

Latest Threads

Top