[svn:parrot] r41602 - in trunk: config/gen/platform config/gen/platform/generic src src/interp src/pmc src/runcore

bacek at svn.parrot.org bacek at svn.parrot.org
Thu Oct 1 22:53:12 UTC 2009


Author: bacek
Date: Thu Oct  1 22:53:09 2009
New Revision: 41602
URL: https://trac.parrot.org/parrot/changeset/41602

Log:
[cage] Change Parrot_*env functions to accept STRING*

Modified:
   trunk/config/gen/platform/generic/env.c
   trunk/config/gen/platform/platform_interface.h
   trunk/src/interp/inter_create.c
   trunk/src/library.c
   trunk/src/pmc/env.pmc
   trunk/src/runcore/profiling.c

Modified: trunk/config/gen/platform/generic/env.c
==============================================================================
--- trunk/config/gen/platform/generic/env.c	Thu Oct  1 22:24:19 2009	(r41601)
+++ trunk/config/gen/platform/generic/env.c	Thu Oct  1 22:53:09 2009	(r41602)
@@ -33,8 +33,10 @@
 */
 
 void
-Parrot_setenv(const char *name, const char *value)
+Parrot_setenv(PARROT_INTERP, STRING *str_name, STRING *str_value)
 {
+    char *name  = Parrot_str_to_cstring(interp, str_name);
+    char *value = Parrot_str_to_cstring(interp, str_value);
 #ifdef PARROT_HAS_SETENV
     setenv(name, value, 1);
 #else
@@ -55,6 +57,8 @@
 
     /* The buffer is intentionally not freed! */
 #endif
+    Parrot_str_free_cstring(name);
+    Parrot_str_free_cstring(value);
 }
 
 /*
@@ -66,13 +70,15 @@
 */
 
 void
-Parrot_unsetenv(const char *name)
+Parrot_unsetenv(PARROT_INTERP, STRING *str_name)
 {
+    char *name = Parrot_str_to_cstring(interp, str_name);
 #ifdef PARROT_HAS_UNSETENV
     unsetenv(name);
 #else
     Parrot_setenv(name, "");
 #endif
+    Parrot_str_free_cstring(name);
 }
 
 /*
@@ -84,10 +90,12 @@
 */
 
 char *
-Parrot_getenv(const char *name, int *free_it)
+Parrot_getenv(PARROT_INTERP, STRING *str_name)
 {
-    *free_it = 0;
-    return getenv(name);
+    char *name  = Parrot_str_to_cstring(interp, str_name);
+    char *value = getenv(name);
+    Parrot_str_free_cstring(name);
+    return value;
 }
 
 /*

Modified: trunk/config/gen/platform/platform_interface.h
==============================================================================
--- trunk/config/gen/platform/platform_interface.h	Thu Oct  1 22:24:19 2009	(r41601)
+++ trunk/config/gen/platform/platform_interface.h	Thu Oct  1 22:53:09 2009	(r41602)
@@ -9,6 +9,7 @@
 ** platform_interface.h
 */
 #include "parrot/config.h"
+#include "parrot/interpreter.h"
 
 /*
 ** I/O:
@@ -84,11 +85,9 @@
  * Env
  */
 
-void Parrot_setenv(const char *name, const char *value);
-void Parrot_unsetenv(const char *name);
-/* free_it is set by the function to either 0 or 1; if set to 1,
-   the return value of the function needs to be mem_sys_free()d after use */
-char * Parrot_getenv(const char *name, int *free_it);
+void Parrot_setenv(PARROT_INTERP, STRING *name, STRING *value);
+void Parrot_unsetenv(PARROT_INTERP, STRING *name);
+char * Parrot_getenv(PARROT_INTERP, STRING *name);
 
 /*
 ** Dynamic Loading:

Modified: trunk/src/interp/inter_create.c
==============================================================================
--- trunk/src/interp/inter_create.c	Thu Oct  1 22:24:19 2009	(r41601)
+++ trunk/src/interp/inter_create.c	Thu Oct  1 22:53:09 2009	(r41602)
@@ -31,14 +31,16 @@
 /* Don't modify between HEADERIZER BEGIN / HEADERIZER END.  Your changes will be lost. */
 
 PARROT_WARN_UNUSED_RESULT
-static int is_env_var_set(ARGIN(const char* var))
-        __attribute__nonnull__(1);
+static int is_env_var_set(PARROT_INTERP, ARGIN(STRING* var))
+        __attribute__nonnull__(1)
+        __attribute__nonnull__(2);
 
 static void setup_default_compreg(PARROT_INTERP)
         __attribute__nonnull__(1);
 
 #define ASSERT_ARGS_is_env_var_set __attribute__unused__ int _ASSERT_ARGS_CHECK = (\
