Skip to content

Commit

Permalink
More use of typedefs.i and language i files.
Browse files Browse the repository at this point in the history
A couple of changes to make CSharp bindings compile in Mono. The ToString() is probably not good.
  • Loading branch information
ajolma committed May 28, 2015
1 parent 0af6ec9 commit 6509ef0
Show file tree
Hide file tree
Showing 10 changed files with 69 additions and 115 deletions.
2 changes: 0 additions & 2 deletions gdal/swig/include/cpl.i
Expand Up @@ -30,8 +30,6 @@

%include constraints.i

%include typedefs.i

%inline %{
void Debug( const char *msg_class, const char *message ) {
CPLDebug( msg_class, "%s", message );
Expand Down
7 changes: 6 additions & 1 deletion gdal/swig/include/csharp/gdal_csharp.i
Expand Up @@ -35,6 +35,8 @@

%include typemaps_csharp.i

%include swig_csharp_extensions.i

%apply (int *pList) {int *band_list, int *panHistogram_in};
%apply (double *OUTPUT) {double *min_ret, double *max_ret};
%apply (int *nLen) {int *buckets_ret};
Expand Down Expand Up @@ -218,9 +220,12 @@ public CPLErr SetGCPs(GCP[] pGCPs, string pszGCPProjection) {
public static void FileFromMemBuffer(string utf8_path, byte[] bytes) {
GCHandle handle = GCHandle.Alloc(bytes, GCHandleType.Pinned);
try {
FileFromMemBuffer(utf8_path, bytes.Length, handle.AddrOfPinnedObject());
/* the ToString is probably wrong but I'm no C# expert */
FileFromMemBuffer(utf8_path, bytes.Length, handle.AddrOfPinnedObject().ToString());
} finally {
handle.Free();
}
}
%}

%include "gdal_csharp_extend.i"
4 changes: 3 additions & 1 deletion gdal/swig/include/csharp/ogr_csharp.i
Expand Up @@ -38,6 +38,8 @@

%include typemaps_csharp.i

%include swig_csharp_extensions.i

DEFINE_EXTERNAL_CLASS(OSRSpatialReferenceShadow, OSGeo.OSR.SpatialReference)
DEFINE_EXTERNAL_CLASS(OSRCoordinateTransformationShadow, OSGeo.OSR.CoordinateTransformation)
DEFINE_EXTERNAL_CLASS(GDALMajorObjectShadow, OSGeo.GDAL.MajorObject)
Expand Down Expand Up @@ -89,4 +91,4 @@ DEFINE_EXTERNAL_CLASS(GDALMajorObjectShadow, OSGeo.GDAL.MajorObject)
public Geometry(wkbGeometryType type) : this(OgrPINVOKE.new_Geometry((int)type, null, 0, IntPtr.Zero, null), true, null) {
if (OgrPINVOKE.SWIGPendingException.Pending) throw OgrPINVOKE.SWIGPendingException.Retrieve();
}
}
}
2 changes: 2 additions & 0 deletions gdal/swig/include/csharp/osr_csharp.i
Expand Up @@ -31,3 +31,5 @@
%include cpl_exceptions.i

%include typemaps_csharp.i

%include swig_csharp_extensions.i
6 changes: 5 additions & 1 deletion gdal/swig/include/csharp/swig_csharp_extensions.i
Expand Up @@ -10,10 +10,14 @@
*/

// Ensure the class is not marked BeforeFieldInit causing memory corruption with CLR4
/*
causes static $imclassname() {
} to be twice in classPINVOKE.cs
%pragma(csharp) imclasscode=%{
static $imclassname() {
}
%}
*/

