Sorry i haven't been here in a while.

camlp4 bug was caught by Michael Ethier <methier@cgr.harvard.edu>

- director.swg: fix a typo
- ocamldec.swg, ocaml.swg: new macros
- ac_compare_version.m4: arty's own more liberally licensed version compare
  autoconf macro.
- configure.in: use version_compare and make swigp4.ml generated by
  configure based on ocaml version.  This is due to an incompatible change
  in camlp4.
- ocaml.cxx: use new return macros in the right places
  (returning non-value)


git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk/SWIG@9518 626c5289-ae23-0410-ae9c-e8d60b6d4f22
This commit is contained in:
Art Yerkes 2006-11-03 07:28:42 +00:00
commit 8ad7605f16
7 changed files with 159 additions and 78 deletions

View file

@ -40,7 +40,7 @@ namespace Swig {
/* attempt to call a pure virtual method via a director method */
class DirectorPureVirtualException : public Swig::DirectorException {
public:
DirectorTypeMismatchException(const char* msg="") {
DirectorPureVirtualException(const char* msg="") {
}
static void raise(const char *msg) {

View file

@ -429,15 +429,15 @@ extern "C" {
case C_short:
case C_ushort:
case C_int:
CAMLreturn(Int_val(SWIG_Field(v,0)));
CAMLreturn_type(Int_val(SWIG_Field(v,0)));
case C_uint:
case C_int32:
CAMLreturn(Int32_val(SWIG_Field(v,0)));
CAMLreturn_type(Int32_val(SWIG_Field(v,0)));
case C_int64:
CAMLreturn(SWIG_Int64_val(SWIG_Field(v,0)));
CAMLreturn_type(SWIG_Int64_val(SWIG_Field(v,0)));
case C_float:
case C_double:
CAMLreturn(Double_val(SWIG_Field(v,0)));
CAMLreturn_type(Double_val(SWIG_Field(v,0)));
default:
fprintf( stderr, "Unknown block tag %d\n", SWIG_Tag_val(v) );
failwith("No conversion to double");
@ -487,13 +487,13 @@ extern "C" {
}
SWIGSTATIC void *caml_ptr_val( CAML_VALUE v, swig_type_info *descriptor ) {
CAMLparam0();
CAMLparam0();
#ifdef TYPE_CAST_VERBOSE
caml_print_val( v );
#endif
void *out = NULL;
if( !caml_ptr_val_internal( v, &out, descriptor ) )
CAMLreturn(out);
CAMLreturn_type(out);
else
failwith( "No appropriate conversion found." );
}

View file

@ -75,6 +75,34 @@ SWIGEXT {
/* Also an l-value. */
#endif
#ifdef CAMLreturn0
#undef CAMLreturn0
#endif
#define CAMLreturn0 do{ \
caml_local_roots = caml__frame; \
return; \
}while (0)
#ifdef CAMLreturn
#undef CAMLreturn
#endif
#define CAMLreturn(result) do{ \
caml_value_t caml__temp_result = (result); \
caml_local_roots = caml__frame; \
return (caml__temp_result); \
}while(0)
#define CAMLreturn_type(result) do{ \
caml_local_roots = caml__frame; \
return result; \
}while(0)
#ifdef CAMLnoreturn
#undef CAMLnoreturn
#endif
#define CAMLnoreturn ((void) caml__frame)
#ifndef ARCH_ALIGN_INT64
#define SWIG_Int64_val(v) (*((int64 *) SWIG_Data_custom_val(v)))
#else

View file

@ -1,7 +1,7 @@
open Pcaml ;;
let lap x y = x :: y
let c_ify e loc =
let c_ify e @OCAMLLOC@ =
match e with
<:expr< $int:_$ >> -> <:expr< (C_int $e$) >>
| <:expr< $str:_$ >> -> <:expr< (C_string $e$) >>
@ -10,44 +10,44 @@ let c_ify e loc =
| <:expr< True >> -> <:expr< (C_bool $e$) >>
| <:expr< False >> -> <:expr< (C_bool $e$) >>
| _ -> <:expr< $e$ >>
let mk_list args loc f =
let rec mk_list_inner args loc f =
let mk_list args @OCAMLLOC@ f =
let rec mk_list_inner args @OCAMLLOC@ f =
match args with
[] -> <:expr< [] >>
| x :: xs ->
(let loc = MLast.loc_of_expr x in
<:expr< [ ($f x loc$) ] @ ($mk_list_inner xs loc f$) >>) in
(let @OCAMLLOC@ = MLast.loc_of_expr x in
<:expr< [ ($f x @OCAMLLOC@$) ] @ ($mk_list_inner xs @OCAMLLOC@ f$) >>) in
match args with
[] -> <:expr< (Obj.magic C_void) >>
| [ a ] -> <:expr< (Obj.magic $f a loc$) >>
| _ -> <:expr< (Obj.magic (C_list ($mk_list_inner args loc f$))) >>
| [ a ] -> <:expr< (Obj.magic $f a @OCAMLLOC@$) >>
| _ -> <:expr< (Obj.magic (C_list ($mk_list_inner args @OCAMLLOC@ f$))) >>
EXTEND
expr:
[ [ e1 = expr ; "'" ; "[" ; e2 = expr ; "]" ->
<:expr< (invoke $e1$) "[]" (C_list [ $c_ify e2 loc$ ]) >>
<:expr< (invoke $e1$) "[]" (C_list [ $c_ify e2 @OCAMLLOC@$ ]) >>
| e1 = expr ; "->" ; l = LIDENT ; "(" ; args = LIST0 (expr LEVEL "simple") SEP "," ; ")" ->
<:expr< (invoke $e1$) $str:l$ ($mk_list args loc c_ify$) >>
<:expr< (invoke $e1$) $str:l$ ($mk_list args @OCAMLLOC@ c_ify$) >>
| e1 = expr ; "->" ; u = UIDENT ; "(" ; args = LIST0 (expr LEVEL "simple") SEP "," ; ")" ->
<:expr< (invoke $e1$) $str:u$ ($mk_list args loc c_ify$) >>
<:expr< (invoke $e1$) $str:u$ ($mk_list args @OCAMLLOC@ c_ify$) >>
| e1 = expr ; "->" ; s = expr LEVEL "simple" ; "(" ; args = LIST0 (expr LEVEL "simple") SEP "," ; ")" ->
<:expr< (invoke $e1$) $s$ ($mk_list args loc c_ify$) >>
<:expr< (invoke $e1$) $s$ ($mk_list args @OCAMLLOC@ c_ify$) >>
| e1 = expr ; "'" ; "." ; "(" ; args = LIST0 (expr LEVEL "simple") SEP "," ; ")" ->
<:expr< (invoke $e1$) "()" ($mk_list args loc c_ify$) >>
<:expr< (invoke $e1$) "()" ($mk_list args @OCAMLLOC@ c_ify$) >>
| e1 = expr ; "'" ; "->" ; l = LIDENT ; "(" ; args = LIST0 (expr LEVEL "simple") SEP "," ; ")" ->
<:expr< (invoke ((invoke $e1$) "->" C_void)) $str:l$ ($mk_list args loc c_ify$) >>
<:expr< (invoke ((invoke $e1$) "->" C_void)) $str:l$ ($mk_list args @OCAMLLOC@ c_ify$) >>
| e1 = expr ; "'" ; "->" ; u = UIDENT ; "(" ; args = LIST0 (expr LEVEL "simple") SEP "," ; ")" ->
<:expr< (invoke ((invoke $e1$) "->" C_void)) $str:u$ ($mk_list args loc c_ify$) >>
<:expr< (invoke ((invoke $e1$) "->" C_void)) $str:u$ ($mk_list args @OCAMLLOC@ c_ify$) >>
| e1 = expr ; "'" ; "->" ; s = expr LEVEL "simple" ; "(" ; args = LIST0 (expr LEVEL "simple") SEP "," ; ")" ->
<:expr< (invoke ((invoke $e1$) "->" C_void)) $s$ ($mk_list args loc c_ify$) >>
<:expr< (invoke ((invoke $e1$) "->" C_void)) $s$ ($mk_list args @OCAMLLOC@ c_ify$) >>
| e1 = expr ; "'" ; "++" ->
<:expr< (invoke $e1$) "++" C_void >>
| e1 = expr ; "'" ; "--" ->
<:expr< (invoke $e1$) "--" C_void >>
| e1 = expr ; "'" ; "-" ; e2 = expr ->
<:expr< (invoke $e1$) "-" (C_list [ $c_ify e2 loc$ ]) >>
| e1 = expr ; "'" ; "+" ; e2 = expr -> <:expr< (invoke $e1$) "+" (C_list [ $c_ify e2 loc$ ]) >>
| e1 = expr ; "'" ; "*" ; e2 = expr -> <:expr< (invoke $e1$) "*" (C_list [ $c_ify e2 loc$ ]) >>
<:expr< (invoke $e1$) "-" (C_list [ $c_ify e2 @OCAMLLOC@$ ]) >>
| e1 = expr ; "'" ; "+" ; e2 = expr -> <:expr< (invoke $e1$) "+" (C_list [ $c_ify e2 @OCAMLLOC@$ ]) >>
| e1 = expr ; "'" ; "*" ; e2 = expr -> <:expr< (invoke $e1$) "*" (C_list [ $c_ify e2 @OCAMLLOC@$ ]) >>
| "'" ; "&" ; e1 = expr ->
<:expr< (invoke $e1$) "&" C_void >>
| "'" ; "!" ; e1 = expr ->
@ -55,64 +55,64 @@ EXTEND
| "'" ; "~" ; e1 = expr ->
<:expr< (invoke $e1$) "~" C_void >>
| e1 = expr ; "'" ; "/" ; e2 = expr ->
<:expr< (invoke $e1$) "/" (C_list [ $c_ify e2 loc$ ]) >>
<:expr< (invoke $e1$) "/" (C_list [ $c_ify e2 @OCAMLLOC@$ ]) >>
| e1 = expr ; "'" ; "%" ; e2 = expr ->
<:expr< (invoke $e1$) "%" (C_list [ $c_ify e2 loc$ ]) >>
<:expr< (invoke $e1$) "%" (C_list [ $c_ify e2 @OCAMLLOC@$ ]) >>
| e1 = expr ; "'" ; "lsl" ; e2 = expr ->
<:expr< (invoke $e1$) ("<" ^ "<") (C_list [ $c_ify e2 loc$ ]) >>
<:expr< (invoke $e1$) ("<" ^ "<") (C_list [ $c_ify e2 @OCAMLLOC@$ ]) >>
| e1 = expr ; "'" ; "lsr" ; e2 = expr ->
<:expr< (invoke $e1$) (">" ^ ">") (C_list [ $c_ify e2 loc$ ]) >>
<:expr< (invoke $e1$) (">" ^ ">") (C_list [ $c_ify e2 @OCAMLLOC@$ ]) >>
| e1 = expr ; "'" ; "<" ; e2 = expr ->
<:expr< (invoke $e1$) "<" (C_list [ $c_ify e2 loc$ ]) >>
<:expr< (invoke $e1$) "<" (C_list [ $c_ify e2 @OCAMLLOC@$ ]) >>
| e1 = expr ; "'" ; "<=" ; e2 = expr ->
<:expr< (invoke $e1$) "<=" (C_list [ $c_ify e2 loc$ ]) >>
<:expr< (invoke $e1$) "<=" (C_list [ $c_ify e2 @OCAMLLOC@$ ]) >>
| e1 = expr ; "'" ; ">" ; e2 = expr ->
<:expr< (invoke $e1$) ">" (C_list [ $c_ify e2 loc$ ]) >>
<:expr< (invoke $e1$) ">" (C_list [ $c_ify e2 @OCAMLLOC@$ ]) >>
| e1 = expr ; "'" ; ">=" ; e2 = expr ->
<:expr< (invoke $e1$) ">=" (C_list [ $c_ify e2 loc$ ]) >>
<:expr< (invoke $e1$) ">=" (C_list [ $c_ify e2 @OCAMLLOC@$ ]) >>
| e1 = expr ; "'" ; "==" ; e2 = expr ->
<:expr< (invoke $e1$) "==" (C_list [ $c_ify e2 loc$ ]) >>
<:expr< (invoke $e1$) "==" (C_list [ $c_ify e2 @OCAMLLOC@$ ]) >>
| e1 = expr ; "'" ; "!=" ; e2 = expr ->
<:expr< (invoke $e1$) "!=" (C_list [ $c_ify e2 loc$ ]) >>
<:expr< (invoke $e1$) "!=" (C_list [ $c_ify e2 @OCAMLLOC@$ ]) >>
| e1 = expr ; "'" ; "&" ; e2 = expr ->
<:expr< (invoke $e1$) "&" (C_list [ $c_ify e2 loc$ ]) >>
<:expr< (invoke $e1$) "&" (C_list [ $c_ify e2 @OCAMLLOC@$ ]) >>
| e1 = expr ; "'" ; "^" ; e2 = expr ->
<:expr< (invoke $e1$) "^" (C_list [ $c_ify e2 loc$ ]) >>
<:expr< (invoke $e1$) "^" (C_list [ $c_ify e2 @OCAMLLOC@$ ]) >>
| e1 = expr ; "'" ; "|" ; e2 = expr ->
<:expr< (invoke $e1$) "|" (C_list [ $c_ify e2 loc$ ]) >>
<:expr< (invoke $e1$) "|" (C_list [ $c_ify e2 @OCAMLLOC@$ ]) >>
| e1 = expr ; "'" ; "&&" ; e2 = expr ->
<:expr< (invoke $e1$) "&&" (C_list [ $c_ify e2 loc$ ]) >>
<:expr< (invoke $e1$) "&&" (C_list [ $c_ify e2 @OCAMLLOC@$ ]) >>
| e1 = expr ; "'" ; "||" ; e2 = expr ->
<:expr< (invoke $e1$) "||" (C_list [ $c_ify e2 loc$ ]) >>
<:expr< (invoke $e1$) "||" (C_list [ $c_ify e2 @OCAMLLOC@$ ]) >>
| e1 = expr ; "'" ; "=" ; e2 = expr ->
<:expr< (invoke $e1$) "=" (C_list [ $c_ify e2 loc$ ]) >>
<:expr< (invoke $e1$) "=" (C_list [ $c_ify e2 @OCAMLLOC@$ ]) >>
| e1 = expr ; "'" ; "+=" ; e2 = expr ->
<:expr< (invoke $e1$) "+=" (C_list [ $c_ify e2 loc$ ]) >>
<:expr< (invoke $e1$) "+=" (C_list [ $c_ify e2 @OCAMLLOC@$ ]) >>
| e1 = expr ; "'" ; "-=" ; e2 = expr ->
<:expr< (invoke $e1$) "-=" (C_list [ $c_ify e2 loc$ ]) >>
<:expr< (invoke $e1$) "-=" (C_list [ $c_ify e2 @OCAMLLOC@$ ]) >>
| e1 = expr ; "'" ; "*=" ; e2 = expr ->
<:expr< (invoke $e1$) "*=" (C_list [ $c_ify e2 loc$ ]) >>
<:expr< (invoke $e1$) "*=" (C_list [ $c_ify e2 @OCAMLLOC@$ ]) >>
| e1 = expr ; "'" ; "/=" ; e2 = expr ->
<:expr< (invoke $e1$) "/=" (C_list [ $c_ify e2 loc$ ]) >>
<:expr< (invoke $e1$) "/=" (C_list [ $c_ify e2 @OCAMLLOC@$ ]) >>
| e1 = expr ; "'" ; "%=" ; e2 = expr ->
<:expr< (invoke $e1$) "%=" (C_list [ $c_ify e2 loc$ ]) >>
<:expr< (invoke $e1$) "%=" (C_list [ $c_ify e2 @OCAMLLOC@$ ]) >>
| e1 = expr ; "'" ; "lsl" ; "=" ; e2 = expr ->
<:expr< (invoke $e1$) ("<" ^ "<=") (C_list [ $c_ify e2 loc$ ]) >>
<:expr< (invoke $e1$) ("<" ^ "<=") (C_list [ $c_ify e2 @OCAMLLOC@$ ]) >>
| e1 = expr ; "'" ; "lsr" ; "=" ; e2 = expr ->
<:expr< (invoke $e1$) (">" ^ ">=") (C_list [ $c_ify e2 loc$ ]) >>
<:expr< (invoke $e1$) (">" ^ ">=") (C_list [ $c_ify e2 @OCAMLLOC@$ ]) >>
| e1 = expr ; "'" ; "&=" ; e2 = expr ->
<:expr< (invoke $e1$) "&=" (C_list [ $c_ify e2 loc$ ]) >>
<:expr< (invoke $e1$) "&=" (C_list [ $c_ify e2 @OCAMLLOC@$ ]) >>
| e1 = expr ; "'" ; "^=" ; e2 = expr ->
<:expr< (invoke $e1$) "^=" (C_list [ $c_ify e2 loc$ ]) >>
<:expr< (invoke $e1$) "^=" (C_list [ $c_ify e2 @OCAMLLOC@$ ]) >>
| e1 = expr ; "'" ; "|=" ; e2 = expr ->
<:expr< (invoke $e1$) "|=" (C_list [ $c_ify e2 loc$ ]) >>
| "'" ; e = expr -> c_ify e loc
<:expr< (invoke $e1$) "|=" (C_list [ $c_ify e2 @OCAMLLOC@$ ]) >>
| "'" ; e = expr -> c_ify e @OCAMLLOC@
| c = expr ; "as" ; id = LIDENT -> <:expr< $lid:"get_" ^ id$ $c$ >>
| c = expr ; "to" ; id = LIDENT -> <:expr< $uid:"C_" ^ id$ $c$ >>
| "`" ; "`" ; l = LIDENT -> <:expr< C_enum `$lid:l$ >>
| "`" ; "`" ; u = UIDENT -> <:expr< C_enum `$uid:u$ >>
| f = expr ; "'" ; "(" ; args = LIST0 (expr LEVEL "simple") SEP "," ; ")" ->
<:expr< $f$ ($mk_list args loc c_ify$) >>
<:expr< $f$ ($mk_list args @OCAMLLOC@ c_ify$) >>
] ] ;
END ;;

View file

@ -1680,9 +1680,9 @@ public:
* always essentially work.
*/
if (!SwigType_isreference(return_type)) {
Printf(w->code, "CAMLreturn((%s)c_result);\n", SwigType_lstr(return_type, ""));
Printf(w->code, "CAMLreturn_type((%s)c_result);\n", SwigType_lstr(return_type, ""));
} else {
Printf(w->code, "CAMLreturn(*c_result);\n");
Printf(w->code, "CAMLreturn_type(*c_result);\n");
}
}
}

View file

@ -0,0 +1,40 @@
dnl @synopsis AC_COMPARE_VERSION\
dnl (version-a, version-b, action-if-greater, action-if-equal, action-if-less)
dnl
dnl This macro compares two version numbers and executes the indicated action
dnl based on whether they're equal or one is greater than the other.
dnl It's needed to determine whether ocaml is new enough that the incompatible
dnl change 'loc' -> '_loc' is present in this version of camlp4.
dnl
dnl It's implemented from scratch just for SWIG by arty.
dnl
dnl @category Misc
dnl @author arty
dnl @version 2006-11-02
dnl @license GPLWithACException
AC_DEFUN([AC_COMPARE_VERSION], [
# Split the version into units.
ver_a="[$1]"
ver_b="[$2]"
nodots_a=`echo $ver_a | sed -e 's/\./ /g'`
condition="equal"
isolate_b_regex='\([[0-9]]\+\).*'
for ver_part in $nodots_a ; do
b_ver_part=`echo "$ver_b" | sed -e 's/'"$isolate_b_regex"'/\1/'`
if test \( "$ver_part" -lt "$b_ver_part" \) -a \( "x$condition" == "xequal" \) ; then
condition=less
elif test \( "$ver_part" -gt "$b_ver_part" \) -a \( "x$condition" == "xequal" \) ; then
condition=greater
fi
isolate_b_regex='[[0-9]]\+\.'"$isolate_b_regex"
done
if test "x$condition" == "xequal" ; then
[$4]
elif test "x$condition" == "xless" ; then
[$3]
elif test "x$condition" == "xgreater" ; then
[$5]
fi
])

View file

@ -1217,58 +1217,68 @@ else
AC_MSG_CHECKING(for Ocaml DL load generator)
if test -z "$OCAMLDLGEN"; then
AC_CHECK_PROGS(OCAMLDLGEN, ocamldlgen, ocamldlgen)
AC_CHECK_PROGS(OCAMLDLGEN, ocamldlgen, :)
else
OCAMLDLGEN="$OCAMLDLGEN"
fi
AC_MSG_CHECKING(for Ocaml package tool)
if test -z "$OCAMLFIND"; then
AC_CHECK_PROGS(OCAMLFIND, ocamlfind, ocamlfind)
AC_CHECK_PROGS(OCAMLFIND, ocamlfind, :)
else
OCAMLFIND="$OCAMLFIND"
fi
AC_MSG_CHECKING(for Ocaml compiler)
if test -z "$OCAMLC"; then
AC_CHECK_PROGS(OCAMLC, ocamlc, ocamlc)
AC_CHECK_PROGS(OCAMLC, ocamlc, :)
else
OCAMLC="$OCAMLC"
fi
AC_MSG_CHECKING(for Ocaml interpreter)
if test "x$OCAMLBIN" = xyes; then
AC_CHECK_PROGS(OCAMLBIN, ocaml, ocaml)
AC_CHECK_PROGS(OCAMLBIN, ocaml, :)
else
OCAMLBIN="$OCAMLBIN"
fi
AC_MSG_CHECKING(for Ocaml toplevel creator)
if test -z "$OCAMLMKTOP"; then
AC_CHECK_PROGS(OCAMLMKTOP, ocamlmktop, ocamlmktop)
AC_CHECK_PROGS(OCAMLMKTOP, ocamlmktop, :)
else
OCAMLMKTOP="$OCAMLMKTOP"
fi
AC_MSG_CHECKING(for Ocaml header files)
dirs="/usr/lib/ocaml/caml /usr/local/lib/ocaml/caml"
dir="`$OCAMLC -where 2>/dev/null`"
if test "$dir"; then
dirs="$dir/caml $dirs"
fi
for i in $dirs; do
if test -r $i/mlvalues.h; then
AC_MSG_RESULT($i)
OCAMLEXT="$i"
OCAMLINC="-I$OCAMLEXT"
break;
OCAMLLOC=loc
if test "$OCAMLC" != ":" ; then
AC_MSG_CHECKING(for Ocaml header files)
dirs="/usr/lib/ocaml/caml /usr/local/lib/ocaml/caml"
dir="`$OCAMLC -where 2>/dev/null`"
if test "$dir"; then
dirs="$dir/caml $dirs"
fi
for i in $dirs; do
if test -r $i/mlvalues.h; then
AC_MSG_RESULT($i)
OCAMLEXT="$i"
OCAMLINC="-I$OCAMLEXT"
break;
fi
done
if test -z "$OCAMLINC"; then
AC_MSG_RESULT(not found)
fi
done
if test -z "$OCAMLINC"; then
AC_MSG_RESULT(not found)
fi
fi
AC_MSG_CHECKING(for Ocaml version 3.08.2 or higher)
OCAMLVER=`$OCAMLC -version | sed -e 's/.*version //g'`
AC_COMPARE_VERSION([$OCAMLVER],[3.08.2],[:],[:],[OCAMLLOC=_loc])
AC_MSG_RESULT($OCAMLVER)
fi
fi # Disabling ocaml
export OCAMLLOC
export OCAMLVER
export OCAMLINC
export OCAMLBIN
export OCAMLC
@ -1276,6 +1286,8 @@ export OCAMLDLGEN
export OCAMLFIND
export OCAMLMKTOP
AC_SUBST(OCAMLLOC)
AC_SUBST(OCAMLVER)
AC_SUBST(OCAMLINC)
AC_SUBST(OCAMLBIN)
AC_SUBST(OCAMLC)
@ -1965,7 +1977,8 @@ AC_CONFIG_FILES([ \
Examples/test-suite/clisp/Makefile \
Examples/test-suite/cffi/Makefile \
Examples/test-suite/uffi/Makefile \
Examples/test-suite/r/Makefile
Examples/test-suite/r/Makefile \
Lib/ocaml/swigp4.ml
])
AC_CONFIG_FILES([preinst-swig], [chmod +x preinst-swig])
AC_OUTPUT