Daniel Russel | 1 Sep 2011 03:26
Picon
Gravatar

trying to work around mis-parsed scope

I have two namespace with the same name, ::a::b and ::b and need to refer to classes in ::b from within ::a::b.

Swig 2.0.4 correctly parses function arguments named like ::b::MyClass that occur in ::a::b, however,
swig 2.0.1 seems to get them wrong and not realize that ::b::MyClass and the MyClass it wrapped in
namespace ::b are the same class.

Does anyone have any suggestions on how to work around this? We would like to support swig 2.0.1. Thanks.
         --Daniel
------------------------------------------------------------------------------
Special Offer -- Download ArcSight Logger for FREE!
Finally, a world-class log management solution at an even better 
price-free! And you'll get a free "Love Thy Logs" t-shirt when you
download Logger. Secure your free ArcSight Logger TODAY!
http://p.sf.net/sfu/arcsisghtdev2dev
Dan Stanger | 1 Sep 2011 02:43
Picon

Simple noob qestion.

Hello All,
I have a simple file size.i :
#include "windef.h"
struct tagSIZE;

which I process with the following command line, which completes without 
error:
swig.exe -sexp -module size size.i

However, the definition of size is:
typedef struct tagSIZE {
         LONG cx;
         LONG cy;
};

and what I am really interested in is information about the members of 
the struct.
If I process this other file x.i:
struct X {
int i;
double j;
};

I get a file which contains information about the members of X.

Is it possible to get a file similar to the results of processing x.i, 
without substitution of the actual definition of tagSIZE into my file 
size.i ?
Thanks in advance.
Dan Stanger
(Continue reading)

Jon Capps | 1 Sep 2011 06:08
Picon

Re: Simple noob qestion.

On Aug 31, 2011, at 20:43, Dan Stanger <dan.stanger <at> ieee.org> wrote:
> Is it possible to get a file similar to the results of processing x.i, 
> without substitution of the actual definition of tagSIZE into my file 
> size.i ?

Not really. SWIG only exposes what you put in your interface file. If you don't define tagSIZE as having
fields cx and cy, SWIG doesn't know you want them exposed. 

What is the issue with defining the struct in the interface file?

Jon
------------------------------------------------------------------------------
Special Offer -- Download ArcSight Logger for FREE!
Finally, a world-class log management solution at an even better 
price-free! And you'll get a free "Love Thy Logs" t-shirt when you
download Logger. Secure your free ArcSight Logger TODAY!
http://p.sf.net/sfu/arcsisghtdev2dev
Kat | 1 Sep 2011 09:50
Picon
Favicon

Finished product problems


Gday,

Thank you for your help. I managed to compile it.

So I thought I would test it. I can create a small c# stub that calls a 
method, but it all crashes with this output:

Unhandled Exception: System.TypeInitializatopnException: The type 
initializer for 'namespace.modulePINVOKE'threw an exception.
---> System.TypeInitializationException: The type initializer for 
'SWIGExceptionHelper' threw an exception.
--->System.EntryPointNotFoundException:Unable to find an entry point 
named 'SWIGRegisterExceptionCallbacks_modulename' in DLL 'modulename'.

at

TTEC.modulenamePINVOKE.SWIGExceptionHelper.SWIGRegisterExceptionCallbacks_modulename(ExceptionDelegate 
applicationDelegate,
ExceptionDelegate arithmeticDelegate, ExceptionDelegate 
divideByZeroDelegate, ExceptionDelegate indexOutOfRangeDelegate, 
ExceptionDelegate invalidCastDelgate, ExceptionDelegate 
invalidOperationDelegate, ExceptionDelegate ioDelegate, 
ExceptionDelegate nullReferenceDelegate, ExceptionDelegate out 
ofMemoryDelegate, ExceptionDelegate overflowDelegatem ExceptionDelegate 
outOfMemoryDelegatem Exception Delegate overflowDelegate, 
ExceptionDelegate systemExceptionDelegate)

   at namespace.modulenamePINVOKE.SWIGExceptionHelper..cctor()
   --- End of inner exception stack trace ---
(Continue reading)

Dan Stanger | 1 Sep 2011 13:01
Picon

Re: Simple noob qestion.

I am using swig output as input to a code generator, which is why I am 
interested in the struct members.
I would need to generate files containing the structs I want to parse, 
which means I need to extract their definitions into an interface file.
A related question is:
I noticed that after I included the definition of tagSIZE in my 
interface file, the generated code had LONG as the type of cx and cy.
There is a typedef in the include file, which defines LONG as long.
  Is there an option to have the generated code resolve the definition 
