472,958 Members | 1,853 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,958 software developers and data experts.

c++, swig and mpatrol


i am not sure whether this problem relates to swig, python or my c++ compiler.
+please forgive me if this is inappropriately posted but i am sure that someone
+on this list must have some good ideas. i have also sent i to the swig
users list a couple of times but have not got any response so i am casting
my net a little wider...

i have been struggling with the following problem for a couple of days now.
+specifically, i have a logger class within a larger project. this class
is coded in c++ but this is all wrapped up in a python interface which i
generate with swig. recently i built the project with mpatrol and got some
errors like:

ERROR: [NOTALL]: free: 0x0806E758 has not been allocated

so i trimmed down all the excess stuff until i had the minimum code which still
+produced the errors.

the header file looks like:

-- log.h -----------------------------------------------------------------------

#ifndef _LOG_H
#define _LOG_H

#include <string>

class Logger {
void debug(const std::string msg) {cerr << msg << endl;}

extern Logger logger;



and this is swig'd via the following simple interface file:

-- log.i -----------------------------------------------------------------------

%module log

#include "log.h"

%include std_string.i

%include log.h

%pythoncode %{
logger = _log.cvar.logger


the global instance of the Logger class, logger, is the only thing in the source
+file log.cc.

i build the project with the following:

-- Makefile --------------------------------------------------------------------

%.o: %.cc
g++ -I/usr/local/include/python2.3 -g -O -c $<

_logmodule.so: log.o log_wrap.o
g++ -shared -o $@ $^ -lmpatrol -lbfd

log_wrap.cc log.py: log.i
swig -c++ -python -shadow -o log_wrap.cc $<


now, when i run this snippet of python code:

import log

msg = "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx xxxxxxxxxxxxxxx"

the mpatrol.log file has:

FREE: free (0x0804BA18) [-|-|-]
0x001280C9 _wrap_Logger_debug+897
0x0017A3C6 PyCFunction_Call+150
0x001543F9 PyObject_Call+45
0x001AF0A2 PyEval_CallObjectWithKeywords+206
0x001A4113 builtin_apply+323
0x0017A3C6 PyCFunction_Call+150
0x001AF1F1 call_function+301
0x001AD864 eval_frame+10576
0x001AE824 PyEval_EvalCodeEx+1848
0x001B0EB9 fast_function+297
0x001AF27A call_function+438
0x001AD864 eval_frame+10576
0x001AE824 PyEval_EvalCodeEx+1848
0x001B0D26 PyEval_EvalCode+50
0x001D1144 run_node+76
0x001D10E7 run_err_node+47
0x001D0DE3 PyRun_FileExFlags+107
0x001CF832 PyRun_SimpleFileExFlags+406
0x001D092F PyRun_AnyFileExFlags+107
0x001D7277 Py_Main+2119
0x08048611 main+33
0x002C717D __libc_start_main+189
0x08048531 _start+33

ERROR: [NOTALL]: free: 0x0804BA18 has not been allocated

which seems to indicate that memory is being free'd without be previously
+allocated. the odd thing is that if i either:

o compile with -O0,
o make the msg string ("xxx....xxx") one character shorter

then the error goes away. this seems very mysterious to me given that it is a
+very simple little module.

if i set MPATROL_OPTIONS="CHECKALL USEDEBUG" then there is a little more

FREE: free (0x0806F448)
0x001280C9 _wrap_Logger_debug+897 at
0x0017A3C6 PyCFunction_Call+150 at
0x001543F9 PyObject_Call+45 at
0x001AF0A2 PyEval_CallObjectWithKeywords+206 at
0x001A4113 builtin_apply+323 at
0x0017A3C6 PyCFunction_Call+150 at

from which i gather that it is choking on something in stl_alloc.h. i was under
+the impression that stl was pretty failsafe regarding memory management. i mean
+there's nothing fancy in my source files.

here are some details of my system:


i would be very grateful if anyone had any ideas what might be causing this

best regards,
andrew collier.

Andrew B. Collier
Antarctic Research Fellow tel: +27 31 2601157
Space Physics Research Institute fax: +27 31 2616550
University of Natal, Durban, 4041, South Africa

Jul 18 '05 #1
0 1573

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

Similar topics

by: Jon Moldover | last post by:
Hi, I'm using Python in my win32 app by linking to the python23.dll. I'm trying to expose some c++ code in my app to Python so I can make application calls from Python scripts (according to the...
by: Ernie | last post by:
Hi, I am learning swig to use C codes from Python. Here is the swig file mvf.i: %module mvf %include "carrays.i" %array_class(double, doubleArray); %typemap(out) double, float "$result =...
by: Kevin Dahlhausen | last post by:
Could anyone post a simple setup.py script that uses a SWIG interface to C++ code and the mingw compiler? I followed some online samples, and am using the setup.cfg file to specify swig-c++=1....
by: It's me | last post by:
I am playing around with SWING building a Python module using the no brainer example in http://www.swig.org/tutorial.html. With that first example, /* File : example.c */ #include <time.h>...
by: Andrew Collier | last post by:
hello, i am not sure whether this problem relates to swig, python or my c++ compiler. +please forgive me if this is inappropriately posted but i am sure that someone +on this list must have some...
by: iceColdFire | last post by:
Hi, I have been using mPatrol for sometime now...I want the tool to check on memeory leaks and other memory nicthes in my VC++ 6.0 programs... Does it run on Windows Intel X86 combo... If...
by: Java and Swing | last post by:
I am trying to wrap some C code I have. Currently I have something like... defs.h ----------- typedef unsigned long MY_DIGIT; myapp.c ------------- void MakeDigits(MY_DIGIT digits) {
by: ajikoe | last post by:
Hi, I tried to follow the example in swig homepage. I found error which I don't understand. I use bcc32, I already include directory where my python.h exist in bcc32.cfg. /* File : example.c...
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=()=>{
by: DJRhino | last post by:
Was curious if anyone else was having this same issue or not.... I was just Up/Down graded to windows 11 and now my access combo boxes are not acting right. With win 10 I could start typing...
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...
by: Aliciasmith | last post by:
In an age dominated by smartphones, having a mobile app for your business is no longer an option; it's a necessity. Whether you're a startup or an established enterprise, finding the right mobile app...
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...
by: NeoPa | last post by:
Introduction For this article I'll be using a very simple database which has Form (clsForm) & Report (clsReport) classes that simply handle making the calling Form invisible until the Form, or all...
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...
by: NeoPa | last post by:
Introduction For this article I'll be focusing on the Report (clsReport) class. This simply handles making the calling Form invisible until all of the Reports opened by it have been closed, when it...
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.