SWIG + print value of pointer

Java and Swing codecraig at gmail.com
Fri Oct 7 10:51:46 EDT 2005


I am using SWIG to wrap a C application for use in Python.

C code
======
// returns a pointer to an array of long values in the string, "input"
// MY_DIGIT is a typedef such as, typedef unsigned long MY_DIGIT;
MY_DIGIT *Split(char *input) { ... }

..I build a DLL named, _MyApp.dll

SWIG interface
==============
%module MyApp
extern MY_DIGIT *Split(char *input, char *delimiters);

%include cpointer.i
%pointer_functions(MY_DIGIT, md_ptr);

Python
=============
>> from MyApp import *
>> msg = "5,7,1,0,4,6,9"
>> delims = ","
>> results = Split(msg, delims)
>> str(results)
'_401ba700_p_MY_DIGIT'
>> repr(results)
'<Swig Object at _401ba700_p_MY_DIGIT>'
>> print results

...when I print "results" python.exe crashes

...any idea why it crashes?  Why can't I print it?  FYI, if it matters,
I do the same steps in the main method of my C code and there is no
problem.

thanks.




More information about the Python-list mailing list