Skip to content

Commit

Permalink
[str] Switch to STRING_equal macro
Browse files Browse the repository at this point in the history
Move the whole 'str_equal' logic into the string vtable functions

git-svn-id: https://svn.parrot.org/parrot/trunk@49416 d31e2699-5ff4-0310-a27c-f18f2fbe73fe
  • Loading branch information
nwellnhof committed Oct 2, 2010
1 parent 02984a9 commit 9116125
Show file tree
Hide file tree
Showing 46 changed files with 257 additions and 255 deletions.
4 changes: 2 additions & 2 deletions compilers/pirc/src/bcgen.c
Original file line number Diff line number Diff line change
Expand Up @@ -271,7 +271,7 @@ add_string_const(ARGIN(bytecode * const bc), ARGIN(char const * const str),
while (index < count) {
constant = bc->interp->code->const_table->constants[index];
if (constant->type == PFC_STRING) {
if (Parrot_str_equal(bc->interp, constant->u.string, parrotstr)) {
if (STRING_equal(bc->interp, constant->u.string, parrotstr)) {
#if DEBUGBC
fprintf(stderr, "found string %s at index %d\n", str, index);
#endif
Expand Down Expand Up @@ -351,7 +351,7 @@ add_key_const(ARGIN(bytecode * const bc), ARGIN(PMC *key))

if (constant->type == PFC_KEY) {
STRING *s2 = key_set_to_string(bc->interp, constant->u.key);
if (Parrot_str_equal(bc->interp, s1, s2)) {
if (STRING_equal(bc->interp, s1, s2)) {
#if DEBUGBC
fprintf(stderr, "found equal key (%d)\n", index);
#endif
Expand Down
63 changes: 35 additions & 28 deletions src/dynext.c
Original file line number Diff line number Diff line change
Expand Up @@ -51,14 +51,16 @@ static void * dlopen_string(PARROT_INTERP,
PARROT_WARN_UNUSED_RESULT
PARROT_CAN_RETURN_NULL
static STRING * get_path(PARROT_INTERP,
ARGMOD_NULLOK(STRING *lib),
ARGMOD(STRING *lib),
Parrot_dlopen_flags flags,
ARGOUT(void **handle),
ARGIN(STRING *wo_ext),
ARGIN_NULLOK(STRING *ext))
ARGIN(STRING *ext))
__attribute__nonnull__(1)
__attribute__nonnull__(2)
__attribute__nonnull__(4)
__attribute__nonnull__(5)
__attribute__nonnull__(6)
FUNC_MODIFIES(*lib)
FUNC_MODIFIES(*handle);

Expand All @@ -77,10 +79,11 @@ static PMC * make_string_pmc(PARROT_INTERP, ARGIN(STRING *string))
PARROT_CANNOT_RETURN_NULL
static PMC * run_init_lib(PARROT_INTERP,
ARGIN(void *handle),
ARGIN_NULLOK(STRING *lib_name),
ARGIN(STRING *lib_name),
ARGIN(STRING *wo_ext))
__attribute__nonnull__(1)
__attribute__nonnull__(2)
__attribute__nonnull__(3)
__attribute__nonnull__(4);

static void set_cstring_prop(PARROT_INTERP,
Expand All @@ -97,11 +100,12 @@ static void store_lib_pmc(PARROT_INTERP,
ARGIN(PMC *lib_pmc),
ARGIN(STRING *path),
ARGIN(STRING *type),
ARGIN_NULLOK(STRING *lib_name))
ARGIN(STRING *lib_name))
__attribute__nonnull__(1)
__attribute__nonnull__(2)
__attribute__nonnull__(3)
__attribute__nonnull__(4);
__attribute__nonnull__(4)
__attribute__nonnull__(5);

#define ASSERT_ARGS_clone_string_into __attribute__unused__ int _ASSERT_ARGS_CHECK = (\
PARROT_ASSERT_ARG(d) \
Expand All @@ -112,8 +116,10 @@ static void store_lib_pmc(PARROT_INTERP,
, PARROT_ASSERT_ARG(path))
#define ASSERT_ARGS_get_path __attribute__unused__ int _ASSERT_ARGS_CHECK = (\
PARROT_ASSERT_ARG(interp) \
, PARROT_ASSERT_ARG(lib) \
, PARROT_ASSERT_ARG(handle) \
, PARROT_ASSERT_ARG(wo_ext))
, PARROT_ASSERT_ARG(wo_ext) \
, PARROT_ASSERT_ARG(ext))
#define ASSERT_ARGS_is_loaded __attribute__unused__ int _ASSERT_ARGS_CHECK = (\
PARROT_ASSERT_ARG(interp) \
, PARROT_ASSERT_ARG(path))
Expand All @@ -123,6 +129,7 @@ static void store_lib_pmc(PARROT_INTERP,
#define ASSERT_ARGS_run_init_lib __attribute__unused__ int _ASSERT_ARGS_CHECK = (\
PARROT_ASSERT_ARG(interp) \
, PARROT_ASSERT_ARG(handle) \
, PARROT_ASSERT_ARG(lib_name) \
, PARROT_ASSERT_ARG(wo_ext))
#define ASSERT_ARGS_set_cstring_prop __attribute__unused__ int _ASSERT_ARGS_CHECK = (\
PARROT_ASSERT_ARG(interp) \
Expand All @@ -133,7 +140,8 @@ static void store_lib_pmc(PARROT_INTERP,
PARROT_ASSERT_ARG(interp) \
, PARROT_ASSERT_ARG(lib_pmc) \
, PARROT_ASSERT_ARG(path) \
, PARROT_ASSERT_ARG(type))
, PARROT_ASSERT_ARG(type) \
, PARROT_ASSERT_ARG(lib_name))
/* Don't modify between HEADERIZER BEGIN / HEADERIZER END. Your changes will be lost. */
/* HEADERIZER END: static */

Expand Down Expand Up @@ -177,7 +185,7 @@ Stores a C<ParrotLibrary> PMC in the interpreter's C<iglobals>.

static void
store_lib_pmc(PARROT_INTERP, ARGIN(PMC *lib_pmc), ARGIN(STRING *path),
ARGIN(STRING *type), ARGIN_NULLOK(STRING *lib_name))
ARGIN(STRING *type), ARGIN(STRING *lib_name))
{
ASSERT_ARGS(store_lib_pmc)
PMC * const iglobals = interp->iglobals;
Expand All @@ -188,7 +196,7 @@ store_lib_pmc(PARROT_INTERP, ARGIN(PMC *lib_pmc), ARGIN(STRING *path),
set_cstring_prop(interp, lib_pmc, "_filename", path);
set_cstring_prop(interp, lib_pmc, "_type", type);

if (lib_name)
if (!STRING_IS_NULL(lib_name))
set_cstring_prop(interp, lib_pmc, "_lib_name", lib_name);

VTABLE_set_pmc_keyed_str(interp, dyn_libs, path, lib_pmc);
Expand Down Expand Up @@ -260,9 +268,8 @@ Returns path and handle of a dynamic lib, setting lib_name to just the filestem
PARROT_WARN_UNUSED_RESULT
PARROT_CAN_RETURN_NULL
static STRING *
get_path(PARROT_INTERP, ARGMOD_NULLOK(STRING *lib), Parrot_dlopen_flags flags,
ARGOUT(void **handle), ARGIN(STRING *wo_ext),
ARGIN_NULLOK(STRING *ext))
get_path(PARROT_INTERP, ARGMOD(STRING *lib), Parrot_dlopen_flags flags,
ARGOUT(void **handle), ARGIN(STRING *wo_ext), ARGIN(STRING *ext))
{
ASSERT_ARGS(get_path)
PMC * const iglobals = interp->iglobals;
Expand All @@ -273,7 +280,7 @@ get_path(PARROT_INTERP, ARGMOD_NULLOK(STRING *lib), Parrot_dlopen_flags flags,

STRING *path, *full_name;

if (! lib) {
if (STRING_IS_NULL(lib)) {
*handle = Parrot_dlopen((char *)NULL, flags);
if (*handle)
return CONST_STRING(interp, "");
Expand All @@ -284,12 +291,12 @@ get_path(PARROT_INTERP, ARGMOD_NULLOK(STRING *lib), Parrot_dlopen_flags flags,
err ? err : "unknown reason");
/* clear the error memory */
(void)Parrot_dlerror();
return NULL;
return STRINGNULL;
}
}

/* first, try to add an extension to the file if it has none */
if (! ext) {
if (STRING_IS_NULL(ext)) {
const INTVAL n = VTABLE_elements(interp, share_ext);
INTVAL i;

Expand All @@ -299,7 +306,7 @@ get_path(PARROT_INTERP, ARGMOD_NULLOK(STRING *lib), Parrot_dlopen_flags flags,
path = Parrot_locate_runtime_file_str(interp, full_name,
PARROT_RUNTIME_FT_DYNEXT);

if (path) {
if (!STRING_IS_NULL(path)) {
*handle = dlopen_string(interp, flags, path);

if (*handle)
Expand All @@ -311,7 +318,7 @@ get_path(PARROT_INTERP, ARGMOD_NULLOK(STRING *lib), Parrot_dlopen_flags flags,
full_name, err ? err : "unknown reason");
/* clear the error memory */
(void)Parrot_dlerror();
return NULL;
return STRINGNULL;
}
}

Expand All @@ -332,7 +339,7 @@ get_path(PARROT_INTERP, ARGMOD_NULLOK(STRING *lib), Parrot_dlopen_flags flags,
full_name = Parrot_locate_runtime_file_str(interp, lib,
PARROT_RUNTIME_FT_DYNEXT);

if (full_name) {
if (!STRING_IS_NULL(full_name)) {
*handle = dlopen_string(interp, flags, full_name);

if (*handle)
Expand All @@ -344,7 +351,7 @@ get_path(PARROT_INTERP, ARGMOD_NULLOK(STRING *lib), Parrot_dlopen_flags flags,
* [shouldn't this happen in Parrot_locate_runtime_file instead?]
*/
#ifdef WIN32
if (!STRING_IS_EMPTY(lib) && memcmp(lib->strstart, "lib", 3) == 0) {
if (STRING_length(lib) >= 3 && memcmp(lib->strstart, "lib", 3) == 0) {
*handle = Parrot_dlopen((char *)lib->strstart + 3, 0);

if (*handle)
Expand All @@ -354,7 +361,7 @@ get_path(PARROT_INTERP, ARGMOD_NULLOK(STRING *lib), Parrot_dlopen_flags flags,

/* And on cygwin replace a leading "lib" by "cyg". */
#ifdef __CYGWIN__
if (!STRING_IS_EMPTY(lib) && memcmp(lib->strstart, "lib", 3) == 0) {
if (!STRING_length(lib) >= 3 && memcmp(lib->strstart, "lib", 3) == 0) {
path = Parrot_str_concat(interp, CONST_STRING(interp, "cyg"),
Parrot_str_substr(interp, lib, 3, lib->strlen - 3));

Expand All @@ -365,7 +372,7 @@ get_path(PARROT_INTERP, ARGMOD_NULLOK(STRING *lib), Parrot_dlopen_flags flags,
}
#endif

if (STRING_IS_EMPTY(lib)) {
if (!STRING_length(lib)) {
*handle = dlopen_string(interp, flags, lib);
if (*handle)
return lib;
Expand All @@ -379,7 +386,7 @@ get_path(PARROT_INTERP, ARGMOD_NULLOK(STRING *lib), Parrot_dlopen_flags flags,

/* clear the error memory */
(void)Parrot_dlerror();
return NULL;
return STRINGNULL;
}
}

Expand Down Expand Up @@ -469,7 +476,7 @@ necessary initialization routines, if any.
PARROT_CANNOT_RETURN_NULL
static PMC *
run_init_lib(PARROT_INTERP, ARGIN(void *handle),
ARGIN_NULLOK(STRING *lib_name), ARGIN(STRING *wo_ext))
ARGIN(STRING *lib_name), ARGIN(STRING *wo_ext))
{
ASSERT_ARGS(run_init_lib)
STRING *type;
Expand All @@ -484,7 +491,7 @@ run_init_lib(PARROT_INTERP, ARGIN(void *handle),
Parrot_pcc_set_namespace(interp, context,
Parrot_get_HLL_namespace(interp, parrot_hll_id));

if (lib_name) {
if (!STRING_IS_NULL(lib_name)) {
STRING * const load_name = Parrot_sprintf_c(interp,
"Parrot_lib_%Ss_load", lib_name);
STRING * const init_func_name = Parrot_sprintf_c(interp,
Expand Down Expand Up @@ -606,7 +613,7 @@ Parrot_clone_lib_into(ARGMOD(Interp *d), ARGMOD(Interp *s), ARGIN(PMC *lib_pmc))
STRING * const type =
VTABLE_get_string(s, VTABLE_getprop(s, lib_pmc, type_str));

if (Parrot_str_equal(s, type, ops)) {
if (STRING_equal(s, type, ops)) {
/* we can't clone oplibs in the normal way, since they're actually
* shared between interpreters dynop_register modifies the (statically
* allocated) op_lib_t structure from core_ops.c, for example.
Expand Down Expand Up @@ -690,12 +697,12 @@ Parrot_load_lib(PARROT_INTERP, ARGIN_NULLOK(STRING *lib), ARGIN_NULLOK(PMC *para
*
* LOCK()
*/
if (lib)
if (!STRING_IS_NULL(lib))
lib_name = parrot_split_path_ext(interp, lib, &wo_ext, &ext);
else {
wo_ext = CONST_STRING(interp, "");
lib_name = NULL;
ext = NULL;
lib_name = STRINGNULL;
ext = STRINGNULL;
}

lib_pmc = is_loaded(interp, wo_ext);
Expand Down
4 changes: 2 additions & 2 deletions src/dynpmc/os.pmc
Original file line number Diff line number Diff line change
Expand Up @@ -508,9 +508,9 @@ reads entries from a directory.
/* Add \* to the directory name and start search. */
STRING *last_char = Parrot_str_substr(INTERP, path,
Parrot_str_length(INTERP, path) - 1, 1, NULL, 0);
int trailing_slash = Parrot_str_equal(INTERP, last_char, string_from_literal(INTERP, "\\"))
int trailing_slash = STRING_equal(INTERP, last_char, string_from_literal(INTERP, "\\"))
||
Parrot_str_equal(INTERP, last_char, string_from_literal(INTERP, "/"));
STRING_equal(INTERP, last_char, string_from_literal(INTERP, "/"));
cpath = Parrot_str_to_cstring(INTERP, Parrot_str_concat(INTERP,
path, string_from_literal(INTERP, trailing_slash ? "*" : "\\*"), 0));
hFind = FindFirstFile(cpath, &file_find_data);
Expand Down
4 changes: 2 additions & 2 deletions src/embed.c
Original file line number Diff line number Diff line change
Expand Up @@ -1118,10 +1118,10 @@ Parrot_compile_string(PARROT_INTERP, Parrot_String type, ARGIN(const char *code)
PARROT_ASSERT(interp->initial_pf);
}

if (Parrot_str_compare(interp, CONST_STRING(interp, "PIR"), type) == 0)
if (STRING_equal(interp, CONST_STRING(interp, "PIR"), type))
return IMCC_compile_pir_s(interp, code, error);

if (Parrot_str_compare(interp, CONST_STRING(interp, "PASM"), type) == 0)
if (STRING_equal(interp, CONST_STRING(interp, "PASM"), type))
return IMCC_compile_pasm_s(interp, code, error);

*error = Parrot_str_new(interp, "Invalid interpreter type", 0);
Expand Down
4 changes: 2 additions & 2 deletions src/exceptions.c
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ die_from_exception(PARROT_INTERP, ARGIN(PMC *exception))
}
}

if (Parrot_str_not_equal(interp, message, CONST_STRING(interp, ""))) {
if (STRING_length(message)) {
if (use_perr)
Parrot_io_eprintf(interp, "%S\n", message);
else {
Expand Down Expand Up @@ -234,7 +234,7 @@ Parrot_ex_throw_from_op(PARROT_INTERP, ARGIN(PMC *exception), ARGIN_NULLOK(void
const INTVAL severity = VTABLE_get_integer_keyed_str(interp, exception, CONST_STRING(interp, "severity"));
if (severity < EXCEPT_error) {
PMC * const resume = VTABLE_get_attr_str(interp, exception, CONST_STRING(interp, "resume"));
if (Parrot_str_not_equal(interp, message, CONST_STRING(interp, ""))) {
if (STRING_length(message)) {
Parrot_io_eprintf(interp, "%S\n", message);
}
else {
Expand Down
4 changes: 2 additions & 2 deletions src/hash.c
Original file line number Diff line number Diff line change
Expand Up @@ -316,7 +316,7 @@ hash_compare_string(PARROT_INTERP, ARGIN(const void *search_key),
STRING const *s1 = (STRING const *)search_key;
STRING const *s2 = (STRING const *)bucket_key;

return Parrot_str_equal(interp, s1, s2) == 0;
return !STRING_equal(interp, s1, s2);
}


Expand Down Expand Up @@ -1499,7 +1499,7 @@ parrot_hash_get_bucket_string(PARROT_INTERP, ARGIN(const Hash *hash),
if ((STRING_byte_length(s) == STRING_byte_length(s2))
&& (memcmp(s->strstart, s2->strstart, STRING_byte_length(s)) == 0))
break;
} else if (Parrot_str_equal(interp, s, s2))
} else if (STRING_equal(interp, s, s2))
break;
}
bucket = bucket->next;
Expand Down
2 changes: 1 addition & 1 deletion src/hll.c
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,7 @@ Parrot_register_HLL_lib(PARROT_INTERP, ARGIN(STRING *hll_lib))

if (!PMC_IS_NULL(lib_name)) {
const STRING * const lib_name_str = VTABLE_get_string(interp, lib_name);
if (Parrot_str_equal(interp, lib_name_str, hll_lib))
if (STRING_equal(interp, lib_name_str, hll_lib))
break;
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/io/filehandle.c
Original file line number Diff line number Diff line change
Expand Up @@ -674,7 +674,7 @@ Parrot_io_is_encoding(PARROT_INTERP, ARGIN(const PMC *filehandle), ARGIN(STRING
if (STRING_IS_NULL(handle_struct->encoding))
return 0;

if (Parrot_str_equal(interp, value, handle_struct->encoding))
if (STRING_equal(interp, value, handle_struct->encoding))
return 1;

return 0;
Expand Down
10 changes: 5 additions & 5 deletions src/library.c
Original file line number Diff line number Diff line change
Expand Up @@ -575,15 +575,15 @@ try_bytecode_extensions(PARROT_INTERP, ARGMOD(STRING* path))
if (Parrot_str_byte_length(interp, test_path) > 4) {
STRING *orig_ext = Parrot_str_substr(interp, test_path, -4, 4);
/* First try substituting .pbc for the .pir extension */
if (Parrot_str_equal(interp, orig_ext, pir_extension)) {
if (STRING_equal(interp, orig_ext, pir_extension)) {
STRING * const without_ext = Parrot_str_chopn(interp, test_path, 4);
test_path = Parrot_str_concat(interp, without_ext, bytecode_extension);
result = try_load_path(interp, test_path);
if (result)
return result;
}
/* Next try substituting .pir, then .pasm for the .pbc extension */
else if (Parrot_str_equal(interp, orig_ext, bytecode_extension)) {
else if (STRING_equal(interp, orig_ext, bytecode_extension)) {
STRING * const without_ext = Parrot_str_chopn(interp, test_path, 4);
test_path = Parrot_str_concat(interp, without_ext, pir_extension);
result = try_load_path(interp, test_path);
Expand All @@ -601,7 +601,7 @@ try_bytecode_extensions(PARROT_INTERP, ARGMOD(STRING* path))
/* Finally, try substituting .pbc for the .pasm extension. */
if (Parrot_str_byte_length(interp, test_path) > 5) {
STRING * const orig_ext = Parrot_str_substr(interp, test_path, -5, 5);
if (Parrot_str_equal(interp, orig_ext, pasm_extension)) {
if (STRING_equal(interp, orig_ext, pasm_extension)) {
STRING * const without_ext = Parrot_str_chopn(interp, test_path, 5);
test_path = Parrot_str_concat(interp, without_ext, bytecode_extension);
result = try_load_path(interp, test_path);
Expand Down Expand Up @@ -878,12 +878,12 @@ parrot_split_path_ext(PARROT_INTERP, ARGMOD(STRING *in),
else if (pos_sl) {
stem = Parrot_str_substr(interp, in, pos_sl, len - pos_sl);
*wo_ext = in;
*ext = NULL;
*ext = STRINGNULL;
}
else {
stem = in;
*wo_ext = stem;
*ext = NULL;
*ext = STRINGNULL;
}
return stem;
}
Expand Down
8 changes: 4 additions & 4 deletions src/multidispatch.c
Original file line number Diff line number Diff line change
Expand Up @@ -401,13 +401,13 @@ mmd_build_type_tuple_from_type_list(PARROT_INTERP, ARGIN(PMC *type_list))
STRING *type_name = VTABLE_get_string_keyed_int(interp, type_list, i);
INTVAL type;

if (Parrot_str_equal(interp, type_name, CONST_STRING(interp, "DEFAULT")))
if (STRING_equal(interp, type_name, CONST_STRING(interp, "DEFAULT")))
type = enum_type_PMC;
else if (Parrot_str_equal(interp, type_name, CONST_STRING(interp, "STRING")))
else if (STRING_equal(interp, type_name, CONST_STRING(interp, "STRING")))
type = enum_type_STRING;
else if (Parrot_str_equal(interp, type_name, CONST_STRING(interp, "INTVAL")))
else if (STRING_equal(interp, type_name, CONST_STRING(interp, "INTVAL")))
type = enum_type_INTVAL;
else if (Parrot_str_equal(interp, type_name, CONST_STRING(interp, "FLOATVAL")))
else if (STRING_equal(interp, type_name, CONST_STRING(interp, "FLOATVAL")))
type = enum_type_FLOATVAL;
else
type = Parrot_pmc_get_type_str(interp, type_name);
Expand Down
Loading

0 comments on commit 9116125

Please sign in to comment.