Uniform SWIGSTATIC on all prototypes.
#ifdef __GNUC__ -> static inline to remove warning spew using gcc typemaps: tweaks for arrays, enums ocaml.cxx: remove Swig. qualifier everywhere it's not needed git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@6655 626c5289-ae23-0410-ae9c-e8d60b6d4f22
This commit is contained in:
parent
134dd53433
commit
b1c2cd26b4
6 changed files with 94 additions and 54 deletions
|
|
@ -19,7 +19,7 @@ run_testcase = \
|
|||
ocamlc swig.cmo -custom -g -cc '$(CXX)' -o runme `cat $(top_srcdir)/Examples/test-suite/$(*).list | sed -e 's/\(.*\)/\1_wrap.o \1.cmo/g'`&& ./runme) ; \
|
||||
elif [ -f $(srcdir)/$(SCRIPTPREFIX)$*$(SCRIPTSUFFIX) ]; then ( \
|
||||
ocamlc -c $(srcdir)/$(SCRIPTPREFIX)$*$(SCRIPTSUFFIX); \
|
||||
ocamlc swig.cmo -custom -g -cc '$(CXX)' -o runme $(srcdir)/$(*)_runme.cmo $(srcdir)/$(*)_wrap.o && \
|
||||
ocamlc swig.cmo -custom -g -cc '$(CXX)' -o runme $(srcdir)/$(*).cmo $(srcdir)/$(*)_runme.cmo $(srcdir)/$(*)_wrap.o && \
|
||||
./runme) ; \
|
||||
fi ;
|
||||
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
open Swig
|
||||
open Name
|
||||
|
||||
let _ = if (get_int _Baz_2) - (get_int (_bar_2 C_void)) == 30
|
||||
let _ = if (get_int (_Baz_2 C_void)) - (get_int (_bar_2 C_void)) == 30
|
||||
then
|
||||
exit 0
|
||||
else
|
||||
|
|
|
|||
|
|
@ -17,10 +17,12 @@
|
|||
%}
|
||||
|
||||
%insert(mltail) %{
|
||||
let swig_val t v =
|
||||
let rec swig_val t v =
|
||||
match v with
|
||||
C_enum e -> enum_to_int t v
|
||||
| _ -> Obj.magic v
|
||||
C_enum e -> enum_to_int t v
|
||||
| C_list l -> Swig.C_list (List.map (swig_val t) l)
|
||||
| C_array a -> Swig.C_array (Array.map (swig_val t) a)
|
||||
| _ -> Obj.magic v
|
||||
%}
|
||||
|
||||
/*#ifndef SWIG_NOINCLUDE*/
|
||||
|
|
|
|||
|
|
@ -26,6 +26,8 @@ SWIGEXT {
|
|||
#include <caml/fail.h>
|
||||
#include <caml/misc.h>
|
||||
|
||||
#define caml_array_set swig_caml_array_set
|
||||
|
||||
// Adapted from memory.h and mlvalues.h
|
||||
|
||||
#define SWIG_CAMLlocal1(x) \
|
||||
|
|
@ -79,7 +81,12 @@ CAMLextern int64 Int64_val(caml_value_t v);
|
|||
#define SWIG_Int64_val(v) Int64_val(v)
|
||||
#endif
|
||||
|
||||
# define SWIGSTATIC static
|
||||
#ifdef __GNUC__
|
||||
# define SWIGSTATIC static inline
|
||||
#else
|
||||
# define SWIGSTATIC static
|
||||
#endif
|
||||
|
||||
|
||||
#define SWIG_NewPointerObj(p,type,flags) caml_val_ptr(p,type)
|
||||
|
||||
|
|
@ -91,48 +98,48 @@ CAMLextern int64 Int64_val(caml_value_t v);
|
|||
SWIGSTATIC void *
|
||||
SWIG_MustGetPtr (CAML_VALUE v, swig_type_info *type);
|
||||
|
||||
static CAML_VALUE _wrap_delete_void( CAML_VALUE );
|
||||
SWIGSTATIC CAML_VALUE _wrap_delete_void( CAML_VALUE );
|
||||
|
||||
static int enum_to_int( char *name, CAML_VALUE v );
|
||||
static CAML_VALUE int_to_enum( char *name, int v );
|
||||
SWIGSTATIC int enum_to_int( char *name, CAML_VALUE v );
|
||||
SWIGSTATIC CAML_VALUE int_to_enum( char *name, int v );
|
||||
|
||||
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 );
|
||||
SWIGSTATIC CAML_VALUE caml_list_nth( CAML_VALUE lst, int n );
|
||||
SWIGSTATIC CAML_VALUE caml_list_append( CAML_VALUE lst, CAML_VALUE elt );
|
||||
SWIGSTATIC int caml_list_length( CAML_VALUE lst );
|
||||
SWIGSTATIC CAML_VALUE caml_array_new( int n );
|
||||
SWIGSTATIC void caml_array_set( CAML_VALUE arr, int n, CAML_VALUE item );
|
||||
SWIGSTATIC CAML_VALUE caml_array_nth( CAML_VALUE arr, int n );
|
||||
SWIGSTATIC int caml_array_length( CAML_VALUE arr );
|
||||
|
||||
static CAML_VALUE caml_val_char( char c );
|
||||
static CAML_VALUE caml_val_uchar( unsigned char c );
|
||||
SWIGSTATIC CAML_VALUE caml_val_char( char c );
|
||||
SWIGSTATIC CAML_VALUE caml_val_uchar( unsigned char c );
|
||||
|
||||
static CAML_VALUE caml_val_short( short s );
|
||||
static CAML_VALUE caml_val_ushort( unsigned short s );
|
||||
SWIGSTATIC CAML_VALUE caml_val_short( short s );
|
||||
SWIGSTATIC CAML_VALUE caml_val_ushort( unsigned short s );
|
||||
|
||||
static CAML_VALUE caml_val_int( int x );
|
||||
static CAML_VALUE caml_val_uint( unsigned int x );
|
||||
SWIGSTATIC CAML_VALUE caml_val_int( int x );
|
||||
SWIGSTATIC CAML_VALUE caml_val_uint( unsigned int x );
|
||||
|
||||
static CAML_VALUE caml_val_long( long x );
|
||||
static CAML_VALUE caml_val_ulong( unsigned long x );
|
||||
SWIGSTATIC CAML_VALUE caml_val_long( long x );
|
||||
SWIGSTATIC CAML_VALUE caml_val_ulong( unsigned long x );
|
||||
|
||||
static CAML_VALUE caml_val_float( float f );
|
||||
static CAML_VALUE caml_val_double( double d );
|
||||
SWIGSTATIC CAML_VALUE caml_val_float( float f );
|
||||
SWIGSTATIC CAML_VALUE caml_val_double( double d );
|
||||
|
||||
static CAML_VALUE caml_val_ptr( void *p, swig_type_info *descriptor );
|
||||
SWIGSTATIC CAML_VALUE caml_val_ptr( void *p, swig_type_info *descriptor );
|
||||
|
||||
static CAML_VALUE caml_val_string( const char *str );
|
||||
static CAML_VALUE caml_val_string_len( const char *str, int len );
|
||||
SWIGSTATIC CAML_VALUE caml_val_string( const char *str );
|
||||
SWIGSTATIC CAML_VALUE caml_val_string_len( const char *str, int len );
|
||||
|
||||
static long caml_long_val( CAML_VALUE v );
|
||||
static double caml_double_val( CAML_VALUE v );
|
||||
SWIGSTATIC long caml_long_val( CAML_VALUE v );
|
||||
SWIGSTATIC double caml_double_val( CAML_VALUE v );
|
||||
|
||||
static int caml_ptr_val_internal( CAML_VALUE v, void **out,
|
||||
SWIGSTATIC int caml_ptr_val_internal( CAML_VALUE v, void **out,
|
||||
swig_type_info *descriptor );
|
||||
static void *caml_ptr_val( CAML_VALUE v, swig_type_info *descriptor );
|
||||
SWIGSTATIC void *caml_ptr_val( CAML_VALUE v, swig_type_info *descriptor );
|
||||
|
||||
static char *caml_string_val( CAML_VALUE v );
|
||||
static int caml_string_len( CAML_VALUE v );
|
||||
SWIGSTATIC char *caml_string_val( CAML_VALUE v );
|
||||
SWIGSTATIC int caml_string_len( CAML_VALUE v );
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
|
|
|
|||
|
|
@ -284,16 +284,37 @@ SIMPLE_MAP(unsigned long long,caml_val_ulong,caml_long_val);
|
|||
%swigtype_ptr_out(varout);
|
||||
%swigtype_ptr_out(directorin);
|
||||
|
||||
%define %swigtype_array_fail(how,msg)
|
||||
%typemap(how) SWIGTYPE [] {
|
||||
failwith(msg);
|
||||
}
|
||||
%enddef
|
||||
|
||||
%swigtype_array_fail(in,"Array arguments for arbitrary types need a typemap");
|
||||
%swigtype_array_fail(varin,"Assignment to global arrays for arbitrary types need a typemap");
|
||||
%swigtype_array_fail(out,"Array arguments for arbitrary types need a typemap");
|
||||
%swigtype_array_fail(varout,"Array variables need a typemap");
|
||||
%swigtype_array_fail(directorin,"Array results with arbitrary types need a typemap");
|
||||
%swigtype_array_fail(directorout,"Array arguments with arbitrary types need a typemap");
|
||||
|
||||
/* C++ References */
|
||||
|
||||
/* Enums */
|
||||
%typemap(in) enum SWIGTYPE {
|
||||
%define %swig_enum_in(how)
|
||||
%typemap(how) enum SWIGTYPE {
|
||||
$1 = ($type)caml_long_val_full($input,"$type_marker");
|
||||
}
|
||||
%enddef
|
||||
|
||||
%typemap(varin) enum SWIGTYPE {
|
||||
$1 = ($type)caml_long_val_full($input,"$type_marker");
|
||||
%define %swig_enum_out(how)
|
||||
%typemap(how) enum SWIGTYPE {
|
||||
$result = callback2(*caml_named_value(SWIG_MODULE "_int_to_enum"),*caml_named_value("$type_marker"),Val_int((int)$1));
|
||||
}
|
||||
%enddef
|
||||
|
||||
%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));"
|
||||
%swig_enum_in(in)
|
||||
%swig_enum_in(varin)
|
||||
%swig_enum_in(directorout)
|
||||
%swig_enum_out(out)
|
||||
%swig_enum_out(varout)
|
||||
%swig_enum_out(directorin)
|
||||
|
|
|
|||
|
|
@ -282,8 +282,8 @@ public:
|
|||
" C_enum _y ->\n"
|
||||
" (let y = _y in match (x : c_enum_type) with\n"
|
||||
" `unknown -> "
|
||||
" (match (Obj.magic y) with\n"
|
||||
" `Int x -> Swig.C_int x\n"
|
||||
" (match y with\n"
|
||||
" `Int x -> (Swig.C_int x)\n"
|
||||
" | _ -> raise (LabelNotFromThisEnum v))\n" );
|
||||
|
||||
Printf( f_int_to_enum,
|
||||
|
|
@ -323,7 +323,7 @@ public:
|
|||
Language::top(n);
|
||||
|
||||
Printf( f_enum_to_int,
|
||||
") | _ -> (Swig.C_int (get_int v))\n"
|
||||
") | _ -> (C_int (get_int v))\n"
|
||||
"let _ = Callback.register \"%s_enum_to_int\" enum_to_int\n",
|
||||
module );
|
||||
Printf( f_mlibody,
|
||||
|
|
@ -916,21 +916,21 @@ public:
|
|||
|
||||
if( Getattr( n, "feature:immutable" ) ) {
|
||||
Printf( f_mlbody,
|
||||
"external _%s : Swig.c_obj -> Swig.c_obj = \"%s\" \n",
|
||||
"external _%s : c_obj -> Swig.c_obj = \"%s\" \n",
|
||||
mname, var_name );
|
||||
Printf( f_mlibody, "val _%s : Swig.c_obj -> Swig.c_obj\n", iname );
|
||||
Printf( f_mlibody, "val _%s : c_obj -> Swig.c_obj\n", iname );
|
||||
if( const_enum ) {
|
||||
Printf( f_enum_to_int,
|
||||
" | `%s -> _%s Swig.C_void\n",
|
||||
" | `%s -> _%s C_void\n",
|
||||
mname, mname );
|
||||
Printf( f_int_to_enum,
|
||||
" if y = (get_int (_%s Swig.C_void)) then `%s else\n",
|
||||
" if y = (get_int (_%s C_void)) then `%s else\n",
|
||||
mname, mname );
|
||||
}
|
||||
} else {
|
||||
Printf( f_mlbody, "external _%s : Swig.c_obj -> Swig.c_obj = \"%s\"\n",
|
||||
Printf( f_mlbody, "external _%s : c_obj -> c_obj = \"%s\"\n",
|
||||
mname, var_name );
|
||||
Printf( f_mlibody, "external _%s : Swig.c_obj -> Swig.c_obj = \"%s\"\n",
|
||||
Printf( f_mlibody, "external _%s : c_obj -> c_obj = \"%s\"\n",
|
||||
mname, var_name );
|
||||
}
|
||||
|
||||
|
|
@ -1204,7 +1204,7 @@ public:
|
|||
|
||||
/* Insert sizeof operator for concrete classes */
|
||||
if( sizeof_feature ) {
|
||||
Printv(f_class_ctors, "\"sizeof\" , (fun args -> Swig.C_int (__",
|
||||
Printv(f_class_ctors, "\"sizeof\" , (fun args -> C_int (__",
|
||||
classname, "_sizeof ())) ;\n", NIL);
|
||||
}
|
||||
/* Handle up-casts in a nice way */
|
||||
|
|
@ -1216,7 +1216,7 @@ public:
|
|||
String *bname = Getattr(b.item, "name");
|
||||
if (bname) {
|
||||
String *base_create = NewString("");
|
||||
Printv(base_create,"(Swig.create_class \"",bname,"\")",NIL);
|
||||
Printv(base_create,"(create_class \"",bname,"\")",NIL);
|
||||
Printv(f_class_ctors,
|
||||
" \"::",bname,"\", (fun args -> ",
|
||||
base_create," args) ;\n",NIL);
|
||||
|
|
@ -1410,7 +1410,7 @@ public:
|
|||
|
||||
if( oname && !seen_enum ) {
|
||||
const_enum = true;
|
||||
Printf( f_enum_to_int, "| `%s -> (match (Obj.magic y) with\n", oname );
|
||||
Printf( f_enum_to_int, "| `%s -> (match y with\n", oname );
|
||||
Printf( f_int_to_enum, "| `%s -> C_enum (\n", oname );
|
||||
/* * * * A note about enum name resolution * * * *
|
||||
* This code should now work, but I think we can do a bit better.
|
||||
|
|
@ -1755,8 +1755,18 @@ public:
|
|||
|
||||
/* any existing helper functions to handle this? */
|
||||
if (!is_void) {
|
||||
if (!SwigType_isreference(return_type)) {
|
||||
Printf(w->code, "CAMLreturn(c_result);\n");
|
||||
/* A little explanation:
|
||||
* The director_enum test case makes a method whose return type
|
||||
* is an enum type. return_type here is "int". gcc complains
|
||||
* about an implicit enum conversion, and although i don't strictly
|
||||
* agree with it, I'm working on fixing the error:
|
||||
*
|
||||
* Below is what I came up with. It's not great but it should
|
||||
* always essentially work.
|
||||
*/
|
||||
if( !SwigType_isreference(return_type) ) {
|
||||
Printf(w->code, "CAMLreturn((%s)c_result);\n",
|
||||
SwigType_lstr(return_type, ""));
|
||||
} else {
|
||||
Printf(w->code, "CAMLreturn(*c_result);\n");
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue