(* Simple test of the API.
* Copyright (C) 2003 Merjis Ltd.
- * $Id: test.ml,v 1.6 2003-12-11 17:41:52 rich Exp $
+ * $Id: test.ml,v 1.7 2004-11-25 22:16:17 rich Exp $
*)
open Printf
let sv = Perl.call_method obj "get_foo" [] in
printf "TestClass.foo is %d\n" (Perl.int_of_sv sv); flush stdout;
+ (* Create an undef value and test it. *)
+ let undef = Perl.sv_undef () in
+ printf "sv_is_undef (undef) = %s\n"
+ (string_of_bool (Perl.sv_is_undef undef));
+
(* Perform a full collection - good way to find GC/allocation bugs. *)
Gc.full_major ()
(* Interface to Perl from OCaml.
* Copyright (C) 2003 Merjis Ltd.
- * $Id: perl.ml,v 1.11 2003-12-11 17:41:52 rich Exp $
+ * $Id: perl.ml,v 1.12 2004-11-25 22:16:17 rich Exp $
*)
type sv
external sv_of_string : string -> sv = "perl4caml_sv_of_string"
external sv_is_true : sv -> bool = "perl4caml_sv_is_true"
external sv_undef : unit -> sv = "perl4caml_sv_undef"
+external sv_is_undef : sv -> bool = "perl4caml_sv_is_undef"
external sv_yes : unit -> sv = "perl4caml_sv_yes"
external sv_no : unit -> sv = "perl4caml_sv_no"
| SVt_PVMG
external sv_type : sv -> sv_t = "perl4caml_sv_type"
-let sv_is_undef sv =
- SVt_NULL = sv_type sv
let string_of_sv_t = function
SVt_NULL -> "SVt_NULL"
/* Interface to Perl from OCaml.
* Copyright (C) 2003 Merjis Ltd.
- * $Id: perl_c.c,v 1.16 2004-11-03 14:15:18 rich Exp $
+ * $Id: perl_c.c,v 1.17 2004-11-25 22:16:17 rich Exp $
*/
#include <stdio.h>
perl4caml_sv_undef (value unit)
{
CAMLparam1 (unit);
- CAMLreturn (Val_sv (newSV (0)));
+ /*CAMLreturn (Val_sv (newSV (0)));*/
+ CAMLreturn (Val_sv (&PL_sv_undef));
+}
+
+CAMLprim value
+perl4caml_sv_is_undef (value svv)
+{
+ CAMLparam1 (svv);
+ SV *sv = Sv_val (svv);
+ CAMLreturn (!SvPOK (sv) && !SvIOK (sv) && SvTYPE (sv) == SVt_NULL
+ ? Val_true : Val_false);
}
CAMLprim value