[svn:parrot] r48009 - in trunk: include/parrot src src/ops

NotFound at svn.parrot.org NotFound at svn.parrot.org
Mon Jul 5 14:33:32 UTC 2010


Author: NotFound
Date: Mon Jul  5 14:33:31 2010
New Revision: 48009
URL: https://trac.parrot.org/parrot/changeset/48009

Log:
add function Parrot_dlsym_str to simplify Parrot_dlsym usages

Modified:
   trunk/include/parrot/dynext.h
   trunk/src/dynext.c
   trunk/src/ops/core.ops
   trunk/src/ops/core_ops.c

Modified: trunk/include/parrot/dynext.h
==============================================================================
--- trunk/include/parrot/dynext.h	Mon Jul  5 10:50:46 2010	(r48008)
+++ trunk/include/parrot/dynext.h	Mon Jul  5 14:33:31 2010	(r48009)
@@ -32,6 +32,13 @@
         FUNC_MODIFIES(*s);
 
 PARROT_EXPORT
+PARROT_CAN_RETURN_NULL
+void * Parrot_dlsym_str(PARROT_INTERP,
+    ARGIN_NULLOK(void *handle),
+    ARGIN_NULLOK(STRING *symbol))
+        __attribute__nonnull__(1);
+
+PARROT_EXPORT
 PARROT_CANNOT_RETURN_NULL
 PMC * Parrot_init_lib(PARROT_INTERP,
     NULLOK(dynext_load_func load_func),
@@ -50,6 +57,8 @@
        PARROT_ASSERT_ARG(d) \
     , PARROT_ASSERT_ARG(s) \
     , PARROT_ASSERT_ARG(lib_pmc))
+#define ASSERT_ARGS_Parrot_dlsym_str __attribute__unused__ int _ASSERT_ARGS_CHECK = (\
+       PARROT_ASSERT_ARG(interp))
 #define ASSERT_ARGS_Parrot_init_lib __attribute__unused__ int _ASSERT_ARGS_CHECK = (\
        PARROT_ASSERT_ARG(interp))
 #define ASSERT_ARGS_Parrot_load_lib __attribute__unused__ int _ASSERT_ARGS_CHECK = (\

Modified: trunk/src/dynext.c
==============================================================================
--- trunk/src/dynext.c	Mon Jul  5 10:50:46 2010	(r48008)
+++ trunk/src/dynext.c	Mon Jul  5 14:33:31 2010	(r48009)
@@ -413,6 +413,36 @@
 
 /*
 
+=item C<void * Parrot_dlsym_str(PARROT_INTERP, void *handle, STRING *symbol)>
+
+Same as Parrot_dlsym but takes the symbol name from a Parrot String instead
+of a C string.
+
+=cut
+
+*/
+
+PARROT_EXPORT
+PARROT_CAN_RETURN_NULL
+void *
+Parrot_dlsym_str(PARROT_INTERP,
+        ARGIN_NULLOK(void *handle), ARGIN_NULLOK(STRING *symbol))
+{
+    ASSERT_ARGS(Parrot_dlsym_str)
+
+    void *ptr;
+    if (STRING_IS_NULL(symbol))
+        ptr = NULL;
+    else {
+        char *const symbol_cs = Parrot_str_to_cstring(interp, symbol);
+        ptr = Parrot_dlsym(handle, symbol_cs);
+        Parrot_str_free_cstring(symbol_cs);
+    }
+    return ptr;
+}
+
+/*
+
 =item C<static PMC * run_init_lib(PARROT_INTERP, void *handle, STRING *lib_name,
 STRING *wo_ext)>
 
@@ -453,18 +483,14 @@
                                         "Parrot_lib_%Ss_load", lib_name);
         STRING * const init_func_name  = Parrot_sprintf_c(interp,
                                         "Parrot_lib_%Ss_init", lib_name);
-        char   * const cload_func_name = Parrot_str_to_cstring(interp, load_name);
-        char   * const cinit_func_name = Parrot_str_to_cstring(interp, init_func_name);
 
         /* get load_func */
-        void * dlsymfunc = Parrot_dlsym(handle, cload_func_name);
+        void * dlsymfunc = Parrot_dlsym_str(interp, handle, load_name);
         load_func = (PMC * (*)(PARROT_INTERP)) D2FPTR(dlsymfunc);
