diff --git a/Examples/test-suite/ocaml/Makefile.in b/Examples/test-suite/ocaml/Makefile.in index 879682f10..bb342e039 100644 --- a/Examples/test-suite/ocaml/Makefile.in +++ b/Examples/test-suite/ocaml/Makefile.in @@ -4,6 +4,7 @@ LANGUAGE = ocaml OCAMLC = @OCAMLC@ +OCAMLPP = -pp "camlp4o ./swigp4.cmo" VARIANT = _static SCRIPTSUFFIX = _runme.ml @@ -51,7 +52,7 @@ run_testcase = \ if [ $(srcdir) != . ]; then \ cp $(srcdir)/$(ml_runme) $(ml_runme); \ fi ; \ - $(COMPILETOOL) $(OCAMLC) -c $(ml_runme) && \ + $(COMPILETOOL) $(OCAMLC) $(OCAMLPP) -c $(ml_runme) && \ if [ -f $(top_srcdir)/Examples/test-suite/$*.list ]; then \ $(COMPILETOOL) $(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'`&& $(RUNTOOL) ./runme; \ else \ diff --git a/Examples/test-suite/ocaml/li_std_vector_runme.ml b/Examples/test-suite/ocaml/li_std_vector_runme.ml new file mode 100644 index 000000000..64e9ec9f2 --- /dev/null +++ b/Examples/test-suite/ocaml/li_std_vector_runme.ml @@ -0,0 +1,23 @@ +open Swig +open Li_std_vector + +let _ = + let iv = new_IntVector '() in + assert (iv -> "empty" () as bool); + assert ((iv -> "size" () as int) = 0); + ignore (iv -> "push_back" (123)); + assert ((iv -> "empty" () as bool) = false); + assert ((iv -> "size" () as int) = 1); + assert ((iv -> "[]" (0) as int) = 123); + ignore (iv -> "clear" ()); + assert (iv -> "empty" () as bool); + assert ((iv -> "size" () as int) = 0); +;; + +let _ = + let rv = new_RealVector '() in + ignore (rv -> "push_back" (100.)); + ignore (rv -> "push_back" (200.)); + assert ((rv -> "[]" (0) as float) = 100.); + assert ((rv -> "[]" (1) as float) = 200.); +;; diff --git a/Source/Modules/ocaml.cxx b/Source/Modules/ocaml.cxx index 0c97cd1d3..56d6fd270 100644 --- a/Source/Modules/ocaml.cxx +++ b/Source/Modules/ocaml.cxx @@ -1112,12 +1112,13 @@ public: */ int classHandler(Node *n) { - String *name = Getattr(n, "sym:name"); + String *name = Getattr(n, "name"); + classname = Getattr(n, "sym:name"); if (!name) return SWIG_OK; - String *mangled_sym_name = mangleNameForCaml(name); + String *mangled_name = mangleNameForCaml(name); String *this_class_def = NewString(f_classtemplate); String *name_normalized = normalizeTemplatedClassName(name); String *old_class_ctors = f_class_ctors; @@ -1126,7 +1127,6 @@ public: bool sizeof_feature = generate_sizeof && isSimpleType(name); - classname = mangled_sym_name; classmode = true; int rv = Language::classHandler(n); classmode = false; @@ -1134,15 +1134,15 @@ public: if (sizeof_feature) { Printf(f_wrappers, "SWIGEXT CAML_VALUE _wrap_%s_sizeof( CAML_VALUE args ) {\n" - " CAMLparam1(args);\n" " CAMLreturn(Val_int(sizeof(%s)));\n" "}\n", mangled_sym_name, name_normalized); + " CAMLparam1(args);\n" " CAMLreturn(Val_int(sizeof(%s)));\n" "}\n", mangled_name, name_normalized); - Printf(f_mlbody, "external __%s_sizeof : unit -> int = " "\"_wrap_%s_sizeof\"\n", classname, mangled_sym_name); + Printf(f_mlbody, "external __%s_sizeof : unit -> int = " "\"_wrap_%s_sizeof\"\n", mangled_name, mangled_name); } /* Insert sizeof operator for concrete classes */ if (sizeof_feature) { - Printv(f_class_ctors, "\"sizeof\" , (fun args -> C_int (__", classname, "_sizeof ())) ;\n", NIL); + Printv(f_class_ctors, "\"sizeof\" , (fun args -> C_int (__", mangled_name, "_sizeof ())) ;\n", NIL); } /* Handle up-casts in a nice way */ List *baselist = Getattr(n, "bases"); @@ -1161,7 +1161,7 @@ public: } } - Replaceall(this_class_def, "$classname", classname); + Replaceall(this_class_def, "$classname", mangled_name); Replaceall(this_class_def, "$normalized", name_normalized); Replaceall(this_class_def, "$realname", name); Replaceall(this_class_def, "$baselist", base_classes); @@ -1174,7 +1174,7 @@ public: Multiwrite(this_class_def); - Setattr(n, "ocaml:ctor", classname); + Setattr(n, "ocaml:ctor", mangled_name); return rv; }