%typemap(csout, excode=SWIGEXCODE) SWIGTYPE {
$&csclassname ret = new $&csclassname($imcall, true, null);$excode
Expand Down Expand Up @@ -92,7 +96,7 @@
%typemap(csbody_derived) SWIGTYPE %{
private HandleRef swigCPtr;

public $csclassname(IntPtr cPtr, bool cMemoryOwn, object parent) : base($modulePINVOKE.$csclassnameUpcast(cPtr), cMemoryOwn, parent) {
public $csclassname(IntPtr cPtr, bool cMemoryOwn, object parent) : base($modulePINVOKE.$csclassname_SWIGUpcast(cPtr), cMemoryOwn, parent) {
swigCPtr = new HandleRef(this, cPtr);
}

Expand Down
45 changes: 3 additions & 42 deletions gdal/swig/include/gdal.i
Expand Up @@ -30,8 +30,6 @@

%include constraints.i

%include typedefs.i

#ifdef PERL_CPAN_NAMESPACE
%module "Geo::GDAL"
#elif defined(SWIGCSHARP)
Expand All @@ -40,28 +38,7 @@
%module gdal
#endif

#ifdef SWIGCSHARP
%include swig_csharp_extensions.i
#endif

//
// We register all the drivers upon module initialization
//

#if defined(SWIGPYTHON) || defined(SWIGJAVA)
%{
#ifdef DEBUG
typedef struct OGRSpatialReferenceHS OSRSpatialReferenceShadow;
typedef struct OGRLayerHS OGRLayerShadow;
typedef struct OGRGeometryHS OGRGeometryShadow;
#else
typedef void OSRSpatialReferenceShadow;
typedef void OGRLayerShadow;
typedef void OGRGeometryShadow;
#endif
typedef struct OGRStyleTableHS OGRStyleTableShadow;
%}
#endif /* #if defined(SWIGPYTHON) || defined(SWIGJAVA) */
%include typedefs.i

//************************************************************************
//
Expand Down Expand Up @@ -195,17 +172,6 @@ typedef enum {
%include "gdal_java.i"
#endif

/* Default memberin typemaps required to support SWIG 1.3.39 and above */
%typemap(memberin) char *Info %{
/* char* Info memberin typemap */
$1;
%}

%typemap(memberin) char *Id %{
/* char* Info memberin typemap */
$1;
%}

//************************************************************************
// Apply NONNULL to all utf8_path's.
%apply Pointer NONNULL { const char* utf8_path };
Expand Down Expand Up @@ -713,6 +679,8 @@ GDALDriverShadow *IdentifyDriver( const char *utf8_path,
}
%}
#endif


%clear char **;


Expand All @@ -723,12 +691,5 @@ GDALDriverShadow *IdentifyDriver( const char *utf8_path,
//************************************************************************

#ifdef SWIGCSHARP
%include "gdal_csharp_extend.i"
#endif

#ifdef SWIGPYTHON
/* Add a __version__ attribute to match the convention */
%pythoncode %{
__version__ = _gdal.VersionInfo("RELEASE_NAME")
%}
#endif
38 changes: 1 addition & 37 deletions gdal/swig/include/ogr.i
Expand Up @@ -27,12 +27,6 @@
* DEALINGS IN THE SOFTWARE.
*****************************************************************************/

%include typedefs.i

#ifndef FROM_GDAL_I
%include "exception.i"
#endif

#ifdef PERL_CPAN_NAMESPACE
%module "Geo::OGR"
#elif defined(SWIGCSHARP)
Expand All @@ -41,9 +35,7 @@
%module ogr
#endif

#ifdef SWIGCSHARP
%include swig_csharp_extensions.i
#endif
%include typedefs.i

%feature("autodoc");

Expand Down Expand Up @@ -145,33 +137,6 @@ typedef enum
} OGRJustification;
#endif

%{
#ifdef DEBUG
typedef struct OGRSpatialReferenceHS OSRSpatialReferenceShadow;
typedef struct OGRDriverHS OGRDriverShadow;
typedef struct OGRDataSourceHS OGRDataSourceShadow;
typedef struct OGRLayerHS OGRLayerShadow;
typedef struct OGRFeatureHS OGRFeatureShadow;
typedef struct OGRFeatureDefnHS OGRFeatureDefnShadow;
typedef struct OGRGeometryHS OGRGeometryShadow;
typedef struct OGRCoordinateTransformationHS OSRCoordinateTransformationShadow;
typedef struct OGRCoordinateTransformationHS OGRCoordinateTransformationShadow;
typedef struct OGRFieldDefnHS OGRFieldDefnShadow;
#else
typedef void OSRSpatialReferenceShadow;
typedef void OGRDriverShadow;
typedef void OGRDataSourceShadow;
typedef void OGRLayerShadow;
typedef void OGRFeatureShadow;
typedef void OGRFeatureDefnShadow;
typedef void OGRGeometryShadow;
typedef void OSRCoordinateTransformationShadow;
typedef void OGRFieldDefnShadow;
#endif
typedef struct OGRStyleTableHS OGRStyleTableShadow;
typedef struct OGRGeomFieldDefnHS OGRGeomFieldDefnShadow;
%}

#ifndef SWIGCSHARP
#ifdef SWIGJAVA
%javaconst(1);
Expand Down Expand Up @@ -288,7 +253,6 @@ typedef struct OGRGeomFieldDefnHS OGRGeomFieldDefnShadow;
%constant char *OLMD_FID64 = "OLMD_FID64";

#else
typedef int OGRErr;

#define wkb25DBit 0x80000000
#define ogrZMarker 0x21125711
Expand Down
29 changes: 2 additions & 27 deletions gdal/swig/include/osr.i
Expand Up @@ -29,8 +29,6 @@

%include constraints.i

%include typedefs.i

#ifdef PERL_CPAN_NAMESPACE
%module "Geo::OSR"
#elif defined(SWIGCSHARP)
Expand All @@ -39,34 +37,11 @@
%module osr
#endif

#ifdef SWIGCSHARP
#ifdef SWIGCSHARPx
%include swig_csharp_extensions.i
#endif

#ifdef SWIGCSHARP
%csconst(1);
#elif defined(SWIGJAVA)
%javaconst(1);
#endif

%include "../../ogr/ogr_srs_api.h"

#ifdef SWIGCSHARP
%csconst(0);
#elif defined(SWIGJAVA)
%javaconst(0);
#endif

%{
#ifdef DEBUG
typedef struct OGRSpatialReferenceHS OSRSpatialReferenceShadow;
typedef struct OGRCoordinateTransformationHS OSRCoordinateTransformationShadow;
typedef struct OGRCoordinateTransformationHS OGRCoordinateTransformationShadow;
#else
typedef void OSRSpatialReferenceShadow;
typedef void OSRCoordinateTransformationShadow;
#endif
%}
%include typedefs.i

#if defined(SWIGPYTHON)
%include osr_python.i
Expand Down
6 changes: 5 additions & 1 deletion gdal/swig/include/python/gdal_python.i
Expand Up @@ -15,7 +15,6 @@
%}

%pythoncode %{


have_warned = 0
def deprecation_warn( module ):
Expand Down Expand Up @@ -726,3 +725,8 @@ CPLErr ReadRaster1( int xoff, int yoff, int xsize, int ysize,
}

%include "callback.i"

/* Add a __version__ attribute to match the convention */
%pythoncode %{
__version__ = _gdal.VersionInfo("RELEASE_NAME")
%}
45 changes: 42 additions & 3 deletions gdal/swig/include/typedefs.i
Expand Up @@ -32,7 +32,20 @@
Typedefs for GDAL types for swig, some extracted from GDAL headers.
*/

#ifdef SWIGCSHARP
%csconst(1);
#elif defined(SWIGJAVA)
%javaconst(1);
#endif

%include "../../port/cpl_config.h"
%include "../../ogr/ogr_srs_api.h"

#ifdef SWIGCSHARP
%csconst(0);
#elif defined(SWIGJAVA)
%javaconst(0);
#endif

%include <windows.i>

Expand Down Expand Up @@ -71,18 +84,17 @@ typedef enum
typedef int CPLErr;
/* why not for CSHARP? */
typedef void VSILFILE;
/* CSHARP has a specific typemap for OGRErr */
typedef int OGRErr;
#endif

typedef int OGRErr;

/*
Typedefs for new types for both the bindings and swig.
*/

/*
First some things needed by the bindings.
These definitions are shared by all bindings.
These definitions are used by all bindings and no harm done if one doesn't.
*/
%{
#include <iostream>
Expand Down Expand Up @@ -112,6 +124,33 @@ typedef void GDALColorTableShadow;
typedef void GDALRasterAttributeTableShadow;
typedef void GDALTransformerInfoShadow;
typedef void GDALAsyncReaderShadow;

#ifdef DEBUG
typedef struct OGRSpatialReferenceHS OSRSpatialReferenceShadow;
typedef struct OGRCoordinateTransformationHS OSRCoordinateTransformationShadow;
typedef struct OGRCoordinateTransformationHS OGRCoordinateTransformationShadow;
typedef struct OGRDriverHS OGRDriverShadow;
typedef struct OGRDataSourceHS OGRDataSourceShadow;
typedef struct OGRLayerHS OGRLayerShadow;
typedef struct OGRFeatureHS OGRFeatureShadow;
typedef struct OGRFeatureDefnHS OGRFeatureDefnShadow;
typedef struct OGRGeometryHS OGRGeometryShadow;
typedef struct OGRFieldDefnHS OGRFieldDefnShadow;
#else
typedef void OSRSpatialReferenceShadow;
typedef void OSRCoordinateTransformationShadow;
typedef void OGRDriverShadow;
typedef void OGRDataSourceShadow;
typedef void OGRLayerShadow;
typedef void OGRFeatureShadow;
typedef void OGRFeatureDefnShadow;
typedef void OGRGeometryShadow;
typedef void OGRFieldDefnShadow;
#endif

typedef struct OGRStyleTableHS OGRStyleTableShadow;
typedef struct OGRGeomFieldDefnHS OGRGeomFieldDefnShadow;

%}

%inline %{
Expand Down

0 comments on commit 6509ef0

Please sign in to comment.