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

Home Posts Topics Members FAQ

Help! Python either hangs or core dumps when calling C malloc

Lil
Hi Everyone! I've been trying to figure out this weird bug in my
program. I have a python program that calls a C function that reads in
a binary file into a buffer. In the C program, buffer is allocated by
calling malloc. The C program runs perfectly fine but when I use python
to call the C function, it core dumps at malloc.
I've tried multiple binary files with different sizes and the result
is:

if file size is < 20 bytes , works fine
if file size is > 20 bytes, it hangs or core dumps.

Please help!!
Lil

Sep 8 '05 #1
9 2229
Question: Why not just use Python to read the file?

f=open(filename , 'rb')
fcontents=f.rea d()

If you need to manipulate what is in fcontents you
can use struct module and/or slicing.

Larry Bates
Lil wrote:
Hi Everyone! I've been trying to figure out this weird bug in my
program. I have a python program that calls a C function that reads in
a binary file into a buffer. In the C program, buffer is allocated by
calling malloc. The C program runs perfectly fine but when I use python
to call the C function, it core dumps at malloc.
I've tried multiple binary files with different sizes and the result
is:

if file size is < 20 bytes , works fine
if file size is > 20 bytes, it hangs or core dumps.

Please help!!
Lil

Sep 8 '05 #2
Lil
Hi Larry,
It's in the C code mainly because the buffer is an input to the
driver. The driver takes a char* as input and I didn't want to pass a
char* from python -> swig -> C since swig has memory leaks passing
pointers.
Do you think this is a Python issue or a Red Hat issue? I'm going to
try it on my windows machine now and see what happens.

thanks! Lil

Sep 8 '05 #3
"Lil" <li*******@gmai l.com> wrote:
It's in the C code mainly because the buffer is an input to the
driver. The driver takes a char* as input and I didn't want to pass a
char* from python -> swig -> C since swig has memory leaks passing
pointers.
Do you think this is a Python issue or a Red Hat issue?


I think we would have noticed by now if Python or Red Hat weren't
able to allocate and read 20 bytes. It's a bug in your program, and
you should concentrate on fixing it, not looking for bugs everywhere
else.

(quick guess: did you perhaps type malloc(sizeof(b ytes)) instead of
malloc(bytes), or something similar)

</F>

Sep 8 '05 #4
Lil
I already double checked my C code. It runs perfectly fine in C without
any errors. So in my python program, I added a pdb.set_trace()
and step through the program and it did not dump. But when i took out
the tracing, the core dump came back. "sigh"

Sep 8 '05 #5
Lil wrote:'
I already double checked my C code. It runs perfectly fine in C without
any errors. So in my python program, I added a pdb.set_trace()
and step through the program and it did not dump. But when i took out
the tracing, the core dump came back. "sigh"


so triple-check it.

if your code overwrites the malloc buffer, it's perfectly possible
that it appears to run fine when you run it standalone or under the
debugger, but that doesn't mean that your code is fine.

</F>

Sep 8 '05 #6
"Fredrik Lundh" <fr*****@python ware.com> writes:
Lil wrote:'
I already double checked my C code. It runs perfectly fine in C without
any errors. So in my python program, I added a pdb.set_trace()
and step through the program and it did not dump. But when i took out
the tracing, the core dump came back. "sigh"


so triple-check it.

if your code overwrites the malloc buffer, it's perfectly possible
that it appears to run fine when you run it standalone or under the
debugger, but that doesn't mean that your code is fine.


The appropriate aphorism is: "Testing can never reveal the absence of
bugs."

<mike
--
Mike Meyer <mw*@mired.or g> http://www.mired.org/home/mwm/
Independent WWW/Perforce/FreeBSD/Unix consultant, email for more information.
Sep 9 '05 #7
"Lil" <li*******@gmai l.com> wrote in message
news:11******** *************@o 13g2000cwo.goog legroups.com...
I already double checked my C code. It runs perfectly fine in C without
any errors. So in my python program, I added a pdb.set_trace()
and step through the program and it did not dump. But when i took out
the tracing, the core dump came back. "sigh"


Check your program for _uninitialized_ variables_.
(Just a guess: but what other side-effect than
changing the values of uninitialized variables
- and the program's timing, of course - might
the stepping through with a debugger have?)

Regards,
Christian
Sep 9 '05 #8

"Lil" <li*******@gmai l.com> wrote in message
news:11******** *************@o 13g2000cwo.goog legroups.com...
I already double checked my C code. It runs perfectly fine in C without
any errors.
Errr - It runs perfectly fine without *announcing* any errors (while
gleefully urinating all over its memory space).

The programming model for "C" is "*you* asked for it, you got it mate!" - so
you have to "tell" the program how to debug memory by rebuilding it with
f.ex. Electric Fence, or whatever memory debug lib is preferred for your
box, and running that again.

