473,581 Members | 2,757 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Segmentation Fault

I would like to ask a question. How do one handle the exception due to
Segmentation fault due to Python ? Our bit operations and arithmetic
manipulations are written in C and to some of our testcases we
experiance Segmentation fault from the python libraries.

If i know how to handle the exception for Segmentation fault , it will
help me complete the run on any testcase , even if i experiance Seg
Fault due to any one or many functions in my testcase.

Aug 28 '06 #1
7 5864
pycraze wrote:
I would like to ask a question. How do one handle the exception due to
Segmentation fault due to Python ? Our bit operations and arithmetic
manipulations are written in C and to some of our testcases we
experiance Segmentation fault from the python libraries.

If i know how to handle the exception for Segmentation fault , it will
help me complete the run on any testcase , even if i experiance Seg
Fault due to any one or many functions in my testcase.
AFAIK, seg fault kills your program dead. There's no exception to
handle. If you're getting seg faults from the python standard library,
that's a pretty serious thing, way more serious than just not-passed
testcases.

An uncaught exception in python should generate a traceback. If it
does, please post that.

Whether it does or not, could you post a minimal example of the code
that causes the seg fault? Python standard lib is fairly robust but of
course not bullet-proof. If there's a way to make it seg fault (and
it's in the standard lib and not your C code) people will want to know.

HTH,
~Simon

Aug 28 '06 #2
pycraze wrote:
I would like to ask a question. How do one handle the exception due to
Segmentation fault due to Python ?
This is confusing. A seg fault kills the process immediately. No
exception (in the Python sense of that word) is raised.
Our bit operations and arithmetic
manipulations are written in C
Do you have a Python extension that is written in C, or are you
embedding Python in a C program -- in other words, is a Python script
calling a C function, or is a C program calling a Python function?
and to some of our testcases we
experiance Segmentation fault from the python libraries.
What is it that you are calling "the python libraries"? Tell us the
filenames of these libraries. *Show us what is output on your stderr
when you experience "Segmentati on fault from the python libraries".*

Was this Python/C combination recently created by current personnel, or
do we have a case of vanished author(s)?
>
If i know how to handle the exception for Segmentation fault , it will
help me complete the run on any testcase , even if i experiance Seg
Fault due to any one or many functions in my testcase.
It would also help if you told us what platform (hardware and software)
that you are running on, what version of Python, and what versions of
any 3rd-party Python modules/packages that may be involved.

Cheers,
John

Aug 28 '06 #3
pycraze wrote:
I would like to ask a question. How do one handle the exception due to
Segmentation fault due to Python ? Our bit operations and arithmetic
manipulations are written in C and to some of our testcases we
experiance Segmentation fault from the python libraries.

If i know how to handle the exception for Segmentation fault , it will
help me complete the run on any testcase , even if i experiance Seg
Fault due to any one or many functions in my testcase.
You will observe, if you look at the list of Python exceptions, that a
segfault isn't among them. A segfault is a trap to the hardware, and
generally indicates that a program is so badly hosed that it wouldn't
make much sense to rely on any further computation in it.

regards
Steve
--
Steve Holden +44 150 684 7255 +1 800 494 3119
Holden Web LLC/Ltd http://www.holdenweb.com
Skype: holdenweb http://holdenweb.blogspot.com
Recent Ramblings http://del.icio.us/steve.holden

Aug 28 '06 #4
pycraze wrote:
I would like to ask a question. How do one handle the exception due to
Segmentation fault due to Python ? Our bit operations and arithmetic
manipulations are written in C and to some of our testcases we
experiance Segmentation fault from the python libraries.
From what you said, I guess you mean that you have written some extensions
to Python in C, but that the segmentation fault is generated when you call
standard Python library functions.

Most likely your C code has bugs: quite possibly you have messed up
reference counting so some objects you use are being freed and then the
Python libraries allocate other objects into the same memory. It is very
easy to do that especially if you are in the habit of trying to 'borrow'
references instead of religiously incrementing/decrementing reference
counts everywhere.

Try to eliminate the problem down to the smallest reproducable code sample
and post that.

Another suggestion I would make is to see if you can use ctypes or Pyrex to
form the glue between Python and C so that none of the C code you write
knows anything about Python. That should eliminate some possible sources
for error.
Aug 28 '06 #5
"Simon Forman" <ro*********@ya hoo.comwrites:
pycraze wrote:
>I would like to ask a question. How do one handle the exception due to
Segmentation fault due to Python ? Our bit operations and arithmetic
manipulation s are written in C and to some of our testcases we
experiance Segmentation fault from the python libraries.

If i know how to handle the exception for Segmentation fault , it will
help me complete the run on any testcase , even if i experiance Seg
Fault due to any one or many functions in my testcase.

