[svn:parrot] r43080 - in trunk: config/gen/platform/generic src src/interp src/io src/pmc
cotto at svn.parrot.org
cotto at svn.parrot.org
Wed Dec 16 03:37:52 UTC 2009
Author: cotto
Date: Wed Dec 16 03:37:48 2009
New Revision: 43080
URL: https://trac.parrot.org/parrot/changeset/43080
Log:
[misc] consting and various cleanups as part of TT #886, courtesy of JimmyZ++
Modified:
trunk/config/gen/platform/generic/exec.c
trunk/src/debug.c
trunk/src/dynext.c
trunk/src/interp/inter_misc.c
trunk/src/io/unix.c
trunk/src/pmc/os.pmc
trunk/src/pmc/string.pmc
Modified: trunk/config/gen/platform/generic/exec.c
==============================================================================
--- trunk/config/gen/platform/generic/exec.c Wed Dec 16 03:10:19 2009 (r43079)
+++ trunk/config/gen/platform/generic/exec.c Wed Dec 16 03:37:48 2009 (r43080)
@@ -54,11 +54,11 @@
}
else {
/* child */
- char *cmd = Parrot_str_to_cstring(interp, command);
- int status = execlp("sh", "sh", "-c", cmd, (void *)NULL);
+ char * const cmd = Parrot_str_to_cstring(interp, command);
+ int status = execlp("sh", "sh", "-c", cmd, (void *)NULL);
/* if we get here, something's horribly wrong, but free anyway... */
- mem_sys_free(cmd);
+ Parrot_str_free_cstring(cmd);
if (status)
exit(status);
@@ -96,8 +96,7 @@
if (child) {
/* parent */
int status;
- pid_t returnstat;
- returnstat = waitpid(child, &status, 0);
+ pid_t returnstat = waitpid(child, &status, 0);
UNUSED(returnstat);
return status;
}
@@ -105,19 +104,18 @@
/* child. Be horribly profligate with memory, since we're
about to be something else */
int status, i;
- char **argv;
STRING *s;
- char *cmd;
+ char *cmd;
+ char **argv = mem_allocate_n_typed((len+1)*sizeof (char *), char**);
- argv = (char **)mem_sys_allocate((len+1)*sizeof (char *));
for (i = 0; i < len; ++i) {
s = VTABLE_get_string_keyed_int(interp, cmdargs, i);
argv[i] = Parrot_str_to_cstring(interp, s);
}
- cmd = argv[0];
- argv[i] = NULL;
- status = execvp(cmd, argv);
+ cmd = argv[0];
+ argv[i] = NULL;
+ status = execvp(cmd, argv);
/* if we get here, something's horribly wrong... */
if (status) {
exit(status);
Modified: trunk/src/debug.c
==============================================================================
--- trunk/src/debug.c Wed Dec 16 03:10:19 2009 (r43079)
+++ trunk/src/debug.c Wed Dec 16 03:37:48 2009 (r43080)
@@ -1274,7 +1274,7 @@
tmp_stdin, readline,
"S->S", prompt, & s);
{
- char * aux = Parrot_str_to_cstring(interpdeb, s);
+ char * const aux = Parrot_str_to_cstring(interpdeb, s);
strcpy(c, aux);
Parrot_str_free_cstring(aux);
}
Modified: trunk/src/dynext.c
==============================================================================
--- trunk/src/dynext.c Wed Dec 16 03:10:19 2009 (r43079)
+++ trunk/src/dynext.c Wed Dec 16 03:37:48 2009 (r43080)
@@ -233,8 +233,8 @@
{
ASSERT_ARGS(dlopen_string)
- char *pathstr = Parrot_str_to_cstring(interp, path);
- void *handle = Parrot_dlopen(pathstr);
+ char * const pathstr = Parrot_str_to_cstring(interp, path);
+ void * handle = Parrot_dlopen(pathstr);
Parrot_str_free_cstring(pathstr);
return handle;
}
Modified: trunk/src/interp/inter_misc.c
==============================================================================
--- trunk/src/interp/inter_misc.c Wed Dec 16 03:10:19 2009 (r43079)
+++ trunk/src/interp/inter_misc.c Wed Dec 16 03:37:48 2009 (r43080)
@@ -341,9 +341,9 @@
else {
/* Need to strip back to what follows the final / or \. */
- STRING *fullname = VTABLE_get_string(interp, exe_name);
- char *fullname_c = Parrot_str_to_cstring(interp, fullname);
- int pos = strlen(fullname_c) - 1;
+ STRING * fullname = VTABLE_get_string(interp, exe_name);
+ char * const fullname_c = Parrot_str_to_cstring(interp, fullname);
+ int pos = strlen(fullname_c) - 1;
while (pos > 0
&& fullname_c[pos] != '/'
@@ -354,7 +354,7 @@
pos++;
basename = Parrot_str_new(interp, fullname_c + pos, 0);
- mem_sys_free(fullname_c);
+ Parrot_str_free_cstring(fullname_c);
return basename;
}
Modified: trunk/src/io/unix.c
==============================================================================
--- trunk/src/io/unix.c Wed Dec 16 03:10:19 2009 (r43079)
+++ trunk/src/io/unix.c Wed Dec 16 03:37:48 2009 (r43080)
@@ -764,7 +764,7 @@
}
# else
- UNUSED(l);
+ UNUSED(filehandle);
UNUSED(command);
UNUSED(flags);
Parrot_ex_throw_from_c_args(interp, NULL, EXCEPTION_UNIMPLEMENTED,
Modified: trunk/src/pmc/os.pmc
==============================================================================
--- trunk/src/pmc/os.pmc Wed Dec 16 03:10:19 2009 (r43079)
+++ trunk/src/pmc/os.pmc Wed Dec 16 03:37:48 2009 (r43080)
@@ -476,11 +476,11 @@
*/
METHOD readdir(STRING *path) {
#ifndef _MSC_VER
+ char * const cpath = Parrot_str_to_cstring(interp, path);
+ DIR *dir = opendir(cpath);
struct dirent *dirent;
PMC *array;
- char *cpath = Parrot_str_to_cstring(interp, path);
STRING *retval;
- DIR *dir = opendir(cpath);
Parrot_str_free_cstring(cpath);
Modified: trunk/src/pmc/string.pmc
==============================================================================
--- trunk/src/pmc/string.pmc Wed Dec 16 03:10:19 2009 (r43079)
+++ trunk/src/pmc/string.pmc Wed Dec 16 03:37:48 2009 (r43080)
@@ -52,6 +52,10 @@
VTABLE void mark() {
STRING *str_val;
+
+ if (!PMC_data(SELF))
+ return;
+
GET_ATTR_str_val(INTERP, SELF, str_val);
Parrot_gc_mark_STRING_alive(INTERP, str_val);
}
@@ -202,8 +206,8 @@
/* Only allow constant PMCs to embed constant strings */
if (PObj_constant_TEST(SELF) && !PObj_constant_TEST(value)) {
- char *copy = Parrot_str_to_cstring(INTERP, value);
- value = Parrot_str_new_init(INTERP, copy, strlen(copy),
+ char * const copy = Parrot_str_to_cstring(INTERP, value);
+ value = Parrot_str_new_init(INTERP, copy, strlen(copy),
PARROT_DEFAULT_ENCODING, PARROT_DEFAULT_CHARSET,
PObj_constant_FLAG);
Parrot_str_free_cstring(copy);
More information about the parrot-commits
mailing list