The tools will spot mistakes faster and more reliable than the developer who
wrote the code. Use them.
So in my python program, I added a pdb.set_trace()
and step through the program and it did not dump. But when i took out
the tracing, the core dump came back. "sigh"


So??

You re-jiggled the bits, so something important got thrashed this time.

Run the C program trough with gdb and see what it does. It thrashes
something.
Sep 20 '05 #9

"Christian Stapfer" <ni*@dev.nul> wrote in message
news:df******** **@news.hispeed .ch...
Check your program for _uninitialized_ variables_.
good point.
(Just a guess: but what other side-effect than
changing the values of uninitialized variables
- and the program's timing, of course - might
the stepping through with a debugger have?)


that, f.ex. with some debuggers, all application memory is conveniently
zeroed so you might survive popping NOP's off the stack until you eventually
hit a valid return ...

I once traced through an embedded assembly program - that had been working
for years - with a logic analyser to re-create the source from the old flow
charts and the hundreds of patches that had been applied to the thing during
"comissioni ng", i.e. On Site Development.

I found that the "correct" program would somtimes get hit by an unitialised
interupt, the CPU would land between two instructions and start executing
garbage until it chrashed over something else and magically re-synchronised.
Fine stuff.

The reassembled program executed 40% faster without all the jump-to-patch
stuff so I had to re-adjust all the timers too.
Sep 20 '05 #10

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

Similar topics

21
6554
by: Dave | last post by:
After following Microsofts admonition to reformat my system before doing a final compilation of my app I got many warnings/errors upon compiling an rtf file created in word. I used the Help Workshop program: hcw.exe that's included with Visual Basic. This exact same file compiled perfectly with no notes, warnings or errors prior to reformatting my system. Prior to the reformatting, I copied the help.rtf file onto a CD and checked the box to...
2
6481
by: Sudheer Kareem | last post by:
Dear All Please tell me how to assosiate help files with my Vb.net Project. Regards Sudheer
6
4346
by: wukexin | last post by:
Help me, good men. I find mang books that introduce bit "mang header files",they talk too bit,in fact it is my too fool, I don't learn it, I have do a test program, but I have no correct doing result in any way. Who can help me, I thank you very very much. list.cpp(main program) //-------------------------------------------------------------------------- - #pragma hdrstop #pragma argsused
6
3024
by: d.warnermurray | last post by:
I am doing a project for school that involves creating help files for a html authoring tool. If you could help me with answers to some questions it would really help. 1. What tasks do you expect an html authoring tool to help you accomplish? 2. What do you expect from online help for a html authoring tool? 3. What audience do you think a freeware html authoring tool is directed towards?
27
2823
by: Bruce Dodds | last post by:
I recently started using Access 2003 for the first time. I wanted to pass on some comments about the Help system to Access MVPs who frequent this board. I'm doing this in the hope that some of what I say may be passed on to Microsoft. Microsoft has implemented a combination local and web based help system in Access 2003. The local Help installed on your hard drive is fast, but the content is abbreviated. For really useful help you have...
5
3382
by: Steve Teeples | last post by:
Can someone point me to a document that clearly identifies the steps of creating a good help system for an application? I have a test tool that I'd like to add help to so that others will know how to use it. -- Steve
0
1510
by: Yabedabe | last post by:
Hello there, I have a strange problem (possible bug?) to display two HTML Help files at the same time. To reproduce this problem. Create a new VB.Net solution. Place two buttons on the form. Create two button_click events with the following code in it For button1 Help.ShowHelpIndex(Me, "C:\Temp\File1 mspaint.chm")
1
1380
by: JJ | last post by:
Ok I have now got to grips with HTML help workshop and created my help files, TOC etc. Now how do I integrate this with my application? I have added an errorprovider to my form and pointed it to my hhp file, but I am not sure which is the correct next step. Specifically my questions are: 1. How do I get the index, table of contents menu items to link to the help file
4
2254
by: Fred Flintstone | last post by:
This one baffles me. I'm using VS.Net 2005 and write desktop apps that need built in help. So logically, I figure maybe VS has a help system component built in so I search the help. Hey! Apparently, all I have to do is create a "Help Project"! There's my starting point. So the VS help says: "To create a Help project, click on the File menu, choose New and follow the wizard's instructions"
1
6136
by: trunxnirvana007 | last post by:
'UPGRADE_WARNING: Array has a new behavior. Click for more: 'ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?keyword="9B7D5ADD-D8FE-4819-A36C-6DEDAF088CC7"' 'UPGRADE_WARNING: Couldn't resolve default property of object Label. Click for more: 'ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?keyword="6A50421D-15FE-4896-8A1B-2EC21E9037B2"' Label = New Object(){Box1, Box2, Box3, Box4, Box5, Box6, Box7, Box8, Box9, Box10, Box11,...
0
9297
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 synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9904
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 captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
9884
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9735
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
7285
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 instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6556
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 into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5168
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
3
3395
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2697
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 effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.