# New Ticket Created by Mark Glines # Please include the string: [perl #43355] # in the subject line of all future correspondence about this issue. # <URL: http://rt.perl.org/rt3/Ticket/Display.html?id=43355 >
string_from_literal() was added in r19260, to handle the string_from_cstring(interp, "some constant string", 0) case more efficiently. Rather than doing a strlen() at runtime, it does a sizeof() at compile time. That patch also fixed up a large number of existing string_from_cstring cases, to use the new function. This patch fixes up the rest of the cases that I can find with grep. This includes most or all of the cases in autogenerated code. The only thing worthy of note was that I had to remove a (const char *) prototype from a case in lib/Parrot/Pmc2c/PCCMETHOD.pm, because it was causing sizeof() to report the size of a pointer, rather than the size of the string. Mark
=== languages/dotnet/pmc/dotnetassembly.pmc ================================================================== --- languages/dotnet/pmc/dotnetassembly.pmc (revision 21011) +++ languages/dotnet/pmc/dotnetassembly.pmc (local) @@ -1224,7 +1224,7 @@ type->str_namespace = string_from_cstring(INTERP, ass->strings + pos_namespace, 0); type->str_fullname = string_concat(INTERP, type->str_namespace, - string_from_cstring(INTERP, ".", 0), 0); + string_from_literal(INTERP, "."), 0); type->str_fullname = string_concat(INTERP, type->str_fullname, type->str_name, 0); } @@ -1775,23 +1775,23 @@ if (pass) { dynclass_DotNetClassMetadata = pmc_type(INTERP, - string_from_cstring(INTERP, "DotNetClassMetadata", 0)); + string_from_literal(INTERP, "DotNetClassMetadata")); dynclass_DotNetMethodMetadata = pmc_type(INTERP, - string_from_cstring(INTERP, "DotNetMethodMetadata", 0)); + string_from_literal(INTERP, "DotNetMethodMetadata")); dynclass_DotNetFieldMetadata = pmc_type(INTERP, - string_from_cstring(INTERP, "DotNetFieldMetadata", 0)); + string_from_literal(INTERP, "DotNetFieldMetadata")); dynclass_DotNetParamMetadata = pmc_type(INTERP, - string_from_cstring(INTERP, "DotNetParamMetadata", 0)); + string_from_literal(INTERP, "DotNetParamMetadata")); dynclass_DotNetBytecode = pmc_type(INTERP, - string_from_cstring(INTERP, "DotNetBytecode", 0)); + string_from_literal(INTERP, "DotNetBytecode")); dynclass_DotNetEH = pmc_type(INTERP, - string_from_cstring(INTERP, "DotNetEH", 0)); + string_from_literal(INTERP, "DotNetEH")); dynclass_DotNetTypeRefMetadata = pmc_type(INTERP, - string_from_cstring(INTERP, "DotNetTypeRefMetadata", 0)); + string_from_literal(INTERP, "DotNetTypeRefMetadata")); dynclass_DotNetMemberRefMetadata = pmc_type(INTERP, - string_from_cstring(INTERP, "DotNetMemberRefMetadata", 0)); + string_from_literal(INTERP, "DotNetMemberRefMetadata")); dynclass_DotNetAssemblyRefMetadata = pmc_type(INTERP, - string_from_cstring(INTERP, "DotNetAssemblyRef", 0)); + string_from_literal(INTERP, "DotNetAssemblyRef")); } } === lib/Parrot/Pmc2c/PCCMETHOD.pm ================================================================== --- lib/Parrot/Pmc2c/PCCMETHOD.pm (revision 21011) +++ lib/Parrot/Pmc2c/PCCMETHOD.pm (local) @@ -196,7 +196,7 @@ return " $name = CTX_REG_$tiss(ctx, $index);\n"; } elsif ( 'name' eq $arg_type ) { - return " CTX_REG_$tiss(ctx, $index) = string_from_cstring(interp, $name, 0);\n"; + return " CTX_REG_$tiss(ctx, $index) = string_from_literal(interp, $name);\n"; } else { #$arg_type eq 'param' or $arg_type eq 'return' return " CTX_REG_$tiss(ctx, $index) = $name;\n"; @@ -247,7 +247,7 @@ return_indexes = temp_return_indexes; } return_sig = Parrot_FixedIntegerArray_new_from_string(interp, _type, - string_from_cstring(interp, $returns_flags, 0), 0); + string_from_literal(interp, $returns_flags), 0); $goto_string /*END PCCRETURN $returns */ } @@ -370,7 +370,7 @@ opcode_t *current_args; PMC* _type = pmc_new(interp, enum_class_FixedIntegerArray); PMC* param_sig = Parrot_FixedIntegerArray_new_from_string(interp, _type, - string_from_cstring(interp, $params_flags, 0), 0); + string_from_literal(interp, $params_flags), 0); PMC* return_sig = PMCNULL; @@ -481,7 +481,7 @@ my $n_regs_used = find_max_regs( [ $result_n_regs_used, $args_n_regs_used ] ); - $method_name = "string_from_cstring(interp, (const char *) $method_name, 0)" + $method_name = "string_from_literal(interp, $method_name)" if isquoted($method_name); my $file = '"' . __FILE__ . '"'; @@ -498,9 +498,9 @@ PMC* _type = pmc_new(interp, enum_class_FixedIntegerArray); PMC* args_sig = Parrot_FixedIntegerArray_new_from_string(interp, - _type, string_from_cstring(interp, $arg_flags, 0), 0); + _type, string_from_literal(interp, $arg_flags), 0); PMC* results_sig = Parrot_FixedIntegerArray_new_from_string(interp, - _type, string_from_cstring(interp, $result_flags, 0), 0); + _type, string_from_literal(interp, $result_flags), 0); PMC* ret_cont = new_ret_continuation_pmc(interp, NULL); parrot_context_t *ctx = Parrot_push_context(interp, n_regs_used); === lib/Parrot/Pmc2c.pm ================================================================== --- lib/Parrot/Pmc2c.pm (revision 21011) +++ lib/Parrot/Pmc2c.pm (local) @@ -1057,7 +1057,7 @@ foreach my $dynpmc (@$dyn_mmds) { next if $dynpmc eq $classname; $cout .= <<"EOC"; - int my_enum_class_$dynpmc = pmc_type(interp, string_from_cstring(interp, "$dynpmc", 0)); + int my_enum_class_$dynpmc = pmc_type(interp, string_from_literal(interp, "$dynpmc")); EOC } === src/inter_misc.c ================================================================== --- src/inter_misc.c (revision 21011) +++ src/inter_misc.c (local) @@ -426,7 +426,7 @@ { switch (info_wanted) { case PARROT_OS: - return string_from_cstring(interp, BUILD_OS_NAME, 0); + return string_from_literal(interp, BUILD_OS_NAME); case PARROT_OS_VERSION: case PARROT_OS_VERSION_NUMBER: case CPU_ARCH: === src/pmc/env.pmc ================================================================== --- src/pmc/env.pmc (revision 21011) +++ src/pmc/env.pmc (local) @@ -154,7 +154,8 @@ val = Parrot_getenv(keyname, &free_it); string_cstring_free(keyname); } - retval = string_from_cstring(interp, val ? val : "", 0); + retval = val ? string_from_cstring(interp, val, 0) + : string_from_literal(interp, ""); if (free_it && val) mem_sys_free(val); break; @@ -185,7 +186,8 @@ val = Parrot_getenv(keyname, &free_it); string_cstring_free(keyname); } - retval = string_from_cstring(INTERP, val ? val : "", 0); + retval = val ? string_from_cstring(INTERP, val, 0) + : string_from_literal(INTERP, ""); if (free_it && val) mem_sys_free(val); return_pmc = pmc_new(INTERP, enum_class_String);