471,330 Members | 1,835 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,330 software developers and data experts.

Python : segmentation fault

Hello everyone
I try to extend Python using a simple C wrapped module . This module includes embedded python code and it is product of Swig . The corresponding files follows :

Expand|Select|Wrap|Line Numbers
  1. //main.c
  2. #include "Python.h"
  3. #include <stdio.h>
  4.  
  5. int main()
  6. {
  7.     Py_Initialize();
  8.     PyRun_SimpleString("execfile('simple.py') \n");
  9.     Py_Finalize();
  10.     return 0;
  11. }
Expand|Select|Wrap|Line Numbers
  1. //simple.py
  2.  
  3. print " Hello, everyone"
Expand|Select|Wrap|Line Numbers
  1. /* example.i */
  2.  
  3. %module example
  4.  
  5. %{
  6. #include "Python.h"
  7. int main();
  8. %}
  9. #include "Python.h"
  10. int main();
Expand|Select|Wrap|Line Numbers
  1. //extend.py
  2.  
  3. import _example
  4. _example.main()


The file main.c embeds python , which only execute the file simple.py. The example.i is the interface file , which is used from Swig to generate the desirable module _example.so . This module called from script python file, extend.py for execution.

To do those things from Linux command prompt I execute the following commands:

$ swig -python example.i
$gcc -c main.c example_wrap.c -Dmain=oldmain -I/usr/include/python2.5
$ld -shared example_wrap.o main.o -o _example.so
$python extend.py
Hello everyone
Segmentation fault (core dumped)

Why does the last message appear ? Swig supports wrapping of embedded with python , C code? Do you have any idea how to solve this problem ?I will appreciate any answers .
Thanks a lot
Oct 8 '07 #1
1 3035
bartonc
6,596 Expert 4TB
The swig users mail list is actually quite good.
Oct 8 '07 #2

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

2 posts views Thread by satish | last post: by
5 posts views Thread by Fra-it | last post: by
99 posts views Thread by Shi Mu | last post: by
18 posts views Thread by Digital Puer | last post: by
27 posts views Thread by Paminu | last post: by
3 posts views Thread by madunix | last post: by
9 posts views Thread by Randy.Galbraith | last post: by
reply views Thread by rosydwin | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.