of LONG to long?

Thank you,
Dan Stanger

Jon Capps wrote:
> On Aug 31, 2011, at 20:43, Dan Stanger<dan.stanger <at> ieee.org>  wrote:
>    
>> Is it possible to get a file similar to the results of processing x.i,
>> without substitution of the actual definition of tagSIZE into my file
>> size.i ?
>>      
> Not really. SWIG only exposes what you put in your interface file. If you don't define tagSIZE as having
fields cx and cy, SWIG doesn't know you want them exposed.
>
> What is the issue with defining the struct in the interface file?
>
> Jon
> ------------------------------------------------------------------------------
> Special Offer -- Download ArcSight Logger for FREE!
> Finally, a world-class log management solution at an even better
(Continue reading)

Josh Cherry | 1 Sep 2011 18:47
Picon
Favicon

Re: Simple noob qestion.


On Thu, 1 Sep 2011, Dan Stanger wrote:

> I am using swig output as input to a code generator, which is why I am
> interested in the struct members.
> I would need to generate files containing the structs I want to parse,
> which means I need to extract their definitions into an interface file.
> A related question is:
> I noticed that after I included the definition of tagSIZE in my
> interface file, the generated code had LONG as the type of cx and cy.
> There is a typedef in the include file, which defines LONG as long.
>  Is there an option to have the generated code resolve the definition
> of LONG to long?

Are you aware that SWIG ignores #include statements (as opposed to 
%include) by default?  Apologies if I'm pointing out the obvious.

Josh

------------------------------------------------------------------------------
Special Offer -- Download ArcSight Logger for FREE!
Finally, a world-class log management solution at an even better 
price-free! And you'll get a free "Love Thy Logs" t-shirt when you
download Logger. Secure your free ArcSight Logger TODAY!
http://p.sf.net/sfu/arcsisghtdev2dev
Matt Funk | 2 Sep 2011 17:27
Picon

error when using swig with gdal

Hi,
i am a novice to SWIG so forgive me if my question are rather basic. I
am trying to reproduce the python wrappers for the gdal library (ver
1.7.1). Anyway, i get the gdal source (including python extensions).
After configuring i get:

swig -Wall -I../include -I../include/python -I../include/python/docs
-outdir "osgeo"   -I/home/mafunk/Downloads/gdal-1.7.1 -c++ -python -o
extensions/gdal_wrap.cpp ../include/gdal.i
swig -Wall -I../include -I../include/python -I../include/python/docs
-outdir "osgeo"   -I/home/mafunk/Downloads/gdal-1.7.1 -python -o
extensions/gdalconst_wrap.c ../include/gdalconst.i
swig -Wall -I../include -I../include/python -I../include/python/docs
-outdir "osgeo"   -I/home/mafunk/Downloads/gdal-1.7.1 -c++ -python -o
extensions/ogr_wrap.cpp ../include/ogr.i
swig -Wall -I../include -I../include/python -I../include/python/docs
-outdir "osgeo"   -I/home/mafunk/Downloads/gdal-1.7.1 -c++ -python -o
extensions/osr_wrap.cpp ../include/osr.i
swig -Wall -I../include -I../include/python -I../include/python/docs
-outdir "osgeo"   -I/home/mafunk/Downloads/gdal-1.7.1 -c++ -python -o
extensions/gdal_array_wrap.cpp gdal_array.i
SWIG:1: Warning(125): Use of the include path to find the input file is
deprecated and will not work with ccache. Please include the path when
specifying the input file.
sed "s/PyErr_Format(PyExc_RuntimeError,
mesg)/PyErr_SetString(PyExc_RuntimeError, mesg)/"
extensions//gdal_wrap.cpp > extensions//gdal_wrap.cpp.tmp
mv -f extensions//gdal_wrap.cpp.tmp extensions//gdal_wrap.cpp
sed "s/PyErr_Format(PyExc_RuntimeError,
mesg)/PyErr_SetString(PyExc_RuntimeError, mesg)/"
(Continue reading)

Brandon A Jones | 2 Sep 2011 18:12
Picon
Favicon

Segfault on character string in C function

Hello all,

I have searched various boards, with no luck on this problem.  I did find at least one other poster with a
similar problem, but no solution was posted.

I am attempting to interface a C function with Python via SWIG.  This software used to work, but the last time
we used it was 18 months ago and we have since upgraded compilers, OS (upgraded to 64-bit), python
versions, etc.  The function takes two ascii files, and generates a binary file.  The input/output is just
the three file names.  Here is the C-file (convert.c) contents (trimmed down to help isolate the problem):

