From: rich Date: Thu, 16 Oct 2003 08:54:56 +0000 (+0000) Subject: Worked around OCaml initialization bug. X-Git-Url: http://git.annexia.org/?a=commitdiff_plain;h=721a6cf6a40bbb25c7f878e89d18a6c0cfdd9109;p=perl4caml.git Worked around OCaml initialization bug. --- diff --git a/.depend b/.depend index b7d8bc1..544ba14 100644 --- a/.depend +++ b/.depend @@ -8,8 +8,8 @@ examples/loadpage.cmo: perl.cmi wrappers/pl_HTML_Element.cmo \ examples/loadpage.cmx: perl.cmx wrappers/pl_HTML_Element.cmx \ wrappers/pl_HTML_TreeBuilder.cmx wrappers/pl_HTTP_Request.cmx \ wrappers/pl_LWP_UserAgent.cmx -examples/test.cmo: perl.cmi wrappers/pl_Net_Google.cmo -examples/test.cmx: perl.cmx wrappers/pl_Net_Google.cmx +examples/test.cmo: perl.cmi +examples/test.cmx: perl.cmx wrappers/pl_HTML_Element.cmo: perl.cmi wrappers/pl_HTML_Element.cmx: perl.cmx wrappers/pl_HTML_Parser.cmo: perl.cmi diff --git a/examples/test.ml b/examples/test.ml index 99bcfd4..f06fe5b 100644 --- a/examples/test.ml +++ b/examples/test.ml @@ -1,15 +1,10 @@ (* Simple test of the API. * Copyright (C) 2003 Merjis Ltd. - * $Id: test.ml,v 1.3 2003-10-15 16:51:12 rich Exp $ + * $Id: test.ml,v 1.4 2003-10-16 08:54:56 rich Exp $ *) open Printf -(* XXX Hack to workaround some sort of linking bug in OCaml. Without this - * the Perl module isn't initialized and this code crashes. - *) -let f = Pl_Net_Google.may - let () = (* Load "test.pl". *) Perl.eval "require 'examples/test.pl'"; diff --git a/perl.ml b/perl.ml index 0f2d9fc..da811c0 100644 --- a/perl.ml +++ b/perl.ml @@ -1,6 +1,6 @@ (* Interface to Perl from OCaml. * Copyright (C) 2003 Merjis Ltd. - * $Id: perl.ml,v 1.6 2003-10-15 16:51:12 rich Exp $ + * $Id: perl.ml,v 1.7 2003-10-16 08:54:56 rich Exp $ *) type t @@ -18,10 +18,6 @@ external create : ?args:string array -> unit -> t *) external c_init : unit -> unit = "perl4caml_init" let () = - (* Leave this debugging message in for now until init support in OCaml - * is debugged. - *) - prerr_endline "perl_init: Initialising Perl support ..."; Callback.register_exception "perl4caml_perl_failure" (Perl_failure ""); c_init (); (* Initialise C code. *) (* Create the default interpreter. *) diff --git a/perl.mli b/perl.mli index 6be7f38..36cb213 100644 --- a/perl.mli +++ b/perl.mli @@ -2,7 +2,7 @@ * * Copyright (C) 2003 Merjis Ltd. * - * $Id: perl.mli,v 1.6 2003-10-15 16:51:12 rich Exp $ + * $Id: perl.mli,v 1.7 2003-10-16 08:54:56 rich Exp $ *) type t @@ -22,8 +22,7 @@ type hv exception Perl_failure of string (** [die] in Perl code is translated automatically into this exception. *) -external current_interpreter : unit -> t - = "perl4caml_current_interpreter" +val current_interpreter : unit -> t (** The [Perl] module has a notion of the "current" interpreter. Throws * [Not_found] if there is no current interpreter. * @@ -46,8 +45,7 @@ external current_interpreter : unit -> t * by calling {!Perl.destroy} followed by {!Perl.create}. *) -external destroy : t -> unit - = "perl4caml_destroy" +val destroy : t -> unit (** Destroy the Perl interpreter, performing any necessary cleanup. * * You should call [Perl.destroy (Perl.current_interpreter ())] at @@ -61,8 +59,7 @@ external destroy : t -> unit * {!Perl.current_interpreter}. *) -external create : ?args:string array -> unit -> t - = "perl4caml_create" +val create : ?args:string array -> unit -> t (** Create a new Perl interpreter. (Note that a Perl interpreter is created * for you by default so you don't need to call this). * @@ -78,8 +75,7 @@ external create : ?args:string array -> unit -> t * The newly created interpreter is set as the "current interpreter". *) -external set_context : t -> unit - = "perl4caml_set_context" +val set_context : t -> unit (** IF Perl was compiled with [-Dusemultiplicity] and IF you are using * multiple interpreters at the same time, then you must call this to * set the implied "current" interpreter. @@ -87,40 +83,40 @@ external set_context : t -> unit * Most users will never need to call this function. *) -external int_of_sv : sv -> int = "perl4caml_int_of_sv" +val int_of_sv : sv -> int (** Convert a Perl [SV] into an integer. Note that OCaml [int]s aren't * large enough to store the full 32 (or 64) bits from a Perl integer, * so you may get a silent overflow. *) -external sv_of_int : int -> sv = "perl4caml_sv_of_int" +val sv_of_int : int -> sv (** Convert an [int] into a Perl [SV]. *) -external float_of_sv : sv -> int = "perl4caml_float_of_sv" +val float_of_sv : sv -> int (** Convert a Perl [SV] into a float. *) -external sv_of_float : int -> sv = "perl4caml_sv_of_float" +val sv_of_float : int -> sv (** Convert a [float] into a Perl [SV]. *) -external string_of_sv : sv -> string = "perl4caml_string_of_sv" +val string_of_sv : sv -> string (** Convert a Perl [SV] into a string. *) -external sv_of_string : string -> sv = "perl4caml_sv_of_string" +val sv_of_string : string -> sv (** Convert a [string] into a Perl [SV]. *) val bool_of_sv : sv -> bool (** Convert an [SV] into a boolean. *) val sv_of_bool : bool -> sv (** Convert a boolean into an [SV]. *) -external sv_is_true : sv -> bool = "perl4caml_sv_is_true" +val sv_is_true : sv -> bool (** Return [true] if the [SV] is "true" (in the Perl sense of truth). *) -external sv_is_undef : sv -> bool = "perl4caml_sv_is_undef" +val sv_is_undef : sv -> bool (** Return [true] if the [SV] is undefined (is [undef]). *) -external sv_undef : unit -> sv = "perl4caml_sv_undef" +val sv_undef : unit -> sv (** Returns [undef]. *) val sv_true : unit -> sv (** Returns an [SV] which is true. *) val sv_false : unit -> sv (** Returns an [SV] which is false. *) -external sv_yes : unit -> sv = "perl4caml_sv_yes" +val sv_yes : unit -> sv (** Returns Perl's internal [PL_sv_yes]. (There are some unresolved issues * with using this, so use {!sv_true} instead). *) -external sv_no : unit -> sv = "perl4caml_sv_no" +val sv_no : unit -> sv (** Returns Perl's internal [PL_sv_no]. (There are some unresolved issues * with using this, so use {!sv_false} instead). *) @@ -135,63 +131,63 @@ type sv_t = SVt_NULL | SVt_PVCV (** Code ref. *) | SVt_PVGV (** Glob. *) | SVt_PVMG (** Blessed or magical scalar. *) -external sv_type : sv -> sv_t = "perl4caml_sv_type" +val sv_type : sv -> sv_t (** Return the type of data contained in an [SV]. Somewhat equivalent to * calling Perl's [ref] function. *) val string_of_sv_t : sv_t -> string (** Return a printable string for an [sv_t] ([SV] type). *) -external deref : sv -> sv = "perl4caml_deref" +val deref : sv -> sv (** The input is a reference to a scalar. This returns the underlying * scalar [SV]. If the input is not a reference to a scalar, throws * [Invalid_arg]. *) -external deref_array : sv -> av = "perl4caml_deref_array" +val deref_array : sv -> av (** The input is a reference to an array. This returns the underlying * array [AV]. If the input is not a reference to an array, throws * [Invalid_arg]. *) (* -external deref_hash : sv -> hv = "perl4caml_deref_hash" +val deref_hash : sv -> hv (** The input is a reference to a hash. This returns the underlying * hash [HV]. If the input is not a reference to a hash, throws * [Invalid_arg]. *) *) -external av_empty : unit -> av = "perl4caml_av_empty" +val av_empty : unit -> av (** Create an empty [AV] (array). *) -external av_of_sv_list : sv list -> av = "perl4caml_av_of_sv_list" +val av_of_sv_list : sv list -> av (** Create an array from a list of [SVs]. *) -external av_push : av -> sv -> unit = "perl4caml_av_push" +val av_push : av -> sv -> unit (** Append the [SV] to the end of the array. Same as Perl [push @av, $sv]. *) -external av_pop : av -> sv = "perl4caml_av_pop" +val av_pop : av -> sv (** Remove the [SV] at the end of the array and return it. Same as * Perl [$sv = pop @av]. *) -external av_shift : av -> sv = "perl4caml_av_shift" +val av_shift : av -> sv (** Remove the [SV] at the beginning of the array and return it. Same as * Perl [$sv = shift @av]. *) -external av_unshift : av -> sv -> unit = "perl4caml_av_unshift" +val av_unshift : av -> sv -> unit (** Prepend the [SV] to the start of the array. Same as Perl * [unshift @av, $sv]. *) -external av_length : av -> int = "perl4caml_av_length" +val av_length : av -> int (** Return the length of the [AV]. *) -external av_set : av -> int -> sv -> unit = "perl4caml_av_set" +val av_set : av -> int -> sv -> unit (** Replace the i'th element of the [AV] with [SV]. *) -external av_get : av -> int -> sv = "perl4caml_av_get" +val av_get : av -> int -> sv (** Get the i'th element of the [AV]. *) -external av_clear : av -> unit = "perl4caml_av_clear" +val av_clear : av -> unit (** Remove all elements from the [AV]. Same as Perl [@av = ()]. *) -external av_undef : av -> unit = "perl4caml_av_undef" +val av_undef : av -> unit (** Delete the [AV] (and all elements in it). Same as Perl [undef @av]. *) -external av_extend : av -> int -> unit = "perl4caml_av_extend" +val av_extend : av -> int -> unit (** Extend the [AV] so it contains at least [n+1] elements. *) val av_map : (sv -> 'a) -> av -> 'a list (** Map a function over the elements in the [AV], return a list of the * results. *) -external get_sv : ?create:bool -> string -> sv = "perl4caml_get_sv" +val get_sv : ?create:bool -> string -> sv (** Return a scalar value by name. For example, if you have a symbol * called [$a] in Perl, then [get_sv "a"] will return its value. * @@ -201,11 +197,10 @@ external get_sv : ?create:bool -> string -> sv = "perl4caml_get_sv" * not exist, then Perl will create the symbol (with value [undef]) and * this function will return the [SV] for [undef]. *) -external get_av : ?create:bool -> string -> av = "perl4caml_get_av" +val get_av : ?create:bool -> string -> av (** Same as {!get_sv} except will return and/or create [@a]. *) -external call : ?sv:sv -> ?fn:string -> sv list -> sv - = "perl4caml_call" +val call : ?sv:sv -> ?fn:string -> sv list -> sv (** Call a Perl function in a scalar context, either by name (using the [?fn] * parameter) or by calling a string/CODEREF (using the [?sv] parameter). * @@ -214,8 +209,7 @@ external call : ?sv:sv -> ?fn:string -> sv list -> sv * If the Perl code calls [die] then this will throw [Perl_failure]. *) -external call_array : ?sv:sv -> ?fn:string -> sv list -> sv list - = "perl4caml_call_array" +val call_array : ?sv:sv -> ?fn:string -> sv list -> sv list (** Call a Perl function in an array context, either by name (using the [?fn] * parameter) or by calling a string/CODEREF (using the [?sv] parameter). * @@ -224,8 +218,7 @@ external call_array : ?sv:sv -> ?fn:string -> sv list -> sv list * If the Perl code calls [die] then this will throw [Perl_failure]. *) -external call_void : ?sv:sv -> ?fn:string -> sv list -> unit - = "perl4caml_call_void" +val call_void : ?sv:sv -> ?fn:string -> sv list -> unit (** Call a Perl function in a void context, either by name (using the [?fn] * parameter) or by calling a string/CODEREF (using the [?sv] parameter). * @@ -234,14 +227,12 @@ external call_void : ?sv:sv -> ?fn:string -> sv list -> unit * If the Perl code calls [die] then this will throw [Perl_failure]. *) -external eval : string -> sv - = "perl4caml_eval" +val eval : string -> sv (** This is exactly like the Perl [eval] command. It evaluates a piece of * Perl code (in scalar context) and returns the result (a Perl [SV]). *) -external call_method : sv -> string -> sv list -> sv - = "perl4caml_call_method" +val call_method : sv -> string -> sv list -> sv (** [call_method obj name [parameters]] calls the method [name] on the Perl * object [obj] with the given parameters, in a scalar context. Thus this * is equivalent to [$obj->name (parameters)]. @@ -251,17 +242,14 @@ external call_method : sv -> string -> sv list -> sv * If the method calls [die] then this will throw [Perl_failure]. *) -external call_method_array : sv -> string -> sv list -> sv list - = "perl4caml_call_method_array" +val call_method_array : sv -> string -> sv list -> sv list (** Like [call_method], but the method is called in an array context. *) -external call_method_void : sv -> string -> sv list -> unit - = "perl4caml_call_method_void" +val call_method_void : sv -> string -> sv list -> unit (** Like [call_method], but the method is called in a void context (results * are discarded). *) -external call_class_method : string -> string -> sv list -> sv - = "perl4caml_call_class_method" +val call_class_method : string -> string -> sv list -> sv (** [call_class_method classname name [parameters]] calls the static method * [name] in the Perl class [classname] with the given parameters, in a * scalar context. Thus this is equivalent to [$classname->name (parameters)]. @@ -271,10 +259,8 @@ external call_class_method : string -> string -> sv list -> sv * If the static method calls [die] then this will throw [Perl_failure]. *) -external call_class_method_array : string -> string -> sv list -> sv list - = "perl4caml_call_class_method_array" +val call_class_method_array : string -> string -> sv list -> sv list (** Like [call_class_method], but the method is called in an array context. *) -external call_class_method_void : string -> string -> sv list -> unit - = "perl4caml_call_class_method_void" +val call_class_method_void : string -> string -> sv list -> unit (** Like [call_class_method], but the method is called in a void context. *)