1 /* Interface to Perl from OCaml.
2 Copyright (C) 2003 Merjis Ltd.
4 This library is free software; you can redistribute it and/or
5 modify it under the terms of the GNU Library General Public
6 License as published by the Free Software Foundation; either
7 version 2 of the License, or (at your option) any later version.
9 This library is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 Library General Public License for more details.
14 You should have received a copy of the GNU General Public License
15 along with this library; see the file COPYING. If not, write to
16 the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
17 Boston, MA 02111-1307, USA.
19 $Id: perl_c.c,v 1.25 2008-03-01 13:02:21 rich Exp $
28 #define CAML_NAME_SPACE 1
30 #include <caml/alloc.h>
31 #include <caml/callback.h>
32 #include <caml/custom.h>
33 #include <caml/fail.h>
34 #include <caml/memory.h>
35 #include <caml/mlvalues.h>
40 /* Perl requires the interpreter to be called literally 'my_perl'! */
41 static PerlInterpreter *my_perl;
43 /* Get the concrete value from an optional field. */
44 static value unoption (value option, value deflt);
46 /* Wrap up an arbitrary void pointer in an opaque OCaml object. */
47 static value Val_voidptr (void *ptr);
49 /* Unwrap an arbitrary void pointer from an opaque OCaml object. */
50 #define Voidptr_val(type,rv) ((type *) Field ((rv), 0))
52 #if PERL4CAML_REFCOUNTING_EXPERIMENTAL
54 /* Unwrap a custom block. */
55 #define Xv_val(rv) (*((void **)Data_custom_val(rv)))
57 /* Wrap up an SV, AV or HV in a custom OCaml object which will decrement
58 * the reference count on finalization.
60 static value Val_xv (SV *sv);
64 #define Xv_val(rv) Voidptr_val (SV, (rv))
65 #define Val_xv(sv) Val_voidptr ((sv))
69 /* Hide Perl types in opaque OCaml objects. */
70 #define Val_perl(pl) (Val_voidptr ((pl)))
71 #define Perl_val(plv) (Voidptr_val (PerlInterpreter, (plv)))
72 #define Val_sv(sv) (Val_xv ((sv)))
73 #define Sv_val(svv) ((SV *) Xv_val (svv))
74 #define Val_av(av) (Val_xv ((SV *)(av)))
75 #define Av_val(avv) ((AV *) Xv_val (avv))
76 #define Val_hv(hv) (Val_xv ((SV *)(hv)))
77 #define Hv_val(hvv) ((HV *) Xv_val (hvv))
78 #define Val_he(he) (Val_voidptr ((he)))
79 #define He_val(hev) (Voidptr_val (HE, (hev)))
84 char *file = __FILE__;
85 EXTERN_C void boot_DynaLoader (pTHX_ CV* cv);
87 newXS("DynaLoader::boot_DynaLoader", boot_DynaLoader, file);
91 perl4caml_init (value unit)
95 static char *argv[] = { "", "-w", "-e", "0", NULL };
97 PERL_SYS_INIT (&argc, &argv);
98 my_perl = perl_alloc ();
99 perl_construct (my_perl);
100 PL_exit_flags |= PERL_EXIT_DESTRUCT_END;
101 perl_parse (my_perl, xs_init, argc, argv, (char **) NULL);
102 /*perl_run (my_perl);*/
104 CAMLreturn (Val_unit);
108 perl4caml_int_of_sv (value svv)
111 SV *sv = Sv_val (svv);
112 CAMLreturn (Val_int (SvIV (sv)));
116 perl4caml_sv_of_int (value iv)
119 CAMLreturn (Val_sv (newSViv (Int_val (iv))));
123 perl4caml_float_of_sv (value svv)
126 SV *sv = Sv_val (svv);
128 f = caml_copy_double (SvNV (sv));
133 perl4caml_sv_of_float (value fv)
136 CAMLreturn (Val_sv (newSVnv (Double_val (fv))));
140 perl4caml_string_of_sv (value svv)
143 SV *sv = Sv_val (svv);
147 str = SvPV (sv, len);
148 strv = caml_alloc_string (len);
149 memcpy (String_val (strv), str, len);
154 perl4caml_sv_of_string (value strv)
157 CAMLreturn (Val_sv (newSVpv (String_val (strv), caml_string_length (strv))));
161 perl4caml_sv_is_true (value svv)
164 SV *sv = Sv_val (svv);
165 CAMLreturn (SvTRUE (sv) ? Val_true : Val_false);
169 perl4caml_sv_undef (value unit)
172 /*CAMLreturn (Val_sv (newSV (0)));*/
173 CAMLreturn (Val_sv (&PL_sv_undef));
177 perl4caml_sv_is_undef (value svv)
180 SV *sv = Sv_val (svv);
181 CAMLreturn (!SvPOK (sv) && !SvIOK (sv) && SvTYPE (sv) == SVt_NULL
182 ? Val_true : Val_false);
186 perl4caml_sv_yes (value unit)
189 CAMLreturn (Val_sv (&PL_sv_yes));
193 perl4caml_sv_no (value unit)
196 CAMLreturn (Val_sv (&PL_sv_no));
204 case SVt_IV: return 1;
205 case SVt_NV: return 2;
206 case SVt_PV: return 3;
207 case SVt_RV: return 4;
208 case SVt_PVAV: return 5;
209 case SVt_PVHV: return 6;
210 case SVt_PVCV: return 7;
211 case SVt_PVGV: return 8;
212 case SVt_PVMG: return 9;
218 perl4caml_sv_type (value svv)
221 SV *sv = Sv_val (svv);
223 CAMLreturn (Val_int (sv_type (sv)));
227 perl4caml_address_of_sv (value svv)
230 SV *sv = Sv_val (svv);
231 CAMLreturn (caml_copy_nativeint ((long) sv));
235 perl4caml_address_of_av (value avv)
238 AV *av = Av_val (avv);
239 CAMLreturn (caml_copy_nativeint ((long) av));
243 perl4caml_address_of_hv (value hvv)
246 HV *hv = Hv_val (hvv);
247 CAMLreturn (caml_copy_nativeint ((long) hv));
251 perl4caml_scalarref (value svv)
255 SV *sv = Sv_val (svv);
256 rsvv = Val_sv (newRV_inc (sv));
261 perl4caml_arrayref (value avv)
265 AV *av = Av_val (avv);
266 rsvv = Val_sv (newRV_inc ((SV *) av));
271 perl4caml_hashref (value hvv)
275 HV *hv = Hv_val (hvv);
276 rsvv = Val_sv (newRV_inc ((SV *) hv));
281 perl4caml_reftype (value svv)
284 SV *sv = Sv_val (svv);
287 caml_invalid_argument ("reftype: SV is not a reference");
289 CAMLreturn (Val_int (sv_type (SvRV (sv))));
293 perl4caml_deref (value svv)
297 SV *sv = Sv_val (svv);
300 caml_invalid_argument ("deref: SV is not a reference");
301 switch (SvTYPE (SvRV (sv))) {
309 caml_invalid_argument ("deref: SV is not a reference to a scalar");
312 /* Increment the reference count because we're creating another
313 * value pointing at the referenced SV.
315 sv = SvREFCNT_inc (sv);
321 perl4caml_deref_array (value svv)
325 SV *sv = Sv_val (svv);
328 caml_invalid_argument ("deref_array: SV is not a reference");
329 switch (SvTYPE (SvRV (sv))) {
333 caml_invalid_argument ("deref_array: SV is not a reference to an array");
336 /* Increment the reference count because we're creating another
337 * value pointing at the referenced AV.
339 sv = SvREFCNT_inc (sv);
340 ravv = Val_av ((AV *) sv);
345 perl4caml_deref_hash (value svv)
349 SV *sv = Sv_val (svv);
352 caml_invalid_argument ("deref_hash: SV is not a reference");
353 switch (SvTYPE (SvRV (sv))) {
357 caml_invalid_argument ("deref_hash: SV is not a reference to a hash");
360 /* Increment the reference count because we're creating another
361 * value pointing at the referenced HV.
363 sv = SvREFCNT_inc (sv);
364 rhvv = Val_hv ((HV *) sv);
369 perl4caml_av_empty (value unit)
373 CAMLreturn (Val_av (av));
376 /* We don't know in advance how long the list will be, which makes this
380 perl4caml_av_of_sv_list (value svlistv)
382 CAMLparam1 (svlistv);
384 SV *sv, **svlist = 0;
385 int alloc = 0, size = 0;
388 for (; svlistv != Val_int (0); svlistv = Field (svlistv, 1))
390 svv = Field (svlistv, 0);
393 alloc = alloc == 0 ? 1 : alloc * 2;
394 svlist = realloc (svlist, alloc * sizeof (SV *));
399 av = av_make (size, svlist);
401 if (alloc > 0) free (svlist); /* Free memory allocated to SV list. */
403 CAMLreturn (Val_av (av));
406 /* XXX av_map would be faster if we also had sv_list_of_av. */
409 perl4caml_av_push (value avv, value svv)
411 CAMLparam2 (avv, svv);
412 AV *av = Av_val (avv);
413 SV *sv = Sv_val (svv);
415 CAMLreturn (Val_unit);
419 perl4caml_av_pop (value avv)
422 AV *av = Av_val (avv);
423 SV *sv = av_pop (av);
424 /* Increment the reference count because we're creating another
425 * value pointing at the referenced AV.
427 sv = SvREFCNT_inc (sv);
428 CAMLreturn (Val_sv (sv));
432 perl4caml_av_unshift (value avv, value svv)
434 CAMLparam2 (avv, svv);
435 AV *av = Av_val (avv);
436 SV *sv = Sv_val (svv);
439 if (av_store (av, 0, sv) == 0)
441 CAMLreturn (Val_unit);
445 perl4caml_av_shift (value avv)
448 AV *av = Av_val (avv);
449 SV *sv = av_shift (av);
450 /* Increment the reference count because we're creating another
451 * value pointing at the referenced AV.
453 sv = SvREFCNT_inc (sv);
454 CAMLreturn (Val_sv (sv));
458 perl4caml_av_length (value avv)
461 AV *av = Av_val (avv);
462 CAMLreturn (Val_int (av_len (av) + 1));
466 perl4caml_av_set (value avv, value i, value svv)
468 CAMLparam3 (avv, i, svv);
469 AV *av = Av_val (avv);
470 SV *sv = Sv_val (svv);
472 if (av_store (av, Int_val (i), sv) == 0)
474 CAMLreturn (Val_unit);
478 perl4caml_av_get (value avv, value i)
481 AV *av = Av_val (avv);
482 SV **svp = av_fetch (av, Int_val (i), 0);
483 if (svp == 0) caml_invalid_argument ("av_get: index out of bounds");
484 /* Increment the reference count because we're creating another
485 * value pointing at the referenced AV.
487 *svp = SvREFCNT_inc (*svp);
488 CAMLreturn (Val_sv (*svp));
492 perl4caml_av_clear (value avv)
495 AV *av = Av_val (avv);
497 CAMLreturn (Val_unit);
501 perl4caml_av_undef (value avv)
504 AV *av = Av_val (avv);
506 CAMLreturn (Val_unit);
510 perl4caml_av_extend (value avv, value i)
513 AV *av = Av_val (avv);
514 av_extend (av, Int_val (i));
515 CAMLreturn (Val_unit);
519 perl4caml_hv_empty (value unit)
523 CAMLreturn (Val_hv (hv));
527 perl4caml_hv_set (value hvv, value key, value svv)
529 CAMLparam3 (hvv, key, svv);
530 HV *hv = Hv_val (hvv);
531 SV *sv = Sv_val (svv);
533 if (hv_store (hv, String_val (key), caml_string_length (key), sv, 0) == 0)
535 CAMLreturn (Val_unit);
539 perl4caml_hv_get (value hvv, value key)
541 CAMLparam2 (hvv, key);
542 HV *hv = Hv_val (hvv);
543 SV **svp = hv_fetch (hv, String_val (key), caml_string_length (key), 0);
544 if (svp == 0) caml_raise_not_found ();
545 /* Increment the reference count because we're creating another
546 * value pointing at the referenced SV.
549 CAMLreturn (Val_sv (*svp));
553 perl4caml_hv_exists (value hvv, value key)
555 CAMLparam2 (hvv, key);
556 HV *hv = Hv_val (hvv);
557 bool r = hv_exists (hv, String_val (key), caml_string_length (key));
558 CAMLreturn (r ? Val_true : Val_false);
562 perl4caml_hv_delete (value hvv, value key)
564 CAMLparam2 (hvv, key);
565 HV *hv = Hv_val (hvv);
566 hv_delete (hv, String_val (key), caml_string_length (key), G_DISCARD);
567 CAMLreturn (Val_unit);
571 perl4caml_hv_clear (value hvv)
574 HV *hv = Hv_val (hvv);
576 CAMLreturn (Val_unit);
580 perl4caml_hv_undef (value hvv)
583 HV *hv = Hv_val (hvv);
585 CAMLreturn (Val_unit);
589 perl4caml_hv_iterinit (value hvv)
592 HV *hv = Hv_val (hvv);
593 int i = hv_iterinit (hv);
594 CAMLreturn (caml_copy_int32 (i));
598 perl4caml_hv_iternext (value hvv)
602 HV *hv = Hv_val (hvv);
603 HE *he = hv_iternext (hv);
604 if (he == NULL) caml_raise_not_found ();
610 perl4caml_hv_iterkey (value hev)
614 HE *he = He_val (hev);
616 char *str = hv_iterkey (he, &len);
617 strv = caml_alloc_string (len);
618 memcpy (String_val (strv), str, len);
623 perl4caml_hv_iterval (value hvv, value hev)
625 CAMLparam2 (hvv, hev);
627 HV *hv = Hv_val (hvv);
628 HE *he = He_val (hev);
629 SV *sv = hv_iterval (hv, he);
636 perl4caml_hv_iternextsv (value hvv)
639 CAMLlocal3 (strv, svv, rv);
640 HV *hv = Hv_val (hvv);
642 SV *sv = hv_iternextsv (hv, &str, &len);
643 if (sv == NULL) caml_raise_not_found ();
646 strv = caml_alloc_string (len);
647 memcpy (String_val (strv), str, len);
648 /* Construct a tuple (strv, svv). */
649 rv = caml_alloc_tuple (2);
650 Field (rv, 0) = strv;
656 perl4caml_get_sv (value optcreate, value name)
658 CAMLparam2 (optcreate, name);
662 create = unoption (optcreate, Val_false);
663 sv = get_sv (String_val (name), create == Val_true ? TRUE : FALSE);
664 if (sv == NULL) caml_raise_not_found ();
666 /* Increment the reference count because we're creating another
667 * value pointing at the referenced SV.
671 CAMLreturn (Val_sv (sv));
675 perl4caml_get_av (value optcreate, value name)
677 CAMLparam2 (optcreate, name);
681 create = unoption (optcreate, Val_false);
682 av = get_av (String_val (name), create == Val_true ? TRUE : FALSE);
683 if (av == NULL) caml_raise_not_found ();
685 /* Increment the reference count because we're creating another
686 * value pointing at the AV.
690 CAMLreturn (Val_av (av));
694 perl4caml_get_hv (value optcreate, value name)
696 CAMLparam2 (optcreate, name);
700 create = unoption (optcreate, Val_false);
701 hv = get_hv (String_val (name), create == Val_true ? TRUE : FALSE);
702 if (hv == NULL) caml_raise_not_found ();
704 /* Increment the reference count because we're creating another
705 * value pointing at the HV.
709 CAMLreturn (Val_hv (hv));
713 check_perl_failure ()
715 SV *errsv = get_sv ("@", TRUE);
717 if (SvTRUE (errsv)) /* Equivalent of $@ in Perl. */
721 const char *err = SvPV (errsv, n_a);
723 errv = caml_copy_string (err);
725 caml_raise_with_arg (*caml_named_value ("perl4caml_perl_failure"), errv);
730 perl4caml_call (value optsv, value optfnname, value arglist)
732 CAMLparam3 (optsv, optfnname, arglist);
736 CAMLlocal3 (errv, svv, fnname);
741 /* Push the parameter list. */
744 /* Iteration over the linked list. */
745 for (; arglist != Val_int (0); arglist = Field (arglist, 1))
747 svv = Field (arglist, 0);
749 XPUSHs (sv_2mortal (newSVsv (sv)));
754 if (optsv != Val_int (0))
756 svv = unoption (optsv, Val_false);
758 count = call_sv (sv, G_EVAL|G_SCALAR);
760 else if (optfnname != Val_int (0))
762 fnname = unoption (optfnname, Val_false);
763 count = call_pv (String_val (fnname), G_EVAL|G_SCALAR);
768 "Perl.call: must supply either 'sv' or 'fn' parameters.");
774 assert (count == 1); /* Pretty sure it should never be anything else. */
776 /* Pop return value off the stack. Note that the return value on the
777 * stack is mortal, so we need to take a copy.
784 check_perl_failure ();
791 perl4caml_call_array (value optsv, value optfnname, value arglist)
793 CAMLparam3 (optsv, optfnname, arglist);
797 CAMLlocal5 (errv, svv, fnname, list, cons);
802 /* Push the parameter list. */
805 /* Iteration over the linked list. */
806 for (; arglist != Val_int (0); arglist = Field (arglist, 1))
808 svv = Field (arglist, 0);
810 XPUSHs (sv_2mortal (newSVsv (sv)));
815 if (optsv != Val_int (0))
817 svv = unoption (optsv, Val_false);
819 count = call_sv (sv, G_EVAL|G_ARRAY);
821 else if (optfnname != Val_int (0))
823 fnname = unoption (optfnname, Val_false);
824 count = call_pv (String_val (fnname), G_EVAL|G_ARRAY);
829 "Perl.call_array: must supply either 'sv' or 'fn' parameters.");
835 /* Pop all the return values off the stack into a list. Values on the
836 * stack are mortal, so we must copy them.
839 for (i = 0; i < count; ++i) {
842 cons = caml_alloc (2, 0);
843 Field (cons, 1) = list;
846 Field (cons, 0) = Val_sv (sv);
849 /* Restore the stack. */
854 check_perl_failure ();
860 perl4caml_call_void (value optsv, value optfnname, value arglist)
862 CAMLparam3 (optsv, optfnname, arglist);
866 CAMLlocal3 (errv, svv, fnname);
871 /* Push the parameter list. */
874 /* Iteration over the linked list. */
875 for (; arglist != Val_int (0); arglist = Field (arglist, 1))
877 svv = Field (arglist, 0);
879 XPUSHs (sv_2mortal (newSVsv (sv)));
884 if (optsv != Val_int (0))
886 svv = unoption (optsv, Val_false);
888 count = call_sv (sv, G_EVAL|G_VOID);
890 else if (optfnname != Val_int (0))
892 fnname = unoption (optfnname, Val_false);
893 count = call_pv (String_val (fnname), G_EVAL|G_VOID|G_DISCARD);
898 "Perl.call_void: must supply either 'sv' or 'fn' parameters.");
906 /* Restore the stack. */
911 check_perl_failure ();
913 CAMLreturn (Val_unit);
917 perl4caml_eval (value expr)
922 CAMLlocal2 (errv, svv);
924 sv = eval_pv (String_val (expr), G_SCALAR);
926 check_perl_failure ();
933 perl4caml_call_method (value ref, value name, value arglist)
935 CAMLparam3 (ref, name, arglist);
939 CAMLlocal2 (errv, svv);
944 /* Push the parameter list. */
948 XPUSHs (sv_2mortal (newSVsv (sv)));
950 /* Iteration over the linked list. */
951 for (; arglist != Val_int (0); arglist = Field (arglist, 1))
953 svv = Field (arglist, 0);
955 XPUSHs (sv_2mortal (newSVsv (sv)));
960 count = call_method (String_val (name), G_EVAL|G_SCALAR);
964 assert (count == 1); /* Pretty sure it should never be anything else. */
966 /* Pop return value off the stack. Note that the return value on the
967 * stack is mortal, so we need to take a copy.
974 check_perl_failure ();
981 perl4caml_call_method_array (value ref, value name, value arglist)
983 CAMLparam3 (ref, name, arglist);
987 CAMLlocal4 (errv, svv, list, cons);
992 /* Push the parameter list. */
996 XPUSHs (sv_2mortal (newSVsv (sv)));
998 /* Iteration over the linked list. */
999 for (; arglist != Val_int (0); arglist = Field (arglist, 1))
1001 svv = Field (arglist, 0);
1003 XPUSHs (sv_2mortal (newSVsv (sv)));
1008 count = call_method (String_val (name), G_EVAL|G_ARRAY);
1012 /* Pop all return values off the stack. Note that the return values on the
1013 * stack are mortal, so we need to take a copy.
1016 for (i = 0; i < count; ++i) {
1019 cons = caml_alloc (2, 0);
1020 Field (cons, 1) = list;
1022 sv = newSVsv (POPs);
1023 Field (cons, 0) = Val_sv (sv);
1026 /* Restore the stack. */
1031 check_perl_failure ();
1037 perl4caml_call_method_void (value ref, value name, value arglist)
1039 CAMLparam3 (ref, name, arglist);
1043 CAMLlocal2 (errv, svv);
1048 /* Push the parameter list. */
1052 XPUSHs (sv_2mortal (newSVsv (sv)));
1054 /* Iteration over the linked list. */
1055 for (; arglist != Val_int (0); arglist = Field (arglist, 1))
1057 svv = Field (arglist, 0);
1059 XPUSHs (sv_2mortal (newSVsv (sv)));
1064 count = call_method (String_val (name), G_EVAL|G_VOID|G_DISCARD);
1068 assert (count == 0);
1070 /* Restore the stack. */
1075 check_perl_failure ();
1077 CAMLreturn (Val_unit);
1081 perl4caml_call_class_method (value classname, value name, value arglist)
1083 CAMLparam3 (classname, name, arglist);
1087 CAMLlocal2 (errv, svv);
1092 /* Push the parameter list. */
1095 XPUSHs (sv_2mortal (newSVpv (String_val (classname), 0)));
1097 /* Iteration over the linked list. */
1098 for (; arglist != Val_int (0); arglist = Field (arglist, 1))
1100 svv = Field (arglist, 0);
1102 XPUSHs (sv_2mortal (newSVsv (sv)));
1107 count = call_method (String_val (name), G_EVAL|G_SCALAR);
1111 assert (count == 1); /* Pretty sure it should never be anything else. */
1113 /* Pop return value off the stack. Note that the return value on the
1114 * stack is mortal, so we need to take a copy.
1116 sv = newSVsv (POPs);
1121 check_perl_failure ();
1128 perl4caml_call_class_method_array (value classname, value name, value arglist)
1130 CAMLparam3 (classname, name, arglist);
1134 CAMLlocal4 (errv, svv, list, cons);
1139 /* Push the parameter list. */
1142 XPUSHs (sv_2mortal (newSVpv (String_val (classname), 0)));
1144 /* Iteration over the linked list. */
1145 for (; arglist != Val_int (0); arglist = Field (arglist, 1))
1147 svv = Field (arglist, 0);
1149 XPUSHs (sv_2mortal (newSVsv (sv)));
1154 count = call_method (String_val (name), G_EVAL|G_ARRAY);
1158 /* Pop all return values off the stack. Note that the return values on the
1159 * stack are mortal, so we need to take a copy.
1162 for (i = 0; i < count; ++i) {
1163 cons = caml_alloc (2, 0);
1164 Field (cons, 1) = list;
1166 Field (cons, 0) = Val_sv (newSVsv (POPs));
1169 /* Restore the stack. */
1174 check_perl_failure ();
1180 perl4caml_call_class_method_void (value classname, value name, value arglist)
1182 CAMLparam3 (classname, name, arglist);
1186 CAMLlocal2 (errv, svv);
1191 /* Push the parameter list. */
1194 XPUSHs (sv_2mortal (newSVpv (String_val (classname), 0)));
1196 /* Iteration over the linked list. */
1197 for (; arglist != Val_int (0); arglist = Field (arglist, 1))
1199 svv = Field (arglist, 0);
1201 XPUSHs (sv_2mortal (newSVsv (sv)));
1206 count = call_method (String_val (name), G_EVAL|G_VOID|G_DISCARD);
1210 assert (count == 0);
1212 /* Restore the stack. */
1217 check_perl_failure ();
1219 CAMLreturn (Val_unit);
1223 Val_voidptr (void *ptr)
1227 rv = caml_alloc (1, Abstract_tag);
1228 Field(rv, 0) = (value) ptr;
1232 #if PERL4CAML_REFCOUNTING_EXPERIMENTAL
1235 xv_finalize (value v)
1237 /*fprintf (stderr, "about to decrement %p\n", Xv_val (v));*/
1238 SvREFCNT_dec ((SV *) Xv_val (v));
1241 static struct custom_operations xv_custom_operations = {
1242 "xv_custom_operations",
1244 custom_compare_default,
1245 custom_hash_default,
1246 custom_serialize_default,
1247 custom_deserialize_default
1255 rv = caml_alloc_custom (&xv_custom_operations, sizeof (void *), 0, 1);
1260 #endif /* PERL4CAML_REFCOUNTING_EXPERIMENTAL */
1263 unoption (value option, value deflt)
1265 if (option == Val_int (0)) /* "None" */
1267 else /* "Some 'a" */
1268 return Field (option, 0);