#include <stdio.h>

int convert(char *infile1name, char *infile2name, char *outfilename)
{

   fprintf( stderr, "convert - %s\n", infile1name );
   fprintf( stderr, "convert - %s\n", outfilename );
   fprintf( stderr, "convert - %p\n", infile2name );
   fprintf( stderr, "convert - %s\n", infile2name );

   return 1;

} /* End: convert.c */

When I run it, infile1name is fine, but it seg faults when I print the string infile2name (final call to
fprintf).  Here are the contents of the SWIG interface file DE_convert.i (again, trimmed down):

%module DE_convert

int convert(char *infile1name, char *infile2name, char *outfilename);
(Continue reading)

A Z | 2 Sep 2011 23:25
Picon

TCL/C: Changing the error codefrom Tcl_Eval

Hello,

  I am using SWIG to generate functions for use with an interactive TCL interpreter. There are many functions where I need to return TCL_ERROR if the command fails. I see that the return value for each function is placed in interp->result but I need to way to change the returned result from Tcl_Eval(). This is how I currently execute each TCL string.

    signed int result = Tcl_Eval(pInterp, line);
   // Tcl_Obj * tclResult = Tcl_GetObjResult(pInterp);
    switch (result)
    {
      case TCL_OK:       printf("TCL_OK\n");break;
      case TCL_ERROR:    printf("TCL_ERROR\n");break;
      case TCL_RETURN:   printf("TCL_RETURN\n");break;
      case TCL_CONTINUE: printf("TCL_CONTINUE\n");break;
      case TCL_BREAK:    printf("TCL_BREAK\n");break;
      default:
      break;
    }
    printf("%s\n",pInterp->result);

I also noticed that of I use incorrect argument types, the SWIG wrapper catches this and returns TCL_ERROR with NULL as the result pointer. So I tried copying the SWIG code to an error function:

static void setTCLError(char * string)
{
  strncpy(errorString,string,ERROR_SIZE);
  Tcl_ResetResult(pInterp);
  Tcl_SetErrorCode(pInterp, "SWIG", errorString, NULL);
  Tcl_AppendResult(pInterp, errorString, " ", errorString, NULL);
}

//SWIG-wrapped C function
static const char * some_c_function()
{
  if(error)
    setTCLError("Error detected");
}

This still results in TCL_OK as the return value. How can force Tcl_Eval to return TCL_ERROR from inside a C function?

Thanks

------------------------------------------------------------------------------
Special Offer -- Download ArcSight Logger for FREE!
Finally, a world-class log management solution at an even better 
price-free! And you'll get a free "Love Thy Logs" t-shirt when you
download Logger. Secure your free ArcSight Logger TODAY!
http://p.sf.net/sfu/arcsisghtdev2dev
_______________________________________________
Swig-user mailing list
Swig-user <at> lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/swig-user
Karl Wette | 5 Sep 2011 15:56
Picon
Gravatar

Change in behaviour of %extend?

Hi,

There seems to be a change in behaviour of %extend between SWIG 1.3.40
and a recent SWIG SVN (r12796). If I try to compile the test module
(code below):

* with SWIG 1.3.40 I get the error message:
test.i:20: Warning(504): Function tagAStruct must have a return type.

* with a recent SWIG SVN I get the error message:
test.i:36: Warning 504: Function CStruct must have a return type. Ignored.

Although these are warnings, the do result in the constructors for
AStruct / CStruct being dropped from the interface.

Is this a regression / change of behaviour / something I'm doing wrong ???

Cheers,
Karl

====================
%module test

%inline {
  typedef struct tagAStruct {
    int ivar;
  } AStruct;
  struct BStruct {
    int ivar;
  };
  typedef struct tagCStruct {
    int ivar;
  } CStruct;
}

%extend tagAStruct {
  tagAStruct(int ivar0) {
    AStruct *s = new AStruct();
    s->ivar = ivar0;
    return s;
  }
}

%extend BStruct {
  BStruct(int ivar0) {
    BStruct *s = new BStruct();
    s->ivar = ivar0;
    return s;
  }
}

%extend CStruct {
  CStruct(int ivar0) {
    CStruct *s = new CStruct();
    s->ivar = ivar0;
    return s;
  }
}
====================

------------------------------------------------------------------------------
Special Offer -- Download ArcSight Logger for FREE!
Finally, a world-class log management solution at an even better 
price-free! And you'll get a free "Love Thy Logs" t-shirt when you
download Logger. Secure your free ArcSight Logger TODAY!
http://p.sf.net/sfu/arcsisghtdev2dev

Gmane