-       PARROT_ASSERT_ARG(var))
+       PARROT_ASSERT_ARG(interp) \
+    , PARROT_ASSERT_ARG(var))
 #define ASSERT_ARGS_setup_default_compreg __attribute__unused__ int _ASSERT_ARGS_CHECK = (\
        PARROT_ASSERT_ARG(interp))
 /* Don't modify between HEADERIZER BEGIN / HEADERIZER END.  Your changes will be lost. */
@@ -48,7 +50,7 @@
 
 /*
 
-=item C<static int is_env_var_set(const char* var)>
+=item C<static int is_env_var_set(PARROT_INTERP, STRING* var)>
 
 Checks whether the specified environment variable is set.
 
@@ -58,11 +60,11 @@
 
 PARROT_WARN_UNUSED_RESULT
 static int
-is_env_var_set(ARGIN(const char* var))
+is_env_var_set(PARROT_INTERP, ARGIN(STRING* var))
 {
     ASSERT_ARGS(is_env_var_set)
     int free_it, retval;
-    char* const value = Parrot_getenv(var, &free_it);
+    char* const value = Parrot_getenv(interp, var);
     if (value == NULL)
         retval = 0;
     else if (*value == '\0')
@@ -148,7 +150,13 @@
     interp->piodata = NULL;
     Parrot_io_init(interp);
 
-    if (is_env_var_set("PARROT_GC_DEBUG")) {
+    /*
+     * Set up the string subsystem
+     * This also generates the constant string tables
+     */
+    Parrot_str_init(interp);
+
+    if (is_env_var_set(interp, CONST_STRING(interp, "PARROT_GC_DEBUG"))) {
 #if ! DISABLE_GC_DEBUG
         Interp_flags_SET(interp, PARROT_GC_DEBUG_FLAG);
 #else
@@ -157,12 +165,6 @@
 #endif
     }
 
-    /*
-     * Set up the string subsystem
-     * This also generates the constant string tables
-     */
-    Parrot_str_init(interp);
-
     Parrot_initialize_core_vtables(interp);
 
     /* Set up MMD; MMD cache for builtins. */