AFAIK, seg fault kills your program dead. There's no exception to
handle. If you're getting seg faults from the python standard library,
that's a pretty serious thing, way more serious than just not-passed
testcases.
Segfault handling is platform-dependant... So, at least on unix-like
platform, you can use the signal module to detect segfault:

import signal

def handler(signum, frame):
print 'Segfault detected'
# you may use the stack frame here to help debugging

signal.signal(s ignal.SIGSEGV, handler)

--
Thomas SAMSON
"You're very sure of your facts, " he said at last, "I
couldn't trust the thinking of a man who takes the Universe
- if there is one - for granted. "
Aug 28 '06 #6
th***********@g mail.com wrote:
"Simon Forman" <ro*********@ya hoo.comwrites:
pycraze wrote:
I would like to ask a question. How do one handle the exception due to
Segmentation fault due to Python ? Our bit operations and arithmetic
manipulations are written in C and to some of our testcases we
experiance Segmentation fault from the python libraries.

If i know how to handle the exception for Segmentation fault , it will
help me complete the run on any testcase , even if i experiance Seg
Fault due to any one or many functions in my testcase.
AFAIK, seg fault kills your program dead. There's no exception to
handle. If you're getting seg faults from the python standard library,
that's a pretty serious thing, way more serious than just not-passed
testcases.

Segfault handling is platform-dependant... So, at least on unix-like
platform, you can use the signal module to detect segfault:

import signal

def handler(signum, frame):
print 'Segfault detected'
# you may use the stack frame here to help debugging

signal.signal(s ignal.SIGSEGV, handler)

--
Thomas SAMSON
"You're very sure of your facts, " he said at last, "I
couldn't trust the thinking of a man who takes the Universe
- if there is one - for granted. "
It's good to know that this is possible. However, it's almost
certainly a bad idea to "catch" seg faults and then just proceed with
further testcases. Printing out debugging information would be pretty
good though.

Peace,
~Simon

Aug 28 '06 #7
"pycraze" <de************ *@wipro.comwrit es:
>I would like to ask a question. How do one handle the exception due to
Segmentation fault due to Python ? Our bit operations and arithmetic
manipulation s are written in C and to some of our testcases we
experiance Segmentation fault from the python libraries.
You don't happen to be using the MSDOS executable do you? I find I get
a segmentation violation with the MSDOS version when I try to print
coloured text. I think I have narrowed it down further: to the situation
where coloured text extends to or beyond the edge of the screen--maybe
it's the text wrapping that causes the seg fault.
--
John Savage (my news address is not valid for email)
Aug 31 '06 #8

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
6795
by: sivignon | last post by:
Hi, I'm writing a php script which deals with 3 ORACLE databases. This script is launch by a script shell on an linux machine like this : /../php/bin/php ./MySript.php (PHP 4.3.3) My script works fine and do all what I need. But at the end of the execution, I can read "Segmentation Fault". The segmentation fault appear at the end of my...
3
1939
by: diyanat | last post by:
i am writing a cgi script in C using the CGIC library, the script fails to run, i am using apache on linux error report from apache : internal server error Premature end of script headers: /var/www/cgi-bin/script.cgi when i debug the program i get Segmentation fault gdb ./script.cgi
16
8968
by: laberth | last post by:
I've got a segmentation fault on a calloc and I don'tunderstand why? Here is what I use : typedef struct noeud { int val; struct noeud *fgauche; struct noeud *fdroit; } *arbre; //for those who don't speak french arbre means tree.
3
11404
by: Zheng Da | last post by:
Program received signal SIGSEGV, Segmentation fault. 0x40093343 in _int_malloc () from /lib/tls/libc.so.6 (gdb) bt #0 0x40093343 in _int_malloc () from /lib/tls/libc.so.6 #1 0x40094c54 in malloc () from /lib/tls/libc.so.6 It's really strange; I just call malloc() like "tmp=malloc(size);" the system gives me Segmentation fault I want to...
5
2984
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 understood that a segmentation fault can occur whenever I declare a pointer and I leave it un-initialized. So I thought the problem here is with the (const...
18
26081
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)? Thanks.
27
3340
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! #include <stdlib.h> #include <stdio.h> typedef struct _node_t {
3
5153
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 from 10g release2 PHP is configured with the following parameters './configure' '--prefix=/opt/oracle/php' '--with-apxs=/opt/oracle/apache/bin/apxs'...
6
5029
by: DanielJohnson | last post by:
int main() { printf("\n Hello World"); main; return 0; } This program terminate just after one loop while the second program goes on infinitely untill segmentation fault (core dumped) on gcc. The only difference is that in first I only call "main" and in second call
0
7804
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
8310
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
0
6563
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
1
5681
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
5366
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3832
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2307
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1409
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
1144
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

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.