Type registration.  Correct support for casting.  Proper type safety.
Changed:
ocaml.swg: Correct casts, declaration order for C
ocamldec.swg: Removed problematic forward declarations without array index.


git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@4573 626c5289-ae23-0410-ae9c-e8d60b6d4f22
This commit is contained in:
Art Yerkes 2003-03-19 16:24:47 +00:00
commit 39f415aa47
12 changed files with 634 additions and 230 deletions

View file

@ -1,22 +1,136 @@
template < class T > class SWIG_OCAML_ARRAY_WRAPPER {
public:
SWIG_OCAML_ARRAY_WRAPPER( T *t ) : t(t) { }
SWIG_OCAML_ARRAY_WRAPPER( T &t ) : t(&t) { }
SWIG_OCAML_ARRAY_WRAPPER( T t[] ) : t(&t[0]) { }
T &operator[]( int n ) { return t[n]; }
SWIG_OCAML_ARRAY_WRAPPER offset( int elts ) {
return SWIG_OCAML_ARRAY_WRAPPER( t + elts );
}
T *operator & () { return t; }
void own() { owned = true; }
void disown() { owned = false; }
~SWIG_OCAML_ARRAY_WRAPPER() {
if( owned ) delete t;
}
%insert(mli) %{
type _value = c_obj
%}
private:
T *t;
int owned;
};
%insert(ml) %{
type _value = c_obj
%}
%apply SWIGTYPE [ANY] {SWIG_OCAML_ARRAY_WRAPPER};
%define %array_tmap_out(type,what,out_f)
%typemap(type) what [ANY] {
int i;
/* $*1_type */
$result = caml_array_new($1_dim0);
for( i = 0; i < $1_dim0; i++ ) {
caml_array_set($result,i,out_f($1[i]));
}
}
%enddef
%define %array_tmap_in(type,what,in_f)
%typemap(type) what [ANY] {
int i;
/* $*1_type */
$1 = ($*1_type *)malloc( $1_size );
for( i = 0; i < $1_dim0 && i < caml_array_len($input); i++ ) {
$1[i] = in_f(caml_array_nth($input,i));
}
}
%typemap(free) what [ANY] {
free( (void *)$1 );
}
%enddef
%define %make_simple_array_typemap(type,out_f,in_f)
%array_tmap_out(out,type,out_f);
%array_tmap_out(varout,type,out_f);
%array_tmap_out(inv,type,out_f);
%array_tmap_in(in,type,in_f);
%array_tmap_in(varin,type,in_f);
%array_tmap_in(outv,type,in_f);
%enddef
%make_simple_array_typemap(bool,caml_val_bool,caml_long_val);
%make_simple_array_typemap(short,caml_val_short,caml_long_val);
%make_simple_array_typemap(unsigned short,caml_val_ushort,caml_long_val);
%make_simple_array_typemap(int,caml_val_int,caml_long_val);
%make_simple_array_typemap(unsigned int,caml_val_uint,caml_long_val);
%make_simple_array_typemap(long,caml_val_long,caml_long_val);
%make_simple_array_typemap(unsigned long,caml_val_ulong,caml_long_val);
%make_simple_array_typemap(size_t,caml_val_int,caml_long_val);
%make_simple_array_typemap(float,caml_val_float,caml_double_val);
%make_simple_array_typemap(double,caml_val_double,caml_double_val);
#ifdef __cplusplus
%typemap(in) SWIGTYPE [] {
int i;
/* $*1_type */
$1 = new $*1_type [$1_dim0];
for( i = 0; i < $1_dim0 && i < caml_array_len($input); i++ ) {
$1[i] = *(($*1_ltype *)
caml_ptr_val(caml_array_nth($input,i),
$*1_descriptor)) ;
}
}
#else
%typemap(in) SWIGTYPE [] {
int i;
/* $*1_type */
$1 = ($*1_type *)malloc( $1_size );
for( i = 0; i < $1_dim0 && i < caml_array_len($input); i++ ) {
$1[i] = *(($*1_ltype)
caml_ptr_val(caml_array_nth($input),
$*1_descriptor));
}
}
#endif
%typemap(out) SWIGTYPE [] {
int i;
CAML_VALUE *fromval = caml_named_value("create_$ntype_from_ptr");
$result = caml_array_new($1_dim0);
for( i = 0; i < $1_dim0; i++ ) {
if( fromval ) {
caml_array_set
($result,
i,
callback(*fromval,caml_val_ptr((void *)&$1[i],$*1_descriptor)));
} else {
caml_array_set
($result,
i,
caml_val_ptr ((void *)&$1[i],$&1_descriptor));
}
}
}
%typemap(in) enum SWIGTYPE [] {
int i;
/* $*1_type */
$1 = ($*1_type *)malloc( $1_size );
for( i = 0; i < $1_dim0 && i < caml_array_len($input); i++ ) {
$1[i] = ($type)
caml_long_val_full(caml_array_nth($input),
"$type_marker");
}
}
%typemap(out) enum SWIGTYPE [] {
int i;
$result = caml_array_new($1_dim0);
for( i = 0; i < $1_dim0; i++ ) {
caml_array_set
($result,
i,
callback2(*caml_named_value(SWIG_MODULE "_int_to_enum"),
*caml_named_value("$type_marker"),
Val_int($1[i])));
}
}
#ifdef __cplusplus
%typemap(freearg) SWIGTYPE [ANY] {
delete [] $1;
}
#else
%typemap(freearg) SWIGTYPE [ANY] {
free( (void *)$1 );
}
#endif

