Ticket #1083: managed_cstring.patch

File managed_cstring.patch, 13.0 KB (added by NotFound, 12 years ago)
  • src/ops/core.ops

     
    13221322} 
    13231323 
    13241324op dlfunc(out PMC, invar PMC, in STR, in STR) { 
    1325     char * const  name      = Parrot_str_to_cstring(interp, ($3)); 
     1325    PMC          *namebuf   = Parrot_str_to_cstring_managed(interp, ($3)); 
     1326    char * const  name      = (char *)VTABLE_get_pointer(interp, namebuf); 
    13261327    void         *dl_handle = NULL; 
    13271328    void         *ptr       = NULL; 
    13281329    funcptr_t     p; 
     
    13501351        VTABLE_set_pointer_keyed_str(interp, $1, $4, F2DPTR(p)); 
    13511352        PObj_get_FLAGS($1) |= PObj_private1_FLAG; 
    13521353    } 
    1353     Parrot_str_free_cstring(name); 
    13541354} 
    13551355 
    13561356op dlvar(out PMC, invar PMC, in STR) { 
    1357     char * const  name      = Parrot_str_to_cstring(interp, ($3)); 
     1357    PMC * const   name_buf  = Parrot_str_to_cstring_managed(interp, ($3)); 
     1358    char * const  name      = (char *)VTABLE_get_pointer(interp, name_buf); 
    13581359    void *        p         = NULL; 
    13591360    void         *dl_handle = NULL; 
    13601361 
     
    13741375        $1 = pmc_new(interp, enum_class_UnManagedStruct); 
    13751376        VTABLE_set_pointer(interp, $1, p); 
    13761377    } 
    1377     Parrot_str_free_cstring(name); 
    13781378} 
    13791379 
    13801380inline op compreg(in STR, invar PMC) { 
  • src/pmc/string.pmc

     
    224224 
    225225        /* Only allow constant PMCs to embed constant strings */ 
    226226        if (PObj_constant_TEST(SELF) && !PObj_constant_TEST(value)) { 
    227             char *copy = Parrot_str_to_cstring(INTERP, value); 
     227            PMC *copybuf = Parrot_str_to_cstring_managed(INTERP, value); 
     228            char *copy = (char *)VTABLE_get_pointer(interp, copybuf); 
    228229            value      = Parrot_str_new_init(INTERP, copy, strlen(copy), 
    229230                PARROT_DEFAULT_ENCODING, PARROT_DEFAULT_CHARSET, 
    230231                PObj_constant_FLAG); 
    231             Parrot_str_free_cstring(copy); 
    232232        } 
    233233 
    234234        SET_ATTR_str_val(INTERP, SELF, value); 
     
    716716                        enum_class_Integer)); 
    717717 
    718718        /* TODO verify encoding */ 
    719         const STRING *me  = VTABLE_get_string(INTERP, SELF); 
    720         char         *str = Parrot_str_to_cstring(INTERP, me); 
     719        PMC          *str_buf = Parrot_str_to_cstring_managed(INTERP, 
     720                VTABLE_get_string(INTERP, SELF)); 
     721        char         *str = (char *)VTABLE_get_pointer(interp, str_buf); 
    721722        UINTVAL       i   = 0; 
    722723        size_t        j   = 0; 
    723724        size_t        len = strlen(str); 
     
    748749 
    749750        if (j < len) { 
    750751            char ch = str[j]; 
    751             Parrot_str_free_cstring(str); 
    752752            Parrot_ex_throw_from_c_args(INTERP, NULL, EXCEPTION_INVALID_OPERATION, 
    753753                    "invalid conversion to int - bad char %c", ch); 
    754754        } 
    755755 
    756         Parrot_str_free_cstring(str); 
    757756        /* TODO: autopromote to BigInt instead of casting away the high bit */ 
    758757        VTABLE_set_integer_native(INTERP, result, (INTVAL)i); 
    759758        RETURN(PMC *result); 
  • src/pmc/hash.pmc

     
    303303 
    304304        for (j = 0; j < n; ++j) { 
    305305            STRING * const key       = VTABLE_shift_string(INTERP, iter); 
    306             char *         key_str; 
    307             size_t         i, str_len; 
     306            size_t         i; 
    308307            int            all_digit = 1; 
    309308            PMC           *val; 
     309            PMC           *key_buf = Parrot_str_to_cstring_managed(INTERP, key); 
     310            char          *key_str = (char *)VTABLE_get_pointer(interp, key_buf); 
     311            size_t         str_len = strlen(key_str); 
    310312 
    311             key_str = Parrot_str_to_cstring(INTERP, key); 
    312             str_len = strlen(key_str); 
    313313            for (i = 0; i < str_len; ++i) { 
    314314                if (!isdigit((unsigned char)key_str[i])) { 
    315315                    all_digit = 0; 
    316316                    break; 
    317317                } 
    318318            } 
    319             Parrot_str_free_cstring(key_str); 
    320319 
    321320            if (all_digit) { 
    322321                res = Parrot_str_append(INTERP, res, key); 
  • src/pmc/resizablebooleanarray.pmc

     
    447447 
    448448*/ 
    449449    VTABLE void thaw(visit_info *info) { 
    450         unsigned char   *bit_array; 
    451450        IMAGE_IO * const io       = info->image_io; 
    452451        const UINTVAL    head_pos = VTABLE_shift_integer(INTERP, io); 
    453452        const UINTVAL    tail_pos = VTABLE_shift_integer(INTERP, io); 
    454453        STRING * const   s        = VTABLE_shift_string(INTERP, io); 
    455  
    456         bit_array      = (unsigned char*)Parrot_str_to_cstring(INTERP, s); 
     454        PMC             *bit_array_buf = 
     455                Parrot_str_to_cstring_managed(INTERP, s); 
     456        unsigned char   *bit_array = 
     457                (unsigned char*) VTABLE_get_pointer(interp, bit_array_buf); 
    457458        SET_ATTR_size(INTERP, SELF, tail_pos); 
    458459        SET_ATTR_resize_threshold(INTERP, SELF, head_pos); 
    459460        SET_ATTR_bit_array(INTERP, SELF, bit_array); 
  • src/pmc/nci.pmc

     
    209209 
    210210        /* ensure that the STRING signature is constant */ 
    211211        if (!PObj_constant_TEST(key)) { 
    212             char * const key_c      = Parrot_str_to_cstring(INTERP, key); 
     212            PMC *key_buf            = Parrot_str_to_cstring_managed(INTERP, key); 
     213            char * const key_c      = (char *)VTABLE_get_pointer(interp, key_buf); 
    213214            size_t       key_length = Parrot_str_byte_length(interp, key); 
    214215            key                     = string_make(interp, key_c, key_length, 
    215216                                        NULL, PObj_constant_FLAG); 
    216             Parrot_str_free_cstring(key_c); 
    217217        } 
    218218 
    219219        nci_info->signature = key; 
     
    301301    VTABLE opcode_t *invoke(void *next) { 
    302302        Parrot_NCI_attributes * const nci_info = PARROT_NCI(SELF); 
    303303        nci_sub_t                     func; 
    304         char                         *sig_str; 
    305304        void                         *orig_func; 
    306305        PMC                          *cont; 
    307306 
     
    321320        } 
    322321 
    323322        if (nci_info->jitted) { 
     323            PMC  *sig_buf; 
     324            char *sig_str; 
    324325            nci_jit_sub_t jit_func = (nci_jit_sub_t) D2FPTR(nci_info->func); 
    325326 
    326327            /* Parrot_eprintf(interp, "JITTED %S\n", nci_info->signature); */ 
    327             sig_str = Parrot_str_to_cstring(interp, nci_info->pcc_params_signature); 
     328            sig_buf = Parrot_str_to_cstring_managed(interp, nci_info->pcc_params_signature); 
     329            sig_str = (char *)VTABLE_get_pointer(interp, sig_buf); 
    328330            jit_func(INTERP, SELF, sig_str); 
    329             Parrot_str_free_cstring(sig_str); 
    330331        } 
    331332        else { 
    332333            if (PObj_flag_TEST(private2, SELF)) { 
  • src/pmc/sub.pmc

     
    10001000        static const char types[] = "INSP"; 
    10011001        char *p; 
    10021002        Parrot_Sub_attributes *sub; 
    1003         char          * const kind = Parrot_str_to_cstring(interp, reg); 
     1003        PMC *kindbuf = Parrot_str_to_cstring_managed(interp, reg); 
     1004        char * const kind = (char *)VTABLE_get_pointer(interp, kindbuf); 
    10041005        INTVAL                regs_used; 
    10051006 
    10061007        PMC_get_sub(INTERP, SELF, sub); 
    10071008        PARROT_ASSERT(sub->n_regs_used); 
    10081009 
    1009         if (!*kind || kind[1]) { 
    1010             Parrot_str_free_cstring(kind); 
     1010        if (!*kind || kind[1]) 
    10111011            Parrot_ex_throw_from_c_args(INTERP, NULL, EXCEPTION_INVALID_OPERATION, 
    10121012                "illegal register kind '%Ss'", reg); 
    1013         } 
    10141013 
    10151014        p = strchr(types, *kind); 
    1016         Parrot_str_free_cstring(kind); 
    10171015 
    10181016        if (!p) 
    10191017            Parrot_ex_throw_from_c_args(INTERP, NULL, EXCEPTION_INVALID_OPERATION, 
  • src/datatypes.c

     
    4141Parrot_get_datatype_enum(PARROT_INTERP, ARGIN(const STRING *type_name)) 
    4242{ 
    4343    ASSERT_ARGS(Parrot_get_datatype_enum) 
    44     char * const type = Parrot_str_to_cstring(interp, type_name); 
     44    PMC *typebuf = Parrot_str_to_cstring_managed(interp, type_name); 
     45    char * const type = (char *)VTABLE_get_pointer(interp, typebuf); 
    4546    int i; 
    4647 
    4748    for (i = enum_first_type; i < enum_last_type; i++) { 
    4849        if (STREQ(data_types[i - enum_first_type].name, type)) { 
    49             Parrot_str_free_cstring(type); 
    5050            return i; 
    5151        } 
    5252    } 
    5353 
    54     Parrot_str_free_cstring(type); 
    55  
    5654    return enum_type_undef; 
    5755} 
    5856 
  • src/packfile.c

     
    46954695        enum_runtime_ft file_type) 
    46964696{ 
    46974697    ASSERT_ARGS(compile_or_load_file) 
    4698     char * const filename = Parrot_str_to_cstring(interp, path); 
     4698    PMC *filenamebuf = Parrot_str_to_cstring_managed(interp, path); 
     4699    char * const filename = (char *)VTABLE_get_pointer(interp, filenamebuf); 
    46994700 
    47004701    INTVAL regs_used[] = { 2, 2, 2, 2 }; /* Arbitrary values */ 
    47014702    const int parrot_hll_id = 0; 
     
    47064707 
    47074708    if (file_type == PARROT_RUNTIME_FT_PBC) { 
    47084709        PackFile * const pf = PackFile_append_pbc(interp, filename); 
    4709         Parrot_str_free_cstring(filename); 
    47104710 
    47114711        if (!pf) 
    47124712            Parrot_ex_throw_from_c_args(interp, NULL, 1, 
     
    47234723        PackFile_ByteCode * const cs = 
    47244724            (PackFile_ByteCode *)IMCC_compile_file_s(interp, 
    47254725                filename, &err); 
    4726         Parrot_str_free_cstring(filename); 
    47274726 
    47284727        if (cs) 
    47294728            do_sub_pragmas(interp, cs, PBC_LOADED, NULL); 
  • src/string/api.c

     
    24262426      return string_to_cstring_nullable(interp, s); 
    24272427} 
    24282428 
     2429/* 
    24292430 
     2431=item C<PMC * Parrot_str_to_cstring_managed(PARROT_INTERP, const STRING *s)> 
     2432 
     2433Returns a PMC containing a C string for the specified Parrot string. Use 
     2434(char *) VTABLE_get_pointer to retrieve the C string and never free it, 
     2435is managed by the PMC. 
     2436 
     2437=cut 
     2438 
     2439*/ 
     2440 
     2441PARROT_EXPORT 
     2442PARROT_CANNOT_RETURN_NULL 
     2443PMC * 
     2444Parrot_str_to_cstring_managed(PARROT_INTERP, ARGIN(const STRING *s)) 
     2445{ 
     2446    PMC *result = pmc_new(interp, enum_class_ManagedStruct); 
     2447    char * const cstr = string_to_cstring_nullable(interp, s); 
     2448    VTABLE_set_pointer(interp, result, cstr); 
     2449    return result; 
     2450} 
     2451 
    24302452/* 
    24312453 
    24322454=item C<char * string_to_cstring_nullable(PARROT_INTERP, const STRING *s)> 
  • src/call/pcc.c

     
    29942994 
    29952995    /* create the signature string, and the various PMCs that are needed to 
    29962996       store all the parameters and parameter counts. */ 
    2997     char * const signature  = Parrot_str_to_cstring(interp, 
     2997    PMC *signature_buf = Parrot_str_to_cstring_managed(interp, 
    29982998                                   VTABLE_get_string(interp, sig_obj)); 
     2999    char * const signature  = (char *)VTABLE_get_pointer(interp, signature_buf); 
    29993000    PMC * const args_sig    = temporary_pmc_new(interp, 
    30003001                                   enum_class_FixedIntegerArray); 
    30013002    PMC * const results_sig = temporary_pmc_new(interp, 
     
    30773078    interp->current_args   = save_current_args; 
    30783079    interp->args_signature = save_args_signature; 
    30793080    interp->current_object = save_current_object; 
    3080     Parrot_str_free_cstring(signature); 
    30813081} 
    30823082 
    30833083 
  • include/parrot/string_funcs.h

     
    412412        __attribute__nonnull__(1); 
    413413 
    414414PARROT_EXPORT 
     415PARROT_CANNOT_RETURN_NULL 
     416PMC * Parrot_str_to_cstring_managed(PARROT_INTERP, ARGIN(const STRING *s)) 
     417        __attribute__nonnull__(1) 
     418        __attribute__nonnull__(2); 
     419 
     420PARROT_EXPORT 
    415421PARROT_WARN_UNUSED_RESULT 
    416422size_t Parrot_str_to_hashval(PARROT_INTERP, ARGMOD_NULLOK(STRING *s)) 
    417423        __attribute__nonnull__(1) 
     
    673679    , PARROT_ASSERT_ARG(s)) 
    674680#define ASSERT_ARGS_Parrot_str_to_cstring __attribute__unused__ int _ASSERT_ARGS_CHECK = (\ 
    675681       PARROT_ASSERT_ARG(interp)) 
     682#define ASSERT_ARGS_Parrot_str_to_cstring_managed __attribute__unused__ int _ASSERT_ARGS_CHECK = (\ 
     683       PARROT_ASSERT_ARG(interp) \ 
     684    , PARROT_ASSERT_ARG(s)) 
    676685#define ASSERT_ARGS_Parrot_str_to_hashval __attribute__unused__ int _ASSERT_ARGS_CHECK = (\ 
    677686       PARROT_ASSERT_ARG(interp)) 
    678687#define ASSERT_ARGS_Parrot_str_to_int __attribute__unused__ int _ASSERT_ARGS_CHECK = (\