Ticket #1083: managed_cstring.patch
File managed_cstring.patch, 13.0 KB (added by NotFound, 12 years ago) |
---|
-
src/ops/core.ops
1322 1322 } 1323 1323 1324 1324 op 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); 1326 1327 void *dl_handle = NULL; 1327 1328 void *ptr = NULL; 1328 1329 funcptr_t p; … … 1350 1351 VTABLE_set_pointer_keyed_str(interp, $1, $4, F2DPTR(p)); 1351 1352 PObj_get_FLAGS($1) |= PObj_private1_FLAG; 1352 1353 } 1353 Parrot_str_free_cstring(name);1354 1354 } 1355 1355 1356 1356 op 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); 1358 1359 void * p = NULL; 1359 1360 void *dl_handle = NULL; 1360 1361 … … 1374 1375 $1 = pmc_new(interp, enum_class_UnManagedStruct); 1375 1376 VTABLE_set_pointer(interp, $1, p); 1376 1377 } 1377 Parrot_str_free_cstring(name);1378 1378 } 1379 1379 1380 1380 inline op compreg(in STR, invar PMC) { -
src/pmc/string.pmc
224 224 225 225 /* Only allow constant PMCs to embed constant strings */ 226 226 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); 228 229 value = Parrot_str_new_init(INTERP, copy, strlen(copy), 229 230 PARROT_DEFAULT_ENCODING, PARROT_DEFAULT_CHARSET, 230 231 PObj_constant_FLAG); 231 Parrot_str_free_cstring(copy);232 232 } 233 233 234 234 SET_ATTR_str_val(INTERP, SELF, value); … … 716 716 enum_class_Integer)); 717 717 718 718 /* 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); 721 722 UINTVAL i = 0; 722 723 size_t j = 0; 723 724 size_t len = strlen(str); … … 748 749 749 750 if (j < len) { 750 751 char ch = str[j]; 751 Parrot_str_free_cstring(str);752 752 Parrot_ex_throw_from_c_args(INTERP, NULL, EXCEPTION_INVALID_OPERATION, 753 753 "invalid conversion to int - bad char %c", ch); 754 754 } 755 755 756 Parrot_str_free_cstring(str);757 756 /* TODO: autopromote to BigInt instead of casting away the high bit */ 758 757 VTABLE_set_integer_native(INTERP, result, (INTVAL)i); 759 758 RETURN(PMC *result); -
src/pmc/hash.pmc
303 303 304 304 for (j = 0; j < n; ++j) { 305 305 STRING * const key = VTABLE_shift_string(INTERP, iter); 306 char * key_str; 307 size_t i, str_len; 306 size_t i; 308 307 int all_digit = 1; 309 308 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); 310 312 311 key_str = Parrot_str_to_cstring(INTERP, key);312 str_len = strlen(key_str);313 313 for (i = 0; i < str_len; ++i) { 314 314 if (!isdigit((unsigned char)key_str[i])) { 315 315 all_digit = 0; 316 316 break; 317 317 } 318 318 } 319 Parrot_str_free_cstring(key_str);320 319 321 320 if (all_digit) { 322 321 res = Parrot_str_append(INTERP, res, key); -
src/pmc/resizablebooleanarray.pmc
447 447 448 448 */ 449 449 VTABLE void thaw(visit_info *info) { 450 unsigned char *bit_array;451 450 IMAGE_IO * const io = info->image_io; 452 451 const UINTVAL head_pos = VTABLE_shift_integer(INTERP, io); 453 452 const UINTVAL tail_pos = VTABLE_shift_integer(INTERP, io); 454 453 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); 457 458 SET_ATTR_size(INTERP, SELF, tail_pos); 458 459 SET_ATTR_resize_threshold(INTERP, SELF, head_pos); 459 460 SET_ATTR_bit_array(INTERP, SELF, bit_array); -
src/pmc/nci.pmc
209 209 210 210 /* ensure that the STRING signature is constant */ 211 211 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); 213 214 size_t key_length = Parrot_str_byte_length(interp, key); 214 215 key = string_make(interp, key_c, key_length, 215 216 NULL, PObj_constant_FLAG); 216 Parrot_str_free_cstring(key_c);217 217 } 218 218 219 219 nci_info->signature = key; … … 301 301 VTABLE opcode_t *invoke(void *next) { 302 302 Parrot_NCI_attributes * const nci_info = PARROT_NCI(SELF); 303 303 nci_sub_t func; 304 char *sig_str;305 304 void *orig_func; 306 305 PMC *cont; 307 306 … … 321 320 } 322 321 323 322 if (nci_info->jitted) { 323 PMC *sig_buf; 324 char *sig_str; 324 325 nci_jit_sub_t jit_func = (nci_jit_sub_t) D2FPTR(nci_info->func); 325 326 326 327 /* 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); 328 330 jit_func(INTERP, SELF, sig_str); 329 Parrot_str_free_cstring(sig_str);330 331 } 331 332 else { 332 333 if (PObj_flag_TEST(private2, SELF)) { -
src/pmc/sub.pmc
1000 1000 static const char types[] = "INSP"; 1001 1001 char *p; 1002 1002 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); 1004 1005 INTVAL regs_used; 1005 1006 1006 1007 PMC_get_sub(INTERP, SELF, sub); 1007 1008 PARROT_ASSERT(sub->n_regs_used); 1008 1009 1009 if (!*kind || kind[1]) { 1010 Parrot_str_free_cstring(kind); 1010 if (!*kind || kind[1]) 1011 1011 Parrot_ex_throw_from_c_args(INTERP, NULL, EXCEPTION_INVALID_OPERATION, 1012 1012 "illegal register kind '%Ss'", reg); 1013 }1014 1013 1015 1014 p = strchr(types, *kind); 1016 Parrot_str_free_cstring(kind);1017 1015 1018 1016 if (!p) 1019 1017 Parrot_ex_throw_from_c_args(INTERP, NULL, EXCEPTION_INVALID_OPERATION, -
src/datatypes.c
41 41 Parrot_get_datatype_enum(PARROT_INTERP, ARGIN(const STRING *type_name)) 42 42 { 43 43 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); 45 46 int i; 46 47 47 48 for (i = enum_first_type; i < enum_last_type; i++) { 48 49 if (STREQ(data_types[i - enum_first_type].name, type)) { 49 Parrot_str_free_cstring(type);50 50 return i; 51 51 } 52 52 } 53 53 54 Parrot_str_free_cstring(type);55 56 54 return enum_type_undef; 57 55 } 58 56 -
src/packfile.c
4695 4695 enum_runtime_ft file_type) 4696 4696 { 4697 4697 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); 4699 4700 4700 4701 INTVAL regs_used[] = { 2, 2, 2, 2 }; /* Arbitrary values */ 4701 4702 const int parrot_hll_id = 0; … … 4706 4707 4707 4708 if (file_type == PARROT_RUNTIME_FT_PBC) { 4708 4709 PackFile * const pf = PackFile_append_pbc(interp, filename); 4709 Parrot_str_free_cstring(filename);4710 4710 4711 4711 if (!pf) 4712 4712 Parrot_ex_throw_from_c_args(interp, NULL, 1, … … 4723 4723 PackFile_ByteCode * const cs = 4724 4724 (PackFile_ByteCode *)IMCC_compile_file_s(interp, 4725 4725 filename, &err); 4726 Parrot_str_free_cstring(filename);4727 4726 4728 4727 if (cs) 4729 4728 do_sub_pragmas(interp, cs, PBC_LOADED, NULL); -
src/string/api.c
2426 2426 return string_to_cstring_nullable(interp, s); 2427 2427 } 2428 2428 2429 /* 2429 2430 2431 =item C<PMC * Parrot_str_to_cstring_managed(PARROT_INTERP, const STRING *s)> 2432 2433 Returns 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, 2435 is managed by the PMC. 2436 2437 =cut 2438 2439 */ 2440 2441 PARROT_EXPORT 2442 PARROT_CANNOT_RETURN_NULL 2443 PMC * 2444 Parrot_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 2430 2452 /* 2431 2453 2432 2454 =item C<char * string_to_cstring_nullable(PARROT_INTERP, const STRING *s)> -
src/call/pcc.c
2994 2994 2995 2995 /* create the signature string, and the various PMCs that are needed to 2996 2996 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, 2998 2998 VTABLE_get_string(interp, sig_obj)); 2999 char * const signature = (char *)VTABLE_get_pointer(interp, signature_buf); 2999 3000 PMC * const args_sig = temporary_pmc_new(interp, 3000 3001 enum_class_FixedIntegerArray); 3001 3002 PMC * const results_sig = temporary_pmc_new(interp, … … 3077 3078 interp->current_args = save_current_args; 3078 3079 interp->args_signature = save_args_signature; 3079 3080 interp->current_object = save_current_object; 3080 Parrot_str_free_cstring(signature);3081 3081 } 3082 3082 3083 3083 -
include/parrot/string_funcs.h
412 412 __attribute__nonnull__(1); 413 413 414 414 PARROT_EXPORT 415 PARROT_CANNOT_RETURN_NULL 416 PMC * Parrot_str_to_cstring_managed(PARROT_INTERP, ARGIN(const STRING *s)) 417 __attribute__nonnull__(1) 418 __attribute__nonnull__(2); 419 420 PARROT_EXPORT 415 421 PARROT_WARN_UNUSED_RESULT 416 422 size_t Parrot_str_to_hashval(PARROT_INTERP, ARGMOD_NULLOK(STRING *s)) 417 423 __attribute__nonnull__(1) … … 673 679 , PARROT_ASSERT_ARG(s)) 674 680 #define ASSERT_ARGS_Parrot_str_to_cstring __attribute__unused__ int _ASSERT_ARGS_CHECK = (\ 675 681 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)) 676 685 #define ASSERT_ARGS_Parrot_str_to_hashval __attribute__unused__ int _ASSERT_ARGS_CHECK = (\ 677 686 PARROT_ASSERT_ARG(interp)) 678 687 #define ASSERT_ARGS_Parrot_str_to_int __attribute__unused__ int _ASSERT_ARGS_CHECK = (\