logo       

[Swig-dev] Core dump in SWIG 1.3.17 - (newbie): msg#00108

programming.swig

Subject: [Swig-dev] Core dump in SWIG 1.3.17 - (newbie)

Sharma K M writes:
> I am a newbie to SWIG. Here is my problem:
>
> What is the equivalent of -
> 1. extern const xint8_t *<parameter> = "<value>"
> and
> 2. the corresponding "typemap" statement
> in the following piece of code under SWIG1.3.17?
>
> For your information, the following code used to work
> properly under SWIG 1.1p5.
> =============================
> %typemap(python, out) xint8_t**
> {
> xint32_t len=0;
>
> while($source[len]) len++;
> $target = PyList_New(len);
>
> for(xint32_t i=0;i<len;i++)
> PyList_SetItem($target, i, PyString_FromString($source[i]));
> }
>
> extern const xint8_t *pyBlack = "K";
> extern const xint8_t *pyBlackLow = "KL";
> extern const xint8_t *pyGreyScale = "Grey";
> =============================
>
> With the above codes, under SWIG 1.3.17, I could get
> *_wrap.cxx file with the required C++ methods. But,
> it does NOT generate any statements in the corresponding
> python file. I was expecting the following lines in
> the generated python file:
> ---------------------
> pyBlack = _module.pyBlack
> pyBlackLow = _module.pyBlackLow
> pyGreyScale = _module.pyGreyScale
> ---------------------
>
> Whereas the above lines exist with SWIG 1.1p5 generated
> python files.
>

Well, a bunch of things are happening here. First, a declaration of
the form:

extern const xint8_t *pyBlack = "K";

doesn't define a constant. The reason it doesn't define a constant is
that someone can redefine it's value. For example:

pyBlack = "Foo";

In other words---the pointer value can be changed to point to a
different location. Therefore, this declaration is wrapped as a
global variable. You would access it using:

module.cvar.pyBlack

If you really want it to be a constant, use the %constant directive.

If xint8_t is the same as "char", you shouldn't need to write a
typemap. Just use a typedef or say this:

%apply char { xint8_t };

If you still want to write a typemap, you would use the "varout"
typemap for variables and the "consttab" typemap for constants. To
see examples, look in Lib/python/python.swg.

Cheers,

Dave
_______________________________________________
Swig maillist - Swig@xxxxxxxxxxxxxxx
http://mailman.cs.uchicago.edu/mailman/listinfo/swig



<Prev in Thread] Current Thread [Next in Thread>
Google Custom Search

News | FAQ | advertise