cvsuser 04/08/23 02:10:02
Modified: include/parrot dynext.h
src dynext.c
Log:
[perl #31114] [PATCH] Dynext functions
I am not sure about this patch. It splits part of Parrot_load_lib
into a Parrot_init_lib(Interp, load_func_ptr, init_func_ptr)
where load/init_func_ptr are pointers to the function loadlib calls. The
objective is allowing dynamic PMCs linked inside a larger library
or maybe an executable. For example Ponie might have Perl5IV,
Perl5PVCV, etc. PMCs linked inside libponie, and the interpreter
construction function would call directly
Parrot_init_lib(PL_Parrot, &Parrot_lib_perl5iv_load, &Parrot_lib_perl5iv_init);
Courtesy of Mattia Barbon <[EMAIL PROTECTED]>
Revision Changes Path
1.6 +7 -1 parrot/include/parrot/dynext.h
Index: dynext.h
===================================================================
RCS file: /cvs/public/parrot/include/parrot/dynext.h,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -w -r1.5 -r1.6
--- dynext.h 22 Apr 2004 08:55:05 -0000 1.5
+++ dynext.h 23 Aug 2004 09:09:59 -0000 1.6
@@ -1,6 +1,6 @@
/* dynext.h
*
-* $Id: dynext.h,v 1.5 2004/04/22 08:55:05 leo Exp $
+* $Id: dynext.h,v 1.6 2004/08/23 09:09:59 leo Exp $
*
* Parrot dynamic extensions
*/
@@ -12,5 +12,11 @@
/* dynamic lib/oplib/PMC loading */
PMC *Parrot_load_lib(Interp *interpreter, STRING *lib, PMC *initializer);
+/* dynamic lib/oplib/PMC init */
+PMC *
+Parrot_init_lib(Interp *interpreter,
+ PMC *(*load_func)(Interp *),
+ void (*init_func)(Interp *, PMC *));
+
#endif /* PARROT_DYNEXT_H_GUARD */
1.27 +41 -24 parrot/src/dynext.c
Index: dynext.c
===================================================================
RCS file: /cvs/public/parrot/src/dynext.c,v
retrieving revision 1.26
retrieving revision 1.27
diff -u -w -r1.26 -r1.27
--- dynext.c 26 May 2004 13:04:07 -0000 1.26
+++ dynext.c 23 Aug 2004 09:10:02 -0000 1.27
@@ -1,6 +1,6 @@
/*
Copyright: 2001-2003 The Perl Foundation. All Rights Reserved.
-$Id: dynext.c,v 1.26 2004/05/26 13:04:07 jrieks Exp $
+$Id: dynext.c,v 1.27 2004/08/23 09:10:02 leo Exp $
=head1 NAME
@@ -226,6 +226,41 @@
*/
PMC *
+Parrot_init_lib(Interp *interpreter,
+ PMC *(*load_func)(Interp *),
+ void (*init_func)(Interp *, PMC *))
+{
+ STRING *type;
+ PMC *lib_pmc;
+
+ if (!load_func) {
+ /* seems to be a native/NCI lib */
+ /*
+ * this PMC should better be constant, but then all the contents
+ * and the metadata have to be constant too
+ * s. also build_tools/ops2c.pl and lib/Parrot/Pmc2c.pm
+ */
+ lib_pmc = pmc_new(interpreter, enum_class_ParrotLibrary);
+ type = const_string(interpreter, "NCI");
+ }
+ else {
+ lib_pmc = (*load_func)(interpreter);
+ /* we could set a private flag in the PMC header too
+ * but currently only ops files have struct_val set
+ */
+ type = const_string(interpreter,
+ PMC_struct_val(lib_pmc) ? "Ops" : "PMC");
+ }
+ /*
+ * call init, if it exists
+ */
+ if (init_func)
+ (init_func)(interpreter, lib_pmc);
+
+ return lib_pmc;
+}
+
+PMC *
Parrot_load_lib(Interp *interpreter, STRING *lib, PMC *initializer)
{
STRING *path, *load_func_name, *init_func_name, *type;
@@ -264,39 +299,21 @@
/* UNLOCK */
return lib_pmc;
}
+ /* get load_func */
load_func_name = Parrot_sprintf_c(interpreter, "Parrot_lib_%Ss_load", lib);
cload_func_name = string_to_cstring(interpreter, load_func_name);
load_func = (PMC * (*)(Interp *))D2FPTR(Parrot_dlsym(handle,
cload_func_name));
string_cstring_free(cload_func_name);
- if (!load_func) {
- /* seems to be a native/NCI lib */
- /*
- * this PMC should better be constant, but then all the contents
- * and the metadata have to be constant too
- * s. also build_tools/ops2c.pl and lib/Parrot/Pmc2c.pm
- */
- lib_pmc = pmc_new(interpreter, enum_class_ParrotLibrary);
- type = const_string(interpreter, "NCI");
- }
- else {
- lib_pmc = (*load_func)(interpreter);
- /* we could set a private flag in the PMC header too
- * but currently only ops files have struct_val set
- */
- type = const_string(interpreter,
- PMC_struct_val(lib_pmc) ? "Ops" : "PMC");
- }
- /*
- * call init, if it exists
- */
+ /* get init_func */
init_func_name = Parrot_sprintf_c(interpreter, "Parrot_lib_%Ss_init", lib);
cinit_func_name = string_to_cstring(interpreter, init_func_name);
init_func = (void (*)(Interp *, PMC *))D2FPTR(Parrot_dlsym(handle,
cinit_func_name));
string_cstring_free(cinit_func_name);
- if (init_func)
- (init_func)(interpreter, lib_pmc);
+
+ lib_pmc = Parrot_init_lib(interpreter, load_func, init_func);
+
PMC_data(lib_pmc) = handle;
/*
* remember lib_pmc in iglobals