472,954 Members | 1,728 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,954 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 3150
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: lllomh | last post by:
Define the method first this.state = { buttonBackgroundColor: 'green', isBlinking: false, // A new status is added to identify whether the button is blinking or not } autoStart=()=>{
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 4 Oct 2023 starting at 18:00 UK time (6PM UTC+1) and finishing at about 19:15 (7.15PM) The start time is equivalent to 19:00 (7PM) in Central...
0
tracyyun
by: tracyyun | last post by:
Hello everyone, I have a question and would like some advice on network connectivity. I have one computer connected to my router via WiFi, but I have two other computers that I want to be able to...
2
by: giovanniandrean | last post by:
The energy model is structured as follows and uses excel sheets to give input data: 1-Utility.py contains all the functions needed to calculate the variables and other minor things (mentions...
4
NeoPa
by: NeoPa | last post by:
Hello everyone. I find myself stuck trying to find the VBA way to get Access to create a PDF of the currently-selected (and open) object (Form or Report). I know it can be done by selecting :...
1
by: Teri B | last post by:
Hi, I have created a sub-form Roles. In my course form the user selects the roles assigned to the course. 0ne-to-many. One course many roles. Then I created a report based on the Course form and...
3
by: nia12 | last post by:
Hi there, I am very new to Access so apologies if any of this is obvious/not clear. I am creating a data collection tool for health care employees to complete. It consists of a number of...
0
isladogs
by: isladogs | last post by:
The next online meeting of the Access Europe User Group will be on Wednesday 6 Dec 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, Mike...
1
by: GKJR | last post by:
Does anyone have a recommendation to build a standalone application to replace an Access database? I have my bookkeeping software I developed in Access that I would like to make available to other...

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.