Index: config/gen/platform/generic/exec.c =================================================================== --- config/gen/platform/generic/exec.c (版本 42299) +++ config/gen/platform/generic/exec.c (工作副本) @@ -55,11 +55,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); @@ -97,8 +97,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; } @@ -106,17 +105,16 @@ /* 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 = (char **)mem_sys_allocate((len+1)*sizeof (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); /* if we get here, something's horribly wrong... */ @@ -140,8 +138,8 @@ { /* Be horribly profligate with memory, since we're about to be something else */ - 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... */ if (status) Index: config/gen/platform/win32/exec.c =================================================================== --- config/gen/platform/win32/exec.c (版本 42300) +++ config/gen/platform/win32/exec.c (工作副本) @@ -41,10 +41,10 @@ DWORD status = 0; STARTUPINFO si; PROCESS_INFORMATION pi; - int free_it = 0; - char* cmd = (char *)mem_sys_allocate(command->strlen + 4); - char* shell = Parrot_getenv(interp, Parrot_str_new(interp, "ComSpec", strlen("ComSpec"))); - char* cmdin = Parrot_str_to_cstring(interp, command); + int free_it = 0; + char* cmd = (char *)mem_sys_allocate(command->strlen + 4); + char* shell = Parrot_getenv(interp, Parrot_str_new(interp, "ComSpec", strlen("ComSpec"))); + char* const cmdin = Parrot_str_to_cstring(interp, command); strcpy(cmd, "/c "); strcat(cmd, cmdin); @@ -95,11 +95,10 @@ DWORD status = 0; STARTUPINFO si; PROCESS_INFORMATION pi; - int pmclen; - int cmdlinelen = 1000; - int cmdlinepos = 0; - char *cmdline = (char *)mem_sys_allocate(cmdlinelen); - int i; + int pmclen, i; + int cmdlinelen = 1000; + int cmdlinepos = 0; + char *cmdline = (char *)mem_sys_allocate(cmdlinelen); /* Ensure there's something in the PMC array. */ pmclen = VTABLE_elements(interp, cmdargs); @@ -109,8 +108,8 @@ /* Now build command line. */ for (i = 0; i < pmclen; i++) { - STRING *s = VTABLE_get_string_keyed_int(interp, cmdargs, i); - char *cs = Parrot_str_to_cstring(interp, s); + STRING *s = VTABLE_get_string_keyed_int(interp, cmdargs, i); + char * const cs = Parrot_str_to_cstring(interp, s); if (cmdlinepos + (int)s->strlen + 3 > cmdlinelen) { cmdlinelen += s->strlen + 4; cmdline = (char *)mem_sys_realloc(cmdline, cmdlinelen); @@ -162,8 +161,8 @@ Parrot_Exec_OS_Command(PARROT_INTERP, STRING *command) { int status; - char *in = Parrot_str_to_cstring(interp, command); - char *cmd = NULL; + char * const in = Parrot_str_to_cstring(interp, command); + char * cmd = NULL; const char **argv = (const char **)mem_sys_allocate_zeroed(2 * sizeof (int)); /* Grab string, extract command and parameters. */ @@ -223,6 +222,8 @@ curPos ++; } + Parrot_str_free_cstring(in); + /* If we still have a seek char, then the input was improper. */ if (seekChar) Parrot_ex_throw_from_c_args(interp, NULL, EXCEPTION_NOSPAWN, Index: src/debug.c =================================================================== --- src/debug.c (版本 42299) +++ src/debug.c (工作副本) @@ -1277,7 +1277,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); } Index: src/dynext.c =================================================================== --- src/dynext.c (版本 42299) +++ src/dynext.c (工作副本) @@ -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; } Index: src/interp/inter_misc.c =================================================================== --- src/interp/inter_misc.c (版本 42299) +++ src/interp/inter_misc.c (工作副本) @@ -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; } Index: src/io/socket_win32.c =================================================================== --- src/io/socket_win32.c (版本 42299) +++ src/io/socket_win32.c (工作副本) @@ -443,10 +443,8 @@ Parrot_io_sockaddr_in(PARROT_INTERP, ARGIN(STRING *addr), INTVAL port) { ASSERT_ARGS(Parrot_io_sockaddr_in) - PMC * sockaddr; - char * s; - - s = Parrot_str_to_cstring(interp, addr); + PMC * sockaddr; + char * const s = Parrot_str_to_cstring(interp, addr); sockaddr = pmc_new(interp, enum_class_Sockaddr); get_sockaddr_in(interp, sockaddr, s, port); Parrot_str_free_cstring(s); Index: src/io/unix.c =================================================================== --- src/io/unix.c (版本 42299) +++ src/io/unix.c (工作副本) @@ -756,7 +756,7 @@ } # else - UNUSED(l); + UNUSED(filehandle); UNUSED(command); UNUSED(flags); Parrot_ex_throw_from_c_args(interp, NULL, EXCEPTION_UNIMPLEMENTED, Index: src/io/win32.c =================================================================== --- src/io/win32.c (版本 42299) +++ src/io/win32.c (工作副本) @@ -693,8 +693,6 @@ NULL, NULL, TRUE, 0, NULL, NULL, &start, &procinfo) == 0) goto fail; - Parrot_str_free_cstring(cmd); - cmd = NULL; if (f_read) { Parrot_io_set_os_handle(interp, io, hread); CloseHandle(hwrite); @@ -703,6 +701,8 @@ Parrot_io_set_os_handle(interp, io, hwrite); CloseHandle(hread); } + + Parrot_str_free_cstring(cmd); CloseHandle(procinfo.hThread); VTABLE_set_integer_keyed_int(interp, io, 0, (INTVAL)procinfo.hProcess); return io; Index: src/pmc/codestring.pmc =================================================================== --- src/pmc/codestring.pmc (版本 42299) +++ src/pmc/codestring.pmc (工作副本) @@ -278,14 +278,16 @@ METHOD charname_to_ord(STRING *name) { #if PARROT_HAS_ICU - UChar32 codepoint; - UErrorCode err = U_ZERO_ERROR; - char *cstr = Parrot_str_to_cstring(INTERP, name); - codepoint = u_charFromName(U_EXTENDED_CHAR_NAME, cstr, &err); + UErrorCode err = U_ZERO_ERROR; + char * const cstr = Parrot_str_to_cstring(INTERP, name); + UChar32 codepoint = u_charFromName(U_EXTENDED_CHAR_NAME, cstr, &err); + Parrot_str_free_cstring(cstr); + if (U_SUCCESS(err)) { RETURN(INTVAL codepoint); } + RETURN(INTVAL -1); #else Parrot_ex_throw_from_c_args(interp, NULL, EXCEPTION_LIBRARY_ERROR, Index: src/pmc/os.pmc =================================================================== --- src/pmc/os.pmc (版本 42299) +++ src/pmc/os.pmc (工作副本) @@ -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); Index: src/pmc/string.pmc =================================================================== --- src/pmc/string.pmc (版本 42299) +++ src/pmc/string.pmc (工作副本) @@ -202,8 +202,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);