Modified: trunk/src/library.c
==============================================================================
--- trunk/src/library.c	Thu Oct  1 22:24:19 2009	(r41601)
+++ trunk/src/library.c	Thu Oct  1 22:53:09 2009	(r41602)
@@ -779,7 +779,7 @@
 {
     ASSERT_ARGS(Parrot_get_runtime_prefix)
     int     free_it;
-    char * const env = Parrot_getenv("PARROT_RUNTIME", &free_it);
+    char * const env = Parrot_getenv(interp, CONST_STRING(interp, "PARROT_RUNTIME"));
 
     if (env)
         return free_it ? env : mem_sys_strdup(env);
@@ -814,7 +814,7 @@
 {
     ASSERT_ARGS(Parrot_get_runtime_path)
     int     free_it;
-    char * const env = Parrot_getenv("PARROT_RUNTIME", &free_it);
+    char * const env = Parrot_getenv(interp, CONST_STRING(interp, "PARROT_RUNTIME"));
     STRING *result;
 
     if (env)

Modified: trunk/src/pmc/env.pmc
==============================================================================
--- trunk/src/pmc/env.pmc	Thu Oct  1 22:24:19 2009	(r41601)
+++ trunk/src/pmc/env.pmc	Thu Oct  1 22:53:09 2009	(r41602)
@@ -148,21 +148,12 @@
 */
 
     VTABLE STRING *get_string_keyed_str(STRING *key) {
-        char * const keyname = Parrot_str_to_cstring(interp, key);
-
-        if (keyname) {
-            int free_it = 0;
-            char * const val = Parrot_getenv(keyname, &free_it);
-            Parrot_str_free_cstring(keyname);
+        if (!STRING_IS_EMPTY(key)) {
+            char * const val = Parrot_getenv(interp, key);
 
             if (val) {
                 STRING * const retval = Parrot_str_new(interp, val, 0);
-
-                if (free_it)
-                    mem_sys_free(val);
-
                 return retval;
-
             }
         }
 
@@ -207,22 +198,17 @@
 */
 
     VTABLE PMC *get_pmc_keyed(PMC *key) {
-        char * const keyname = Parrot_str_to_cstring(INTERP,
-            VTABLE_get_string(INTERP, key));
+        STRING *keyname = VTABLE_get_string(INTERP, key);
 
         char   *val     = NULL;
         STRING *retval  = NULL;
         PMC    *return_pmc;
 
-        if (keyname) {
-            int free_it = 0;
-            val         = Parrot_getenv(keyname, &free_it);
-            Parrot_str_free_cstring(keyname);
+        if (!STRING_IS_EMPTY(keyname)) {
+            val         = Parrot_getenv(INTERP, keyname);
 
             if (val) {
                 retval = Parrot_str_new(INTERP, val, 0);
-                if (free_it)
-                    mem_sys_free(val);
             }
         }
 
@@ -246,18 +232,10 @@
 */
 
     VTABLE void set_string_keyed(PMC *key, STRING *value) {
-        char * const keyname = Parrot_str_to_cstring(INTERP,
-            VTABLE_get_string(INTERP, key));
-        char * const env_val = Parrot_str_to_cstring(INTERP, value);
-
-        if (keyname && env_val)
-            Parrot_setenv(keyname, env_val);
-
-        if (keyname)
-            Parrot_str_free_cstring(keyname);
+        STRING *keyname = VTABLE_get_string(INTERP, key);
 
-        if (env_val)
-            Parrot_str_free_cstring(env_val);
+        if (keyname && value)
+            Parrot_setenv(INTERP, keyname, value);
     }
 
 /*
@@ -271,20 +249,11 @@
 */
 
     VTABLE void set_pmc_keyed(PMC *key, PMC *value) {
-        char * const keyname = Parrot_str_to_cstring(INTERP,
-            VTABLE_get_string(INTERP, key));
+        STRING * keyname   = VTABLE_get_string(INTERP, key);
+        STRING * str_value = VTABLE_get_string(INTERP, value);
 
-        const STRING * const str_value = VTABLE_get_string(INTERP, value);
-        char         * const env_val   = Parrot_str_to_cstring(INTERP, str_value);
-
-        if (keyname && env_val)
-            Parrot_setenv(keyname, env_val);
-
-        if (keyname)
-            Parrot_str_free_cstring(keyname);
-
-        if (env_val)
-            Parrot_str_free_cstring(env_val);
+        if (keyname && str_value)
+            Parrot_setenv(INTERP, keyname, str_value);
     }
 
 /*
@@ -297,18 +266,13 @@
 
 */
 
-    VTABLE INTVAL exists_keyed(PMC *key) {
-        char * const keyname = Parrot_str_to_cstring(INTERP,
-            VTABLE_get_string(INTERP, key));
-
-        if (keyname) {
-            int free_it;
-            char * const val = Parrot_getenv(keyname, &free_it);
-            Parrot_str_free_cstring(keyname);
+    VTABLE INTVAL exists_keyed(PMC *pmckey) {
+        STRING *keyname = VTABLE_get_string(INTERP, pmckey);
+
+        if (!STRING_IS_EMPTY(keyname)) {
+            char * const val = Parrot_getenv(interp, keyname);
 
             if (val) {
-                if (free_it)
-                    mem_sys_free(val);
                 return 1;
             }
         }
@@ -327,21 +291,14 @@
 */
 
     VTABLE void delete_keyed(PMC *key) {
-        char * const keyname = Parrot_str_to_cstring(INTERP,
-            VTABLE_get_string(INTERP, key));
+        STRING *keyname = VTABLE_get_string(INTERP, key);
 
-        if (keyname) {
-            int          free_it;
-            char * const val = Parrot_getenv(keyname, &free_it);
+        if (!STRING_IS_EMPTY(keyname)) {
+            char * const val = Parrot_getenv(INTERP, keyname);
 
             if (val) {
-                if (free_it)
-                    mem_sys_free(val);
-
-                Parrot_unsetenv(keyname);
+                Parrot_unsetenv(INTERP, keyname);
             }
-
-            Parrot_str_free_cstring(keyname);
         }
     }
 }

Modified: trunk/src/runcore/profiling.c
==============================================================================
--- trunk/src/runcore/profiling.c	Thu Oct  1 22:24:19 2009	(r41601)
+++ trunk/src/runcore/profiling.c	Thu Oct  1 22:53:09 2009	(r41602)
@@ -110,9 +110,8 @@
     ASSERT_ARGS(init_profiling_core)
 
     char *profile_filename, *profile_output_var;
-    int free_env_var;
 
-    profile_output_var = Parrot_getenv("PARROT_PROFILING_OUTPUT", &free_env_var);
+    profile_output_var = Parrot_getenv(interp, CONST_STRING(interp, "PARROT_PROFILING_OUTPUT"));
 
     if (profile_output_var) {
         STRING  *lc_filename;
@@ -130,9 +129,6 @@
         }
         else
             runcore->profile_fd = fopen(profile_filename, "w");
-
-        if (free_env_var)
-            mem_sys_free(profile_output_var);
     }
     else {
         runcore->profile_filename = Parrot_sprintf_c(interp, "parrot.pprof.%d", getpid());


More information about the parrot-commits mailing list