View file

@ -26,7 +26,7 @@ public:
virtual ~SWIG_DIRECTOR_EXCEPTION() { }
};
/* type mismatch in the return value from a ocaml method call */
/* type mismatch in the return CAML_VALUE from a ocaml method call */
class SWIG_DIRECTOR_TYPE_MISMATCH: public SWIG_DIRECTOR_EXCEPTION {
public:
SWIG_DIRECTOR_TYPE_MISMATCH(const char* msg="") {
@ -57,7 +57,7 @@ class SWIG_DIRECTOR_METHOD_EXCEPTION: public SWIG_DIRECTOR_EXCEPTION { };
class __DIRECTOR__ {
private:
/* pointer to the wrapped ocaml object */
value _self;
CAML_VALUE _self;
/* flag indicating whether the object is owned by ocaml or c++ */
mutable int _disown;
/* shared flag for breaking recursive director calls */
@ -90,7 +90,7 @@ public:
}
/* wrap a ocaml object, optionally taking ownership */
__DIRECTOR__(value self, int disown): _self(self), _disown(disown) {
__DIRECTOR__(CAML_VALUE self, int disown): _self(self), _disown(disown) {
register_global_root(&_self);
}
@ -103,7 +103,7 @@ public:
}
/* return a pointer to the wrapped ocaml object */
value __get_self() const {
CAML_VALUE __get_self() const {
return callback(*caml_named_value("caml_director_get_self"),_self);
}

View file

@ -14,7 +14,9 @@
%insert(runtime) "ocamldec.swg"
/* Type registration */
#if 0
%insert(init) "typeregister.swg"
#endif
/*#ifndef SWIG_NOINCLUDE*/
%insert(runtime) "ocaml.swg"

View file

@ -81,9 +81,9 @@ extern "C" {
}
}
SWIGSTATIC void caml_print_list( value v );
SWIGSTATIC void caml_print_list( CAML_VALUE v );
SWIGSTATIC void caml_print_val( value v ) {
SWIGSTATIC void caml_print_val( CAML_VALUE v ) {
switch( Tag_val(v) ) {
case C_bool:
if( Bool_val(Field(v,0)) ) fprintf( stderr, "true " );
@ -117,8 +117,8 @@ extern "C" {
case C_ptr:
{
void *vout = 0;
swig_type_info *ty = (swig_type_info *)(long)Int64_val(Field(v,1));
caml_ptr_val_internal(v,&vout,0);
swig_type_info *ty = (swig_type_info *)Int64_val(Field(v,1));
fprintf( stderr, "PTR(%p,%s) ",
vout,
ty ? ty->name : "(null)" );
@ -147,7 +147,7 @@ extern "C" {
}
}
SWIGSTATIC void caml_print_list( value v ) {
SWIGSTATIC void caml_print_list( CAML_VALUE v ) {
CAMLparam1(v);
while( v && Is_block(v) ) {
fprintf( stderr, "[ " );
@ -157,7 +157,7 @@ extern "C" {
}
}
SWIGSTATIC value caml_list_nth( value lst, int n ) {
SWIGSTATIC CAML_VALUE caml_list_nth( CAML_VALUE lst, int n ) {
CAMLparam1(lst);
int i = 0;
while( i < n && lst && Is_block(lst) ) {
@ -167,7 +167,7 @@ extern "C" {
else CAMLreturn(Field(lst,0));
}
SWIGSTATIC value caml_list_append( value lst, value elt ) {
SWIGSTATIC CAML_VALUE caml_list_append( CAML_VALUE lst, CAML_VALUE elt ) {
CAMLparam2(lst,elt);
CAMLlocal3(v,vt,lh);
lh = Val_unit;
@ -201,30 +201,64 @@ extern "C" {
CAMLreturn(lh);
}
SWIGSTATIC int caml_list_length( value lst ) {
SWIGSTATIC int caml_list_length( CAML_VALUE lst ) {
CAMLparam1(lst);
int i = 0;
while( lst && Is_block(lst) ) { i++; lst = Field(lst,1); }
CAMLreturn(i);
}
SWIGSTATIC void caml_array_set( CAML_VALUE arr, int n, CAML_VALUE item ) {
CAMLparam2(arr,item);
Store_field(Field(arr,0),n,item);
CAMLreturn0;
}
SWIGSTATIC value caml_array_nth( CAML_VALUE arr, int n ) {
CAMLparam1(arr);
if( Tag_val(arr) == C_array )
CAMLreturn(Field(Field(arr,0),n));
else if( Tag_val(arr) == C_list )
CAMLreturn(caml_list_nth(arr,0));
else
failwith("Need array or list");
}
SWIGSTATIC int caml_array_len( CAML_VALUE arr ) {
CAMLparam1(arr);
if( Tag_val(arr) == C_array )
CAMLreturn(Wosize_val(Field(arr,0)));
else if( Tag_val(arr) == C_list )
CAMLreturn(caml_list_length(arr));
else
failwith("Need array or list");
}
#ifdef __cplusplus
namespace caml {
extern "C"
#endif
value alloc(int,int);
CAML_VALUE alloc(int,int);
#ifdef __cplusplus
};
#endif
SWIGSTATIC value caml_swig_alloc(int x,int y) {
SWIGSTATIC CAML_VALUE caml_swig_alloc(int x,int y) {
#ifdef __cplusplus
using namespace caml;
#endif
return alloc(x,y);
}
SWIGSTATIC value caml_array_new( int n ) {
CAMLparam0();
CAMLlocal1(vv);
vv = caml_swig_alloc(1,C_array);
Store_field(vv,0,alloc_tuple(n));
CAMLreturn(vv);
}
SWIGSTATIC value caml_val_bool( int b ) {
SWIGSTATIC CAML_VALUE caml_val_bool( int b ) {
CAMLparam0();
CAMLlocal1(bv);
bv = caml_swig_alloc(1,C_bool);
@ -232,7 +266,7 @@ extern "C" {
CAMLreturn(bv);
}
SWIGSTATIC value caml_val_char( char c ) {
SWIGSTATIC CAML_VALUE caml_val_char( char c ) {
CAMLparam0();
CAMLlocal1(cv);
cv = caml_swig_alloc(1,C_char);
@ -240,7 +274,7 @@ extern "C" {
CAMLreturn(cv);
}
SWIGSTATIC value caml_val_uchar( unsigned char uc ) {
SWIGSTATIC CAML_VALUE caml_val_uchar( unsigned char uc ) {
CAMLparam0();
CAMLlocal1(ucv);
ucv = caml_swig_alloc(1,C_uchar);
@ -248,7 +282,7 @@ extern "C" {
CAMLreturn(ucv);
}
SWIGSTATIC value caml_val_short( short s ) {
SWIGSTATIC CAML_VALUE caml_val_short( short s ) {
CAMLparam0();
CAMLlocal1(sv);
sv = caml_swig_alloc(1,C_short);
@ -256,7 +290,7 @@ extern "C" {
CAMLreturn(sv);
}
SWIGSTATIC value caml_val_ushort( unsigned short us ) {
SWIGSTATIC CAML_VALUE caml_val_ushort( unsigned short us ) {
CAMLparam0();
CAMLlocal1(usv);
usv = caml_swig_alloc(1,C_ushort);
@ -264,7 +298,7 @@ extern "C" {
CAMLreturn(usv);
}
SWIGSTATIC value caml_val_int( int i ) {
SWIGSTATIC CAML_VALUE caml_val_int( int i ) {
CAMLparam0();
CAMLlocal1(iv);
iv = caml_swig_alloc(1,C_int);
@ -272,7 +306,7 @@ extern "C" {
CAMLreturn(iv);
}
SWIGSTATIC value caml_val_uint( unsigned int ui ) {
SWIGSTATIC CAML_VALUE caml_val_uint( unsigned int ui ) {
CAMLparam0();
CAMLlocal1(uiv);
uiv = caml_swig_alloc(1,C_int);
@ -280,7 +314,7 @@ extern "C" {
CAMLreturn(uiv);
}
SWIGSTATIC value caml_val_long( long l ) {
SWIGSTATIC CAML_VALUE caml_val_long( long l ) {
CAMLparam0();
CAMLlocal1(lv);
lv = caml_swig_alloc(1,C_int64);
@ -288,7 +322,7 @@ extern "C" {
CAMLreturn(lv);
}
SWIGSTATIC value caml_val_ulong( unsigned long ul ) {
SWIGSTATIC CAML_VALUE caml_val_ulong( unsigned long ul ) {
CAMLparam0();
CAMLlocal1(ulv);
ulv = caml_swig_alloc(1,C_int64);
@ -296,7 +330,7 @@ extern "C" {
CAMLreturn(ulv);
}
SWIGSTATIC value caml_val_float( float f ) {
SWIGSTATIC CAML_VALUE caml_val_float( float f ) {
CAMLparam0();
CAMLlocal1(fv);
fv = caml_swig_alloc(1,C_float);
@ -304,7 +338,7 @@ extern "C" {
CAMLreturn(fv);
}
SWIGSTATIC value caml_val_double( double d ) {
SWIGSTATIC CAML_VALUE caml_val_double( double d ) {
CAMLparam0();
CAMLlocal1(fv);
fv = caml_swig_alloc(1,C_double);
@ -312,7 +346,7 @@ extern "C" {
CAMLreturn(fv);
}
SWIGSTATIC value caml_val_ptr( void *p, swig_type_info *info ) {
SWIGSTATIC CAML_VALUE caml_val_ptr( void *p, swig_type_info *info ) {
CAMLparam0();
CAMLlocal1(vv);
vv = caml_swig_alloc(2,C_ptr);
@ -321,7 +355,7 @@ extern "C" {
CAMLreturn(vv);
}
SWIGSTATIC value caml_val_string( const char *p ) {
SWIGSTATIC CAML_VALUE caml_val_string( const char *p ) {
CAMLparam0();
CAMLlocal1(vv);
if( !p ) CAMLreturn(caml_val_ptr( (void *)p, 0 ));
@ -330,7 +364,7 @@ extern "C" {
CAMLreturn(vv);
}
SWIGSTATIC value caml_val_string_len( const char *p, int len ) {
SWIGSTATIC CAML_VALUE caml_val_string_len( const char *p, int len ) {
CAMLparam0();
CAMLlocal1(vv);
if( !p || len < 0 ) CAMLreturn(caml_val_ptr( (void *)p, 0 ));
@ -340,14 +374,14 @@ extern "C" {
CAMLreturn(vv);
}
SWIGSTATIC value caml_val_obj( void *v, char *object_type ) {
SWIGSTATIC CAML_VALUE caml_val_obj( void *v, char *object_type ) {
CAMLparam0();
CAMLreturn(callback2(*caml_named_value("caml_create_object_fn"),
caml_val_ptr(v,SWIG_TypeQuery(object_type)),
copy_string(object_type)));
}
SWIGSTATIC long caml_long_val_full( value v, char *name ) {
SWIGSTATIC long caml_long_val_full( CAML_VALUE v, char *name ) {
CAMLparam1(v);
if( !Is_block(v) ) return 0;
@ -373,7 +407,7 @@ extern "C" {
CAMLreturn((long)Int64_val(Field(Field(v,0),0)));
case C_enum: {
CAMLlocal1(ret);
value *enum_to_int = caml_named_value(SWIG_MODULE "_enum_to_int");
CAML_VALUE *enum_to_int = caml_named_value(SWIG_MODULE "_enum_to_int");
if( !name ) failwith( "Not an enum conversion" );
ret = callback2(*enum_to_int,*caml_named_value(name),v);
CAMLreturn(caml_long_val(ret));
@ -383,11 +417,11 @@ extern "C" {
}
}
SWIGSTATIC long caml_long_val( value v ) {
SWIGSTATIC long caml_long_val( CAML_VALUE v ) {
return caml_long_val_full(v,0);
}
SWIGSTATIC double caml_double_val( value v ) {
SWIGSTATIC double caml_double_val( CAML_VALUE v ) {
CAMLparam1(v);
if( !Is_block(v) ) return 0.0;
switch( Tag_val(v) ) {
@ -412,7 +446,7 @@ extern "C" {
}
}
SWIGSTATIC int caml_ptr_val_internal( value v, void **out,
SWIGSTATIC int caml_ptr_val_internal( CAML_VALUE v, void **out,
swig_type_info *descriptor ) {
CAMLparam1(v);
void *outptr = NULL;
@ -454,7 +488,7 @@ extern "C" {
CAMLreturn(SWIG_GetPtr(outptr,out,outdescr,descriptor));
}
SWIGSTATIC void *caml_ptr_val( value v, swig_type_info *descriptor ) {
SWIGSTATIC void *caml_ptr_val( CAML_VALUE v, swig_type_info *descriptor ) {
CAMLparam0();
#ifdef TYPE_CAST_VERBOSE
caml_print_val( v );
@ -466,11 +500,11 @@ extern "C" {
failwith( "No appropriate conversion found." );
}
SWIGSTATIC char *caml_string_val( value v ) {
SWIGSTATIC char *caml_string_val( CAML_VALUE v ) {
return (char *)caml_ptr_val( v, 0 );
}
SWIGSTATIC int caml_bool_check( value v ) {
SWIGSTATIC int caml_bool_check( CAML_VALUE v ) {
CAMLparam1(v);
if( !Is_block(v) ) return 0;
@ -485,7 +519,7 @@ extern "C" {
}
}
SWIGSTATIC int caml_int_check( value v ) {
SWIGSTATIC int caml_int_check( CAML_VALUE v ) {
CAMLparam1(v);
if( !Is_block(v) ) return 0;
@ -506,7 +540,7 @@ extern "C" {
}
}
SWIGSTATIC int caml_float_check( value v ) {
SWIGSTATIC int caml_float_check( CAML_VALUE v ) {
CAMLparam1(v);
if( !Is_block(v) ) return 0;
@ -520,7 +554,7 @@ extern "C" {
}
}
SWIGSTATIC int caml_ptr_check( value v ) {
SWIGSTATIC int caml_ptr_check( CAML_VALUE v ) {
CAMLparam1(v);
if( !Is_block(v) ) return 0;

View file

@ -17,6 +17,7 @@ SWIGEXT {
#define SWIGEXT
#endif
#define alloc caml_alloc
#define value caml_value_t
#include <caml/alloc.h>
#include <caml/custom.h>
#include <caml/mlvalues.h>
@ -25,6 +26,7 @@ SWIGEXT {
#include <caml/fail.h>
#include <caml/misc.h>
#undef alloc
#define CAML_VALUE value
#if defined(SWIG_NOINCLUDE)
# define SWIGSTATIC
@ -36,77 +38,56 @@ SWIGEXT {
#define __OCAML__SWIG__MAXVALUES 6
static swig_type_info *swig_types[];
static swig_type_info *swig_types_initial[];
SWIGSTATIC int
SWIG_GetPtr(void *source, void **result, swig_type_info *type, swig_type_info *result_type);
SWIGSTATIC void *
SWIG_MustGetPtr (value v, swig_type_info *type);
SWIG_MustGetPtr (CAML_VALUE v, swig_type_info *type);
static value _wrap_delete_void( value );
static CAML_VALUE _wrap_delete_void( CAML_VALUE );
static int enum_to_int( char *name, value v );
static value int_to_enum( char *name, int v );
static int enum_to_int( char *name, CAML_VALUE v );
static CAML_VALUE int_to_enum( char *name, int v );
static value caml_list_nth( value lst, int n );
static value caml_list_append( value lst, value elt );
static int caml_list_length( value lst );
static CAML_VALUE caml_list_nth( CAML_VALUE lst, int n );
static CAML_VALUE caml_list_append( CAML_VALUE lst, CAML_VALUE elt );
static int caml_list_length( CAML_VALUE lst );
static CAML_VALUE caml_array_new( int n );
static void caml_array_set( CAML_VALUE arr, int n, CAML_VALUE item );
static CAML_VALUE caml_array_nth( CAML_VALUE arr, int n );
static int caml_array_length( CAML_VALUE arr );
static value caml_val_char( char c );
static value caml_val_uchar( unsigned char c );
static CAML_VALUE caml_val_char( char c );
static CAML_VALUE caml_val_uchar( unsigned char c );
static value caml_val_short( short s );
static value caml_val_ushort( unsigned short s );
static CAML_VALUE caml_val_short( short s );
static CAML_VALUE caml_val_ushort( unsigned short s );
static value caml_val_int( int x );
static value caml_val_uint( unsigned int x );
static CAML_VALUE caml_val_int( int x );
static CAML_VALUE caml_val_uint( unsigned int x );
static value caml_val_long( long x );
static value caml_val_ulong( unsigned long x );
static CAML_VALUE caml_val_long( long x );
static CAML_VALUE caml_val_ulong( unsigned long x );
static value caml_val_float( float f );
static value caml_val_double( double d );
static CAML_VALUE caml_val_float( float f );
static CAML_VALUE caml_val_double( double d );
static value caml_val_ptr( void *p, swig_type_info *descriptor );
static CAML_VALUE caml_val_ptr( void *p, swig_type_info *descriptor );
static value caml_val_string( const char *str );
static value caml_val_string_len( const char *str, int len );
static CAML_VALUE caml_val_string( const char *str );
static CAML_VALUE caml_val_string_len( const char *str, int len );
static long caml_long_val( value v );
static double caml_double_val( value v );
static long caml_long_val( CAML_VALUE v );
static double caml_double_val( CAML_VALUE v );
static int caml_ptr_val_internal( value v, void **out,
static int caml_ptr_val_internal( CAML_VALUE v, void **out,
swig_type_info *descriptor );
static void *caml_ptr_val( value v, swig_type_info *descriptor );
static void *caml_ptr_val( CAML_VALUE v, swig_type_info *descriptor );
static char *caml_string_val( value v );
static char *caml_string_val( CAML_VALUE v );
#ifdef __cplusplus
}
template < class T > class SWIG_OCAML_ARRAY_WRAPPER {
public:
SWIG_OCAML_ARRAY_WRAPPER( T *t ) : t(t) { }
SWIG_OCAML_ARRAY_WRAPPER( T &t ) : t(&t) { }
SWIG_OCAML_ARRAY_WRAPPER( T t[] ) : t(&t[0]) { }
T &operator[]( int n ) { return t[n]; }
SWIG_OCAML_ARRAY_WRAPPER offset( int elts ) {
return SWIG_OCAML_ARRAY_WRAPPER( t + elts );
}
T *operator & () { return t; }
void own() { owned = true; }
void disown() { owned = false; }
~SWIG_OCAML_ARRAY_WRAPPER() {
if( owned ) delete t;
}
private:
T *t;
int owned;
};
#endif
/* mzschemedec.swg ends here */

View file

@ -8,10 +8,10 @@
%{
#include <string>
value SwigString_FromString(const std::string& s) {
CAML_VALUE SwigString_FromString(const std::string& s) {
return caml_val_string((char *)s.c_str());
}
std::string SwigString_AsString(value o) {
std::string SwigString_AsString(CAML_VALUE o) {
return std::string((char *)caml_ptr_val(o,0));
}
%}

View file

@ -18,6 +18,8 @@
%{
#include <string>
#include <vector>
using std::string;
using std::vector;
%}
%include std_vector.i

View file

@ -11,74 +11,34 @@
/* Pointers */
%typemap(ocaml,in) void * {
%typemap(in) void ""
%typemap(out) void "$result = Val_int(0);"
%typemap(in) void * {
$1 = caml_ptr_val($input,$descriptor);
}
%typemap(ocaml,varin) void * {
%typemap(varin) void * {
$1 = ($ltype)caml_ptr_val($input,$descriptor);
}
%typemap(ocaml,in) char *, signed char *, unsigned char *, const char *, const signed char *, const unsigned char * {
$1 = ($ltype)caml_string_val($input);
}
%typemap(ocaml,varin) char *, signed char *, unsigned char *, const char *, const signed char *, const unsigned char * {
$1 = ($ltype)caml_string_val($input);
}
%typemap(ocaml,out) void * {
%typemap(out) void * {
$result = caml_val_ptr($1,$descriptor);
}
%typemap(ocaml,varout) void * {
%typemap(varout) void * {
$result = caml_val_ptr($1,$descriptor);
}
%typemap(ocaml,out) char *, signed char *, unsigned char *, const char *, const signed char *, const unsigned char * {
$result = caml_val_string($1);
}
%typemap(ocaml,varout) char *, signed char *, unsigned char *, const char *, const signed char *, const unsigned char * {
$result = caml_val_string($1);
}
%typemap(ocaml,in) SWIGTYPE * {
$1 = ($ltype)caml_ptr_val($input,$1_descriptor);
}
%typemap(ocaml,out) SWIGTYPE * {
value *fromval = caml_named_value("create_$ntype_from_ptr");
if( fromval ) {
$result = callback(*fromval,caml_val_ptr((void *)$1,$1_descriptor));
} else {
$result = caml_val_ptr ((void *)$1,$1_descriptor);
}
}
%typemap(ocaml,varin) SWIGTYPE * {
$1 = ($ltype)caml_ptr_val($input,$1_descriptor);
}
%typemap(ocaml,varout) SWIGTYPE * {
value *fromval = caml_named_value("create_$ntype_from_ptr");
if( fromval ) {
$result = callback(*fromval,caml_val_ptr((void *)$1,$1_descriptor));
} else {
$result = caml_val_ptr ((void *)$1,$1_descriptor);
}
}
/* C++ References */
#ifdef __cplusplus
%typemap(ocaml,in) SWIGTYPE & {
%typemap(in) SWIGTYPE & {
$1 = ($ltype) caml_ptr_val($input,$1_descriptor);
}
%typemap(ocaml,out) SWIGTYPE & {
value *fromval = caml_named_value("create_$ntype_from_ptr");
%typemap(out) SWIGTYPE & {
CAML_VALUE *fromval = caml_named_value("create_$ntype_from_ptr");
if( fromval ) {
$result = callback(*fromval,caml_val_ptr((void *) $1,$1_descriptor));
} else {
@ -87,8 +47,8 @@
}
#if 0
%typemap(ocaml,argout) SWIGTYPE & {
value *fromval = caml_named_value("create_$ntype_from_ptr");
%typemap(argout) SWIGTYPE & {
CAML_VALUE *fromval = caml_named_value("create_$ntype_from_ptr");
if( fromval ) {
swig_result =
caml_list_append(swig_result,
@ -102,15 +62,15 @@
}
#endif
%typemap(ocaml,argout) const SWIGTYPE & { }
%typemap(argout) const SWIGTYPE & { }
%typemap(ocaml,in) SWIGTYPE {
%typemap(in) SWIGTYPE {
$1 = *(($&1_ltype) caml_ptr_val($input,$&1_descriptor)) ;
}
%typemap(ocaml,out) SWIGTYPE {
%typemap(out) SWIGTYPE {
void *temp = new $ltype($1);
value *fromval = caml_named_value("create_$ntype_from_ptr");
CAML_VALUE *fromval = caml_named_value("create_$ntype_from_ptr");
*(($ltype *)temp) = $1;
if( fromval ) {
$result = callback(*fromval,caml_val_ptr((void *)temp,$&1_descriptor));
@ -121,13 +81,13 @@
#else
%typemap(ocaml,in) SWIGTYPE {
%typemap(in) SWIGTYPE {
$1 = *(($&1_ltype) caml_ptr_val($input,$&1_descriptor)) ;
}
%typemap(ocaml,out) SWIGTYPE {
%typemap(out) SWIGTYPE {
void *temp = calloc(1,sizeof($ltype));
value *fromval = caml_named_value("create_$ntype_from_ptr");
CAML_VALUE *fromval = caml_named_value("create_$ntype_from_ptr");
*(($ltype *)temp) = $1;
if( fromval ) {
$result = callback(*fromval,caml_val_ptr((void *)temp,$&1_descriptor));
@ -140,20 +100,6 @@
#endif
/* Arrays */
/* Enums */
%typemap(ocaml,in) enum SWIGTYPE {
$1 = ($type)caml_long_val_full($input,"$type_marker");
}
%typemap(ocaml,varin) enum SWIGTYPE {
$1 = ($type)caml_long_val_full($input,"$type_marker");
}
%typemap(ocaml,out) enum SWIGTYPE "$result = callback2(*caml_named_value(SWIG_MODULE \"_int_to_enum\"),*caml_named_value(\"$type_marker\"),Val_int($1));"
%typemap(ocaml,varout) enum SWIGTYPE "$result = callback2(*caml_named_value(SWIG_MODULE \"_int_to_enum\"),*caml_named_value(\"$type_marker\"),Val_int($1));"
/* The SIMPLE_MAP macro below defines the whole set of typemaps needed
for simple types. */
@ -164,18 +110,12 @@
%typemap(varin) C_NAME {
$1 = MZ_TO_C($input);
}
%typemap(memberin) C_NAME {
$1 = MZ_TO_C($input);
}
%typemap(out) C_NAME {
$result = C_TO_MZ($1);
}
%typemap(varout) C_NAME {
$result = C_TO_MZ($1);
}
%typemap(memberout) C_NAME {
$resunt = C_TO_MZ($1);
}
%typemap(in) C_NAME *INPUT ($*1_ltype temp) {
temp = ($*1_ltype) MZ_TO_C($input);
$1 = &temp;
@ -225,5 +165,97 @@ SIMPLE_MAP(unsigned long long,caml_val_ulong,caml_long_val);
/* Pass through value */
%typemap (in) value "$1=$input;";
%typemap (out) value "$result=$1;";
%typemap (in) value,caml::value,CAML_VALUE "$1=$input;";
%typemap (out) value,caml::value,CAML_VALUE "$result=$1;";
/* Arrays */
%typemap(in) ArrayCarrier * {
$1 = ($ltype)caml_ptr_val($input,$1_descriptor);
}
%typemap(out) ArrayCarrier * {
CAML_VALUE *fromval = caml_named_value("create_$ntype_from_ptr");
if( fromval ) {
$result = callback(*fromval,caml_val_ptr((void *)$1,$1_descriptor));
} else {
$result = caml_val_ptr ((void *)$1,$1_descriptor);
}
}
#if 0
%include "carray.i"
#endif
/* Handle char arrays as strings */
%define %char_ptr_in(how)
%typemap(how) char *, signed char *, unsigned char * {
$1 = ($ltype)caml_string_val($input);
}
%typemap(how) char [ANY], signed char [ANY], unsigned char [ANY] {
char *temp = caml_string_val($input);
strncpy((char *)$1,temp,$1_dim0);
}
%enddef
%char_ptr_in(in);
%char_ptr_in(varin);
%char_ptr_in(outv);
%define %char_ptr_out(how)
%typemap(how)
char *, signed char *, unsigned char *,
const char *, const signed char *, const unsigned char * {
$result = caml_val_string((char *)$1);
}
%typemap(how)
char [ANY], signed char [ANY], unsigned char [ANY],
const char [ANY], const signed char [ANY], const unsigned char [ANY] {
$result = caml_val_string_len((char *)$1,(int)$1_size);
}
%enddef
%char_ptr_out(out);
%char_ptr_out(varout);
%char_ptr_out(invv);
%typemap(in) SWIGTYPE * {
$1 = ($ltype)caml_ptr_val($input,$1_descriptor);
}
%typemap(out) SWIGTYPE * {
CAML_VALUE *fromval = caml_named_value("create_$ntype_from_ptr");
if( fromval ) {
$result = callback(*fromval,caml_val_ptr((void *)$1,$1_descriptor));
} else {
$result = caml_val_ptr ((void *)$1,$1_descriptor);
}
}
%typemap(varin) SWIGTYPE * {
$1 = ($ltype)caml_ptr_val($input,$1_descriptor);
}
%typemap(varout) SWIGTYPE * {
CAML_VALUE *fromval = caml_named_value("create_$ntype_from_ptr");
if( fromval ) {
$result = callback(*fromval,caml_val_ptr((void *)$1,$1_descriptor));
} else {
$result = caml_val_ptr ((void *)$1,$1_descriptor);
}
}
/* C++ References */
/* Enums */
%typemap(in) enum SWIGTYPE {
$1 = ($type)caml_long_val_full($input,"$type_marker");
}
%typemap(varin) enum SWIGTYPE {
$1 = ($type)caml_long_val_full($input,"$type_marker");
}
%typemap(out) enum SWIGTYPE "$result = callback2(*caml_named_value(SWIG_MODULE \"_int_to_enum\"),*caml_named_value(\"$type_marker\"),Val_int($1));"
%typemap(varout) enum SWIGTYPE "$result = callback2(*caml_named_value(SWIG_MODULE \"_int_to_enum\"),*caml_named_value(\"$type_marker\"),Val_int($1));"

View file

@ -0,0 +1,11 @@
/* Code ripped from python implementation */
{
static int typeinit = 0;
int i;
if (!typeinit) {
for (i = 0; swig_types_initial[i]; i++) {
swig_types[i] = SWIG_TypeRegister(swig_types_initial[i]);
}
typeinit = 1;
}
}