Ticket #886: cage.3.patch

File cage.3.patch, 10.5 KB (added by jimmy, 12 years ago)

new patch

  • config/gen/platform/generic/exec.c

     
    5555    } 
    5656    else { 
    5757        /* child */ 
    58         char *cmd    = Parrot_str_to_cstring(interp, command); 
    59         int   status = execlp("sh", "sh", "-c", cmd, (void *)NULL); 
     58        char * const cmd    = Parrot_str_to_cstring(interp, command); 
     59        int          status = execlp("sh", "sh", "-c", cmd, (void *)NULL); 
    6060 
    6161        /* if we get here, something's horribly wrong, but free anyway... */ 
    62         mem_sys_free(cmd); 
     62        Parrot_str_free_cstring(cmd); 
    6363 
    6464        if (status) 
    6565            exit(status); 
     
    9797    if (child) { 
    9898        /* parent */ 
    9999        int status; 
    100         pid_t returnstat; 
    101         returnstat = waitpid(child, &status, 0); 
     100        pid_t returnstat = waitpid(child, &status, 0); 
    102101        UNUSED(returnstat); 
    103102        return status; 
    104103    } 
     
    106105        /* child. Be horribly profligate with memory, since we're 
    107106           about to be something else */ 
    108107        int status, i; 
    109         char **argv; 
    110108        STRING *s; 
    111         char *cmd; 
     109        char   *cmd; 
     110        char  **argv = (char **)mem_sys_allocate((len+1)*sizeof (char *)); 
    112111 
    113         argv = (char **)mem_sys_allocate((len+1)*sizeof (char *)); 
    114112        for (i = 0; i < len; ++i) { 
    115113            s = VTABLE_get_string_keyed_int(interp, cmdargs, i); 
    116114            argv[i] = Parrot_str_to_cstring(interp, s); 
    117115        } 
     116 
    118117        cmd = argv[0]; 
    119         argv[i] = NULL; 
    120118 
    121119        status = execvp(cmd, argv); 
    122120        /* if we get here, something's horribly wrong... */ 
     
    140138{ 
    141139    /* Be horribly profligate with memory, since we're 
    142140       about to be something else */ 
    143     char *cmd  = Parrot_str_to_cstring(interp, command); 
    144     int status = execlp("sh", "sh", "-c", cmd, (void *)NULL); 
     141    char * const cmd    = Parrot_str_to_cstring(interp, command); 
     142    int          status = execlp("sh", "sh", "-c", cmd, (void *)NULL); 
    145143 
    146144    /* if we get here, something's horribly wrong... */ 
    147145    if (status) 
  • config/gen/platform/win32/exec.c

     
    4141    DWORD status = 0; 
    4242    STARTUPINFO si; 
    4343    PROCESS_INFORMATION pi; 
    44     int free_it = 0; 
    45     char* cmd = (char *)mem_sys_allocate(command->strlen + 4); 
    46     char* shell = Parrot_getenv(interp, Parrot_str_new(interp, "ComSpec", strlen("ComSpec"))); 
    47     char* cmdin = Parrot_str_to_cstring(interp, command); 
     44    int         free_it = 0; 
     45    char*       cmd    = (char *)mem_sys_allocate(command->strlen + 4); 
     46    char*       shell  = Parrot_getenv(interp, Parrot_str_new(interp, "ComSpec", strlen("ComSpec"))); 
     47    char* const cmdin  = Parrot_str_to_cstring(interp, command); 
    4848 
    4949    strcpy(cmd, "/c "); 
    5050    strcat(cmd, cmdin); 
     
    9595    DWORD status = 0; 
    9696    STARTUPINFO si; 
    9797    PROCESS_INFORMATION pi; 
    98     int pmclen; 
    99     int cmdlinelen = 1000; 
    100     int cmdlinepos = 0; 
    101     char *cmdline = (char *)mem_sys_allocate(cmdlinelen); 
    102     int i; 
     98    int   pmclen, i; 
     99    int   cmdlinelen = 1000; 
     100    int   cmdlinepos = 0; 
     101    char *cmdline    = (char *)mem_sys_allocate(cmdlinelen); 
    103102 
    104103    /* Ensure there's something in the PMC array. */ 
    105104    pmclen = VTABLE_elements(interp, cmdargs); 
     
    109108 
    110109    /* Now build command line. */ 
    111110    for (i = 0; i < pmclen; i++) { 
    112         STRING *s = VTABLE_get_string_keyed_int(interp, cmdargs, i); 
    113         char *cs = Parrot_str_to_cstring(interp, s); 
     111        STRING      *s = VTABLE_get_string_keyed_int(interp, cmdargs, i); 
     112        char * const cs = Parrot_str_to_cstring(interp, s); 
    114113        if (cmdlinepos + (int)s->strlen + 3 > cmdlinelen) { 
    115114            cmdlinelen += s->strlen + 4; 
    116115            cmdline = (char *)mem_sys_realloc(cmdline, cmdlinelen); 
     
    162161Parrot_Exec_OS_Command(PARROT_INTERP, STRING *command) 
    163162{ 
    164163    int status; 
    165     char *in = Parrot_str_to_cstring(interp, command); 
    166     char *cmd = NULL; 
     164    char * const in  = Parrot_str_to_cstring(interp, command); 
     165    char *       cmd = NULL; 
    167166    const char **argv = (const char **)mem_sys_allocate_zeroed(2 * sizeof (int)); 
    168167 
    169168    /* Grab string, extract command and parameters. */ 
     
    223222        curPos ++; 
    224223    } 
    225224 
     225    Parrot_str_free_cstring(in); 
     226 
    226227    /* If we still have a seek char, then the input was improper. */ 
    227228    if (seekChar) 
    228229        Parrot_ex_throw_from_c_args(interp, NULL, EXCEPTION_NOSPAWN, 
  • src/debug.c

     
    12771277            tmp_stdin, readline, 
    12781278            "S->S", prompt, & s); 
    12791279        { 
    1280         char * aux = Parrot_str_to_cstring(interpdeb, s); 
     1280        char * const aux = Parrot_str_to_cstring(interpdeb, s); 
    12811281        strcpy(c, aux); 
    12821282        Parrot_str_free_cstring(aux); 
    12831283        } 
  • src/dynext.c

     
    233233{ 
    234234    ASSERT_ARGS(dlopen_string) 
    235235 
    236     char *pathstr = Parrot_str_to_cstring(interp, path); 
    237     void *handle = Parrot_dlopen(pathstr); 
     236    char * const pathstr = Parrot_str_to_cstring(interp, path); 
     237    void *       handle = Parrot_dlopen(pathstr); 
    238238    Parrot_str_free_cstring(pathstr); 
    239239    return handle; 
    240240} 
  • src/interp/inter_misc.c

     
    341341 
    342342            else { 
    343343                /* Need to strip back to what follows the final / or \. */ 
    344                 STRING *fullname   = VTABLE_get_string(interp, exe_name); 
    345                 char   *fullname_c = Parrot_str_to_cstring(interp, fullname); 
    346                 int     pos        = strlen(fullname_c) - 1; 
     344                STRING *       fullname   = VTABLE_get_string(interp, exe_name); 
     345                char   * const fullname_c = Parrot_str_to_cstring(interp, fullname); 
     346                int            pos        = strlen(fullname_c) - 1; 
    347347 
    348348                while (pos              >  0 
    349349                &&     fullname_c[pos] != '/' 
     
    354354                    pos++; 
    355355 
    356356                basename = Parrot_str_new(interp, fullname_c + pos, 0); 
    357                 mem_sys_free(fullname_c); 
     357                Parrot_str_free_cstring(fullname_c); 
    358358 
    359359                return basename; 
    360360            } 
  • src/io/socket_win32.c

     
    443443Parrot_io_sockaddr_in(PARROT_INTERP, ARGIN(STRING *addr), INTVAL port) 
    444444{ 
    445445    ASSERT_ARGS(Parrot_io_sockaddr_in) 
    446     PMC * sockaddr; 
    447     char * s; 
    448  
    449     s = Parrot_str_to_cstring(interp, addr); 
     446    PMC  * sockaddr; 
     447    char * const s = Parrot_str_to_cstring(interp, addr); 
    450448    sockaddr = pmc_new(interp, enum_class_Sockaddr); 
    451449    get_sockaddr_in(interp, sockaddr, s, port); 
    452450    Parrot_str_free_cstring(s); 
  • src/io/unix.c

     
    756756    } 
    757757 
    758758#  else 
    759     UNUSED(l); 
     759    UNUSED(filehandle); 
    760760    UNUSED(command); 
    761761    UNUSED(flags); 
    762762    Parrot_ex_throw_from_c_args(interp, NULL, EXCEPTION_UNIMPLEMENTED, 
  • src/io/win32.c

     
    693693            NULL, NULL, TRUE, 0, 
    694694            NULL, NULL, &start, &procinfo) == 0) 
    695695        goto fail; 
    696     Parrot_str_free_cstring(cmd); 
    697     cmd = NULL; 
    698696    if (f_read) { 
    699697        Parrot_io_set_os_handle(interp, io, hread); 
    700698        CloseHandle(hwrite); 
     
    703701        Parrot_io_set_os_handle(interp, io, hwrite); 
    704702        CloseHandle(hread); 
    705703    } 
     704 
     705    Parrot_str_free_cstring(cmd);  
    706706    CloseHandle(procinfo.hThread); 
    707707    VTABLE_set_integer_keyed_int(interp, io, 0, (INTVAL)procinfo.hProcess); 
    708708    return io; 
  • src/pmc/codestring.pmc

     
    278278 
    279279  METHOD charname_to_ord(STRING *name) { 
    280280#if PARROT_HAS_ICU 
    281     UChar32    codepoint; 
    282     UErrorCode err       = U_ZERO_ERROR; 
    283     char       *cstr     = Parrot_str_to_cstring(INTERP, name); 
    284     codepoint = u_charFromName(U_EXTENDED_CHAR_NAME, cstr, &err); 
     281    UErrorCode         err       = U_ZERO_ERROR; 
     282    char       * const cstr      = Parrot_str_to_cstring(INTERP, name); 
     283    UChar32            codepoint = u_charFromName(U_EXTENDED_CHAR_NAME, cstr, &err); 
     284 
    285285    Parrot_str_free_cstring(cstr); 
     286 
    286287    if (U_SUCCESS(err)) { 
    287288        RETURN(INTVAL codepoint); 
    288289    } 
     290 
    289291    RETURN(INTVAL -1); 
    290292#else 
    291293    Parrot_ex_throw_from_c_args(interp, NULL, EXCEPTION_LIBRARY_ERROR, 
  • src/pmc/os.pmc

     
    476476*/ 
    477477    METHOD readdir(STRING *path) { 
    478478#ifndef _MSC_VER 
     479        char  * const cpath = Parrot_str_to_cstring(interp, path); 
     480        DIR           *dir  = opendir(cpath); 
    479481        struct dirent *dirent; 
    480482        PMC           *array; 
    481         char          *cpath = Parrot_str_to_cstring(interp, path); 
    482483        STRING        *retval; 
    483         DIR           *dir   = opendir(cpath); 
    484484 
    485485        Parrot_str_free_cstring(cpath); 
    486486 
  • src/pmc/string.pmc

     
    202202 
    203203        /* Only allow constant PMCs to embed constant strings */ 
    204204        if (PObj_constant_TEST(SELF) && !PObj_constant_TEST(value)) { 
    205             char *copy = Parrot_str_to_cstring(INTERP, value); 
    206             value      = Parrot_str_new_init(INTERP, copy, strlen(copy), 
     205            char * const copy = Parrot_str_to_cstring(INTERP, value); 
     206            value             = Parrot_str_new_init(INTERP, copy, strlen(copy), 
    207207                PARROT_DEFAULT_ENCODING, PARROT_DEFAULT_CHARSET, 
    208208                PObj_constant_FLAG); 
    209209            Parrot_str_free_cstring(copy);