-        Parrot_str_free_cstring(cload_func_name);
 
         /* get init_func */
-        dlsymfunc = Parrot_dlsym(handle, cinit_func_name);
+        dlsymfunc = Parrot_dlsym_str(interp, handle, init_func_name);
         init_func = (void (*)(PARROT_INTERP, PMC *)) D2FPTR(dlsymfunc);
-        Parrot_str_free_cstring(cinit_func_name);
     }
     else {
         load_func = NULL;

Modified: trunk/src/ops/core.ops
==============================================================================
--- trunk/src/ops/core.ops	Mon Jul  5 10:50:46 2010	(r48008)
+++ trunk/src/ops/core.ops	Mon Jul  5 14:33:31 2010	(r48009)
@@ -1253,7 +1253,6 @@
 }
 
 op dlfunc(out PMC, invar PMC, in STR, in STR) {
-    char * const  name      = Parrot_str_to_cstring(interp, ($3));
     void         *dl_handle = NULL;
     void         *ptr       = NULL;
     funcptr_t     p;
@@ -1264,24 +1263,22 @@
         dl_handle = ((Parrot_ParrotLibrary_attributes*)PMC_data($2))->dl_handle;
     }
 
-    ptr = Parrot_dlsym(dl_handle, name);
+    ptr = Parrot_dlsym_str(interp, dl_handle, $3);
     p = D2FPTR(ptr);
 
     if (p == NULLfunc) {
         const char * err = Parrot_dlerror();
         Parrot_warn(interp, PARROT_WARNINGS_UNDEF_FLAG,
-                "Symbol '%s' not found: %s\n", name, err ? err : "unknown reason");
+                "Symbol '%Ss' not found: %s\n", $3, err ? err : "unknown reason");
         $1 = Parrot_pmc_new(interp, enum_class_Undef);
     }
     else {
         $1 = Parrot_pmc_new(interp, enum_class_NCI);
         VTABLE_set_pointer_keyed_str(interp, $1, $4, F2DPTR(p));
     }
-    Parrot_str_free_cstring(name);
 }
 
 op dlvar(out PMC, invar PMC, in STR) {
-    char * const  name      = Parrot_str_to_cstring(interp, ($3));
     void *        dl_handle = NULL;
     void *        p         = NULL;
 
@@ -1291,12 +1288,12 @@
         dl_handle = ((Parrot_ParrotLibrary_attributes*)PMC_data($2))->dl_handle;
     }
 
-    p = Parrot_dlsym(dl_handle, name);
+    p = Parrot_dlsym_str(interp, dl_handle, $3);
 
     if (p == NULL) {
         const char * const err = Parrot_dlerror();
         Parrot_warn(interp, PARROT_WARNINGS_UNDEF_FLAG,
-                "Symbol '%s' not found: %s\n", name, err ? err : "unknown reason");
+                "Symbol '%Ss' not found: %s\n", $3, err ? err : "unknown reason");
         $1 = Parrot_pmc_new(interp, enum_class_Undef);
     }
     else {
@@ -1305,7 +1302,6 @@
         $1 = Parrot_pmc_new(interp, enum_class_UnManagedStruct);
         VTABLE_set_pointer(interp, $1, p);
     }
-    Parrot_str_free_cstring(name);
 }
 
 inline op compreg(in STR, invar PMC) {

Modified: trunk/src/ops/core_ops.c
==============================================================================
--- trunk/src/ops/core_ops.c	Mon Jul  5 10:50:46 2010	(r48008)
+++ trunk/src/ops/core_ops.c	Mon Jul  5 14:33:31 2010	(r48009)
@@ -15126,7 +15126,6 @@
 opcode_t *
 Parrot_dlfunc_p_p_s_s(opcode_t *cur_opcode, PARROT_INTERP)  {
     const Parrot_Context * const CUR_CTX = Parrot_pcc_get_context_struct(interp, interp->ctx);
-    char * const  name      = Parrot_str_to_cstring(interp, (SREG(3)));
     void         *dl_handle = NULL;
     void         *ptr       = NULL;
     funcptr_t     p;
@@ -15137,27 +15136,25 @@
         dl_handle = ((Parrot_ParrotLibrary_attributes*)PMC_data(PREG(2)))->dl_handle;
     }
 
-    ptr = Parrot_dlsym(dl_handle, name);
+    ptr = Parrot_dlsym_str(interp, dl_handle, SREG(3));
     p = D2FPTR(ptr);
 
     if (p == NULLfunc) {
         const char * err = Parrot_dlerror();
         Parrot_warn(interp, PARROT_WARNINGS_UNDEF_FLAG,
-                "Symbol '%s' not found: %s\n", name, err ? err : "unknown reason");
+                "Symbol '%Ss' not found: %s\n", SREG(3), err ? err : "unknown reason");
         PREG(1) = Parrot_pmc_new(interp, enum_class_Undef);
     }
     else {
         PREG(1) = Parrot_pmc_new(interp, enum_class_NCI);
         VTABLE_set_pointer_keyed_str(interp, PREG(1), SREG(4), F2DPTR(p));
     }
-    Parrot_str_free_cstring(name);
 
 return (opcode_t *)cur_opcode + 5;}
 
 opcode_t *
 Parrot_dlfunc_p_p_sc_s(opcode_t *cur_opcode, PARROT_INTERP)  {
     const Parrot_Context * const CUR_CTX = Parrot_pcc_get_context_struct(interp, interp->ctx);
-    char * const  name      = Parrot_str_to_cstring(interp, (CONST(3)->u.string));
     void         *dl_handle = NULL;
     void         *ptr       = NULL;
     funcptr_t     p;
@@ -15168,27 +15165,25 @@
         dl_handle = ((Parrot_ParrotLibrary_attributes*)PMC_data(PREG(2)))->dl_handle;
     }
 
-    ptr = Parrot_dlsym(dl_handle, name);
+    ptr = Parrot_dlsym_str(interp, dl_handle, CONST(3)->u.string);
     p = D2FPTR(ptr);
 
     if (p == NULLfunc) {
         const char * err = Parrot_dlerror();
         Parrot_warn(interp, PARROT_WARNINGS_UNDEF_FLAG,
-                "Symbol '%s' not found: %s\n", name, err ? err : "unknown reason");
+                "Symbol '%Ss' not found: %s\n", CONST(3)->u.string, err ? err : "unknown reason");
         PREG(1) = Parrot_pmc_new(interp, enum_class_Undef);
     }
     else {
         PREG(1) = Parrot_pmc_new(interp, enum_class_NCI);
         VTABLE_set_pointer_keyed_str(interp, PREG(1), SREG(4), F2DPTR(p));
     }
-    Parrot_str_free_cstring(name);
 
 return (opcode_t *)cur_opcode + 5;}
 
 opcode_t *
 Parrot_dlfunc_p_p_s_sc(opcode_t *cur_opcode, PARROT_INTERP)  {
     const Parrot_Context * const CUR_CTX = Parrot_pcc_get_context_struct(interp, interp->ctx);
-    char * const  name      = Parrot_str_to_cstring(interp, (SREG(3)));
     void         *dl_handle = NULL;
     void         *ptr       = NULL;
     funcptr_t     p;
@@ -15199,27 +15194,25 @@
         dl_handle = ((Parrot_ParrotLibrary_attributes*)PMC_data(PREG(2)))->dl_handle;
     }
 
-    ptr = Parrot_dlsym(dl_handle, name);
+    ptr = Parrot_dlsym_str(interp, dl_handle, SREG(3));
     p = D2FPTR(ptr);
 
     if (p == NULLfunc) {
         const char * err = Parrot_dlerror();
         Parrot_warn(interp, PARROT_WARNINGS_UNDEF_FLAG,
-                "Symbol '%s' not found: %s\n", name, err ? err : "unknown reason");
+                "Symbol '%Ss' not found: %s\n", SREG(3), err ? err : "unknown reason");
         PREG(1) = Parrot_pmc_new(interp, enum_class_Undef);
     }
     else {
         PREG(1) = Parrot_pmc_new(interp, enum_class_NCI);
         VTABLE_set_pointer_keyed_str(interp, PREG(1), CONST(4)->u.string, F2DPTR(p));
     }
-    Parrot_str_free_cstring(name);
 
 return (opcode_t *)cur_opcode + 5;}
 
 opcode_t *
 Parrot_dlfunc_p_p_sc_sc(opcode_t *cur_opcode, PARROT_INTERP)  {
     const Parrot_Context * const CUR_CTX = Parrot_pcc_get_context_struct(interp, interp->ctx);
-    char * const  name      = Parrot_str_to_cstring(interp, (CONST(3)->u.string));
     void         *dl_handle = NULL;
     void         *ptr       = NULL;
     funcptr_t     p;
@@ -15230,27 +15223,25 @@
         dl_handle = ((Parrot_ParrotLibrary_attributes*)PMC_data(PREG(2)))->dl_handle;
     }
 
-    ptr = Parrot_dlsym(dl_handle, name);
+    ptr = Parrot_dlsym_str(interp, dl_handle, CONST(3)->u.string);
     p = D2FPTR(ptr);
 
     if (p == NULLfunc) {
         const char * err = Parrot_dlerror();
         Parrot_warn(interp, PARROT_WARNINGS_UNDEF_FLAG,
-                "Symbol '%s' not found: %s\n", name, err ? err : "unknown reason");
+                "Symbol '%Ss' not found: %s\n", CONST(3)->u.string, err ? err : "unknown reason");
         PREG(1) = Parrot_pmc_new(interp, enum_class_Undef);
     }
     else {
         PREG(1) = Parrot_pmc_new(interp, enum_class_NCI);
         VTABLE_set_pointer_keyed_str(interp, PREG(1), CONST(4)->u.string, F2DPTR(p));
     }
-    Parrot_str_free_cstring(name);
 
 return (opcode_t *)cur_opcode + 5;}
 
 opcode_t *
 Parrot_dlvar_p_p_s(opcode_t *cur_opcode, PARROT_INTERP)  {
     const Parrot_Context * const CUR_CTX = Parrot_pcc_get_context_struct(interp, interp->ctx);
-    char * const  name      = Parrot_str_to_cstring(interp, (SREG(3)));
     void *        dl_handle = NULL;
     void *        p         = NULL;
 
@@ -15260,12 +15251,12 @@
         dl_handle = ((Parrot_ParrotLibrary_attributes*)PMC_data(PREG(2)))->dl_handle;
     }
 
-    p = Parrot_dlsym(dl_handle, name);
+    p = Parrot_dlsym_str(interp, dl_handle, SREG(3));
 
     if (p == NULL) {
         const char * const err = Parrot_dlerror();
         Parrot_warn(interp, PARROT_WARNINGS_UNDEF_FLAG,
-                "Symbol '%s' not found: %s\n", name, err ? err : "unknown reason");
+                "Symbol '%Ss' not found: %s\n", SREG(3), err ? err : "unknown reason");
         PREG(1) = Parrot_pmc_new(interp, enum_class_Undef);
     }
     else {
@@ -15274,14 +15265,12 @@
         PREG(1) = Parrot_pmc_new(interp, enum_class_UnManagedStruct);
         VTABLE_set_pointer(interp, PREG(1), p);
     }
-    Parrot_str_free_cstring(name);
 
 return (opcode_t *)cur_opcode + 4;}
 
 opcode_t *
 Parrot_dlvar_p_p_sc(opcode_t *cur_opcode, PARROT_INTERP)  {
     const Parrot_Context * const CUR_CTX = Parrot_pcc_get_context_struct(interp, interp->ctx);
-    char * const  name      = Parrot_str_to_cstring(interp, (CONST(3)->u.string));
     void *        dl_handle = NULL;
     void *        p         = NULL;
 
@@ -15291,12 +15280,12 @@
         dl_handle = ((Parrot_ParrotLibrary_attributes*)PMC_data(PREG(2)))->dl_handle;
     }
 
-    p = Parrot_dlsym(dl_handle, name);
+    p = Parrot_dlsym_str(interp, dl_handle, CONST(3)->u.string);
 
     if (p == NULL) {
         const char * const err = Parrot_dlerror();
         Parrot_warn(interp, PARROT_WARNINGS_UNDEF_FLAG,
-                "Symbol '%s' not found: %s\n", name, err ? err : "unknown reason");
+                "Symbol '%Ss' not found: %s\n", CONST(3)->u.string, err ? err : "unknown reason");
         PREG(1) = Parrot_pmc_new(interp, enum_class_Undef);
     }
     else {
@@ -15305,7 +15294,6 @@
         PREG(1) = Parrot_pmc_new(interp, enum_class_UnManagedStruct);
         VTABLE_set_pointer(interp, PREG(1), p);
     }
-    Parrot_str_free_cstring(name);
 
 return (opcode_t *)cur_opcode + 4;}
 


More information about the parrot-commits mailing list