[svn:parrot] r37159 - in trunk: config/gen/makefiles src/ops src/pmc

cotto at svn.parrot.org cotto at svn.parrot.org
Sat Mar 7 10:57:42 UTC 2009


Author: cotto
Date: Sat Mar  7 10:57:41 2009
New Revision: 37159
URL: https://trac.parrot.org/parrot/changeset/37159

Log:
[PMC] partially convert ParrotLibrary to ATTRs (no dynops breakage yet)

Modified:
   trunk/config/gen/makefiles/root.in
   trunk/src/ops/core.ops
   trunk/src/pmc/parrotlibrary.pmc

Modified: trunk/config/gen/makefiles/root.in
==============================================================================
--- trunk/config/gen/makefiles/root.in	Sat Mar  7 10:55:55 2009	(r37158)
+++ trunk/config/gen/makefiles/root.in	Sat Mar  7 10:57:41 2009	(r37159)
@@ -1202,7 +1202,7 @@
 $(IO_DIR)/filehandle$(O) : $(SRC_DIR)/pmc/pmc_filehandle.h $(SRC_DIR)/io/io_private.h
 
 $(OPS_DIR)/core_ops$(O) : $(GENERAL_H_FILES) $(OPS_DIR)/core_ops.c \
-	$(SRC_DIR)/pmc/pmc_continuation.h
+	$(SRC_DIR)/pmc/pmc_continuation.h $(SRC_DIR)/pmc/pmc_continuation.h
 
 $(OPS_DIR)/pic.ops : $(SRC_DIR)/pmc/pmc_fixedintegerarray.h
 

Modified: trunk/src/ops/core.ops
==============================================================================
--- trunk/src/ops/core.ops	Sat Mar  7 10:55:55 2009	(r37158)
+++ trunk/src/ops/core.ops	Sat Mar  7 10:57:41 2009	(r37159)
@@ -7,6 +7,7 @@
 #include "parrot/embed.h"
 #include "../interp_guts.h"
 #include "../pmc/pmc_continuation.h"
+#include "../pmc/pmc_parrotlibrary.h"
 
 VERSION = PARROT_VERSION;
 
@@ -1344,14 +1345,22 @@
 }
 
 op dlfunc(out PMC, invar PMC, in STR, in STR) {
-    char * const name = Parrot_str_to_cstring(interp, ($3));
-    void * const ptr  = Parrot_dlsym(
-                            PMC_IS_NULL($2) ? NULL :
-                            VTABLE_defined(interp, $2) ? PMC_data($2) :
-                            NULL,
-                            name);
+    char * const  name      = Parrot_str_to_cstring(interp, ($3));
+    void         *dl_handle = NULL;
+    void         *ptr       = NULL;
+    funcptr_t     p;
+
+    if (!PMC_IS_NULL($2) && $2->vtable->base_type == enum_class_ParrotLibrary) {
+        dl_handle = ((Parrot_ParrotLibrary_attributes*)PMC_data($2))->dl_handle;
+    }
+
+    ptr = Parrot_dlsym(
+            PMC_IS_NULL($2) ? NULL :
+            VTABLE_defined(interp, $2) ? dl_handle :
+            NULL,
+            name);
 
-    funcptr_t p = D2FPTR(ptr);
+    p = D2FPTR(ptr);
 
     if (p == NULLfunc) {
         const char * err = Parrot_dlerror();
@@ -1368,8 +1377,14 @@
 }
 
 op dlvar(out PMC, invar PMC, in STR) {
-    char * const name = Parrot_str_to_cstring(interp, ($3));
-    void * const p = Parrot_dlsym(PMC_IS_NULL($2) ? NULL : PMC_data($2), name);
+    char * const  name      = Parrot_str_to_cstring(interp, ($3));
+    void *        p         = NULL;
+    void         *dl_handle = NULL;
+
+    if (!PMC_IS_NULL($2) && $2->vtable->base_type == enum_class_ParrotLibrary) {
+        dl_handle = ((Parrot_ParrotLibrary_attributes*)PMC_data($2))->dl_handle;
+        p         = Parrot_dlsym(PMC_IS_NULL($2) ? NULL : dl_handle, name);
+    }
     if (p == NULL) {
         const char * const err = Parrot_dlerror();
         Parrot_warn(interp, PARROT_WARNINGS_UNDEF_FLAG,

Modified: trunk/src/pmc/parrotlibrary.pmc
==============================================================================
--- trunk/src/pmc/parrotlibrary.pmc	Sat Mar  7 10:55:55 2009	(r37158)
+++ trunk/src/pmc/parrotlibrary.pmc	Sat Mar  7 10:57:41 2009	(r37159)
@@ -34,7 +34,10 @@
 
 #include "parrot/parrot.h"
 
+#define PMC_dlhandle(x) ((Parrot_ParrotLibrary_attributes*)PMC_data(x))->dl_handle
+
 pmclass ParrotLibrary need_ext provides library {
+    ATTR void * dl_handle;
 
 /*
 
@@ -47,6 +50,9 @@
 */
 
     VTABLE void init() {
+        Parrot_ParrotLibrary_attributes *attrs =
+            mem_allocate_zeroed_typed(Parrot_ParrotLibrary_attributes);
+        PMC_data(SELF) = attrs;
         PObj_active_destroy_SET(SELF);
         PMC_struct_val(SELF) = NULL;
     }
@@ -62,8 +68,10 @@
 */
 
     VTABLE void destroy() {
-        if (PMC_data(SELF))
-            Parrot_dlclose(PMC_data(SELF));
+        void *dl_handle = PMC_dlhandle(SELF);
+        if (dl_handle)
+            Parrot_dlclose(dl_handle);
+        mem_sys_free(PMC_data(SELF));
     }
 
 
@@ -78,9 +86,9 @@
 */
 
     VTABLE PMC *clone() {
-        PMC *dest            = pmc_new_noinit(INTERP, SELF->vtable->base_type);
+        PMC *dest            = pmc_new(INTERP, SELF->vtable->base_type);
         PMC_struct_val(dest) = PMC_struct_val(SELF);
-        PMC_data(dest)       = PMC_data(SELF);
+        PMC_dlhandle(dest)   = PMC_dlhandle(SELF);
 
         if (PMC_metadata(SELF))
             PMC_metadata(dest) = VTABLE_clone(INTERP, PMC_metadata(SELF));
@@ -99,7 +107,7 @@
 */
 
     VTABLE INTVAL get_bool() {
-        return (PMC_data(SELF) != NULL);
+        return (PMC_dlhandle(SELF) != NULL);
     }
 
 /*
@@ -130,7 +138,7 @@
 */
 
     VTABLE void set_pointer(void *handle) {
-        PMC_data(SELF) = handle;
+        PMC_dlhandle(SELF) = handle;
     }
 }
 


More information about the parrot-commits mailing list