473,382 Members | 1,447 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,382 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 3171
bartonc
6,596 Expert 4TB
The swig users mail list is actually quite good.
Oct 8 '07 #2

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

Similar topics

2
by: satish | last post by:
Hello all, I have a shared object executable viz. *cable* which I execute as follows : $ ansyscust71 -custom cable -p ANSYSRF **ansyscust71 is a shell script and is a part of a software...
5
by: Fra-it | last post by:
Hi everybody, I'm trying to make the following code running properly, but I can't get rid of the "SEGMENTATION FAULT" error message when executing. Reading some messages posted earlier, I...
99
by: Shi Mu | last post by:
Got confused by the following code: >>> a >>> b >>> c {1: , ], 2: ]} >>> c.append(b.sort()) >>> c {1: , ], 2: , None]}
18
by: Digital Puer | last post by:
Hi, I'm coming over from Java to C++, so please bear with me. In C++, is there a way for me to use exceptions to catch segmentation faults (e.g. when I access a location off the end of an array)?...
27
by: Paminu | last post by:
I have a wierd problem. In my main function I print "test" as the first thing. But if I run the call to node_alloc AFTER the printf call I get a segmentation fault and test is not printed! ...
2
by: robert | last post by:
When employing complex UI libs (wx, win32ui, ..) and other extension libs, nice "only Python stack traces" remain a myth. Currently I'm hunting again a rare C-level crash bug of a Python based...
3
by: madunix | last post by:
My Server is suffering bad lag (High Utlization) I am running on that server Oracle10g with apache_1.3.35/ php-4.4.2 Web visitors retrieve data from the web by php calls through oci cobnnection...
3
by: ShambhuHubli | last post by:
Hi all!! .. I am New member to this group. And also new to C/PYTHON API coding. I am trying to have two way communication i,e i am calling from python to C and then from C to python. I have no...
9
by: Randy.Galbraith | last post by:
I'm investigating the possible use of Mecurial SCM as a replacement for CVS. Mecurial is written in Python. I have a background in GNU/ Linux, Solaris, sparc and Perl. However AIX, powerpc and...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

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.