# perl4caml configuration -*- Makefile -*-
-# $Id: Makefile.config,v 1.13 2003-12-11 17:41:52 rich Exp $
+# $Id: Makefile.config,v 1.14 2004-02-03 12:38:57 rich Exp $
# PERLINCDIR
# Directory containing the Perl include files, eg. <EXTERN.h>.
# EXTRA_CFLAGS
# You can specify extra flags to be passed to gcc here.
+#
+# One flag you might want to pass here is
+#
+# -DPERL4CAML_REFCOUNTING_EXPERIMENTAL=1
+#
+# which will turn on experimental support for reference counting.
+# Without this none of the Perl structures that you allocate will get
+# freed. With this we try to map Perl's reference counting onto
+# OCaml's garbage collection by using finalizers. There are some
+# problems with this code at the moment, hence it is disabled by
+# default.
EXTRA_CFLAGS :=
+#EXTRA_CFLAGS := -DPERL4CAML_REFCOUNTING_EXPERIMENTAL=1
# PACKAGE and VERSION
/* Interface to Perl from OCaml.
* Copyright (C) 2003 Merjis Ltd.
- * $Id: perl_c.c,v 1.13 2003-12-11 17:41:52 rich Exp $
+ * $Id: perl_c.c,v 1.14 2004-02-03 12:38:57 rich Exp $
*/
#include <stdio.h>
/* Perl requires the interpreter to be called literally 'my_perl'! */
static PerlInterpreter *my_perl;
+/* Get the concrete value from an optional field. */
+static value unoption (value option, value deflt);
+
/* Wrap up an arbitrary void pointer in an opaque OCaml object. */
static value Val_voidptr (void *ptr);
+/* Unwrap an arbitrary void pointer from an opaque OCaml object. */
+#define Voidptr_val(type,rv) ((type *) Field ((rv), 0))
+
+#if PERL4CAML_REFCOUNTING_EXPERIMENTAL
+
+/* Unwrap a custom block. */
+#define Xv_val(rv) (*((void **)Data_custom_val(rv)))
+
/* Wrap up an SV, AV or HV in a custom OCaml object which will decrement
* the reference count on finalization.
*/
static value Val_xv (SV *sv);
-/* Get the concrete value from an optional field. */
-static value unoption (value option, value deflt);
+#else
-/* Unwrap an arbitrary void pointer from an opaque OCaml object. */
-#define Voidptr_val(type,rv) ((type *) Field ((rv), 0))
+#define Xv_val(rv) Voidptr_val (SV, (rv))
+#define Val_xv(sv) Val_voidptr ((sv))
-/* Unwrap a custom block. */
-#define Xv_val(rv) (*((void **)Data_custom_val(rv)))
+#endif
/* Hide Perl types in opaque OCaml objects. */
#define Val_perl(pl) (Val_voidptr ((pl)))
CAMLreturn (rv);
}
+#if PERL4CAML_REFCOUNTING_EXPERIMENTAL
+
static void
xv_finalize (value v)
{
CAMLreturn (rv);
}
+#endif /* PERL4CAML_REFCOUNTING_EXPERIMENTAL */
+
static value
unoption (value option, value deflt)
{