Replace CFCUtil_cat with CFCUtil_sprintf where appropriate
Project: http://git-wip-us.apache.org/repos/asf/lucy/repo Commit: http://git-wip-us.apache.org/repos/asf/lucy/commit/cec0b47b Tree: http://git-wip-us.apache.org/repos/asf/lucy/tree/cec0b47b Diff: http://git-wip-us.apache.org/repos/asf/lucy/diff/cec0b47b Branch: refs/heads/master Commit: cec0b47b39808eebea89dcee395fca7060b7aefe Parents: f6f0d83 Author: Nick Wellnhofer <[email protected]> Authored: Wed Dec 26 23:25:32 2012 +0100 Committer: Nick Wellnhofer <[email protected]> Committed: Fri Dec 28 22:23:10 2012 +0100 ---------------------------------------------------------------------- clownfish/compiler/src/CFCBindClass.c | 3 +- clownfish/compiler/src/CFCBindCore.c | 8 +++--- clownfish/compiler/src/CFCHierarchy.c | 8 +++--- clownfish/compiler/src/CFCPerl.c | 36 ++++++++++---------------- clownfish/compiler/src/CFCPerlPod.c | 2 +- clownfish/compiler/src/CFCPerlSub.c | 3 +- clownfish/compiler/src/CFCPerlTypeMap.c | 23 +++++++--------- 7 files changed, 35 insertions(+), 48 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/lucy/blob/cec0b47b/clownfish/compiler/src/CFCBindClass.c ---------------------------------------------------------------------- diff --git a/clownfish/compiler/src/CFCBindClass.c b/clownfish/compiler/src/CFCBindClass.c index a053e5c..7bfcf53 100644 --- a/clownfish/compiler/src/CFCBindClass.c +++ b/clownfish/compiler/src/CFCBindClass.c @@ -386,8 +386,7 @@ CFCBindClass_spec_def(CFCBindClass *self) { // Create a pointer to the parent class's vtable. char *parent_ref; if (parent) { - parent_ref = CFCUtil_cat(CFCUtil_strdup("&"), - CFCClass_full_vtable_var(parent), NULL); + parent_ref = CFCUtil_sprintf("&%s", CFCClass_full_vtable_var(parent)); } else { // No parent, e.g. Obj or inert classes. http://git-wip-us.apache.org/repos/asf/lucy/blob/cec0b47b/clownfish/compiler/src/CFCBindCore.c ---------------------------------------------------------------------- diff --git a/clownfish/compiler/src/CFCBindCore.c b/clownfish/compiler/src/CFCBindCore.c index 903f429..e4c9491 100644 --- a/clownfish/compiler/src/CFCBindCore.c +++ b/clownfish/compiler/src/CFCBindCore.c @@ -255,8 +255,8 @@ S_write_parcel_h(CFCBindCore *self) { // Unlink then write file. const char *inc_dest = CFCHierarchy_get_include_dest(hierarchy); - char *filepath = CFCUtil_cat(CFCUtil_strdup(""), inc_dest, - CFCUTIL_PATH_SEP, "parcel.h", NULL); + char *filepath = CFCUtil_sprintf("%s" CFCUTIL_PATH_SEP "parcel.h", + inc_dest); remove(filepath); CFCUtil_write_file(filepath, file_content, strlen(file_content)); FREEMEM(filepath); @@ -347,8 +347,8 @@ S_write_parcel_c(CFCBindCore *self) { // Unlink then open file. const char *src_dest = CFCHierarchy_get_source_dest(hierarchy); - char *filepath = CFCUtil_cat(CFCUtil_strdup(""), src_dest, - CFCUTIL_PATH_SEP, "parcel.c", NULL); + char *filepath = CFCUtil_sprintf("%s" CFCUTIL_PATH_SEP "parcel.c", + src_dest); remove(filepath); CFCUtil_write_file(filepath, file_content, strlen(file_content)); FREEMEM(filepath); http://git-wip-us.apache.org/repos/asf/lucy/blob/cec0b47b/clownfish/compiler/src/CFCHierarchy.c ---------------------------------------------------------------------- diff --git a/clownfish/compiler/src/CFCHierarchy.c b/clownfish/compiler/src/CFCHierarchy.c index e98a258..5e90c16 100644 --- a/clownfish/compiler/src/CFCHierarchy.c +++ b/clownfish/compiler/src/CFCHierarchy.c @@ -114,10 +114,10 @@ CFCHierarchy_init(CFCHierarchy *self, const char *dest) { self->num_classes = 0; self->parser = CFCParser_new(); - self->inc_dest = CFCUtil_cat(CFCUtil_strdup(""), self->dest, - CFCUTIL_PATH_SEP, "include", NULL); - self->src_dest = CFCUtil_cat(CFCUtil_strdup(""), self->dest, - CFCUTIL_PATH_SEP, "source", NULL); + self->inc_dest = CFCUtil_sprintf("%s" CFCUTIL_PATH_SEP "include", + self->dest); + self->src_dest = CFCUtil_sprintf("%s" CFCUTIL_PATH_SEP "source", + self->dest); S_do_make_path(self->inc_dest); S_do_make_path(self->src_dest); http://git-wip-us.apache.org/repos/asf/lucy/blob/cec0b47b/clownfish/compiler/src/CFCPerl.c ---------------------------------------------------------------------- diff --git a/clownfish/compiler/src/CFCPerl.c b/clownfish/compiler/src/CFCPerl.c index dd6d667..f7bc313 100644 --- a/clownfish/compiler/src/CFCPerl.c +++ b/clownfish/compiler/src/CFCPerl.c @@ -83,29 +83,23 @@ CFCPerl_init(CFCPerl *self, CFCParcel *parcel, CFCHierarchy *hierarchy, self->footer = CFCUtil_strdup(footer); // Derive path to generated .xs file. - self->xs_path = CFCUtil_cat(CFCUtil_strdup(""), lib_dir, CFCUTIL_PATH_SEP, - boot_class, ".xs", NULL); + self->xs_path = CFCUtil_sprintf("%s" CFCUTIL_PATH_SEP "%s.xs", lib_dir, + boot_class); S_replace_double_colons(self->xs_path, CFCUTIL_PATH_SEP_CHAR); // Derive the name of the files containing bootstrapping code. const char *prefix = CFCParcel_get_prefix(parcel); const char *inc_dest = CFCHierarchy_get_include_dest(hierarchy); const char *src_dest = CFCHierarchy_get_source_dest(hierarchy); - self->boot_h_file = CFCUtil_cat(CFCUtil_strdup(""), prefix, "boot.h", - NULL); - self->boot_c_file = CFCUtil_cat(CFCUtil_strdup(""), prefix, "boot.c", - NULL); - self->boot_h_path = CFCUtil_cat(CFCUtil_strdup(""), inc_dest, - CFCUTIL_PATH_SEP, self->boot_h_file, - NULL); - self->boot_c_path = CFCUtil_cat(CFCUtil_strdup(""), src_dest, - CFCUTIL_PATH_SEP, self->boot_c_file, - NULL); + self->boot_h_file = CFCUtil_sprintf("%sboot.h", prefix); + self->boot_c_file = CFCUtil_sprintf("%sboot.c", prefix); + self->boot_h_path = CFCUtil_sprintf("%s" CFCUTIL_PATH_SEP "%s", inc_dest, + self->boot_h_file); + self->boot_c_path = CFCUtil_sprintf("%s" CFCUTIL_PATH_SEP "%s", src_dest, + self->boot_c_file); // Derive the name of the bootstrap function. - self->boot_func - = CFCUtil_cat(CFCUtil_strdup(""), CFCParcel_get_prefix(parcel), - boot_class, "_bootstrap", NULL); + self->boot_func = CFCUtil_sprintf("%s%s_bootstrap", prefix, boot_class); for (int i = 0; self->boot_func[i] != 0; i++) { if (!isalnum(self->boot_func[i])) { self->boot_func[i] = '_'; @@ -162,9 +156,8 @@ CFCPerl_write_pod(CFCPerl *self) { const char *class_name = CFCPerlClass_get_class_name(registry[i]); char *pod = CFCPerlClass_create_pod(registry[i]); if (!pod) { continue; } - char *pod_path - = CFCUtil_cat(CFCUtil_strdup(""), self->lib_dir, CFCUTIL_PATH_SEP, - class_name, ".pod", NULL); + char *pod_path = CFCUtil_sprintf("%s" CFCUTIL_PATH_SEP "%s.pod", + self->lib_dir, class_name); S_replace_double_colons(pod_path, CFCUTIL_PATH_SEP_CHAR); pods[count] = pod; @@ -193,8 +186,7 @@ CFCPerl_write_pod(CFCPerl *self) { static void S_write_boot_h(CFCPerl *self) { - char *guard = CFCUtil_cat(CFCUtil_strdup(""), self->boot_class, - "_BOOT", NULL); + char *guard = CFCUtil_sprintf("%s_BOOT", self->boot_class); S_replace_double_colons(guard, '_'); for (char *ptr = guard; *ptr != '\0'; ptr++) { if (isalpha(*ptr)) { @@ -583,8 +575,8 @@ CFCPerl_write_callbacks(CFCPerl *self) { // Write if changed. const char *src_dest = CFCHierarchy_get_source_dest(self->hierarchy); - char *filepath = CFCUtil_cat(CFCUtil_strdup(""), src_dest, - CFCUTIL_PATH_SEP, "callbacks.c", NULL); + char *filepath = CFCUtil_sprintf("%s" CFCUTIL_PATH_SEP "callbacks.c", + src_dest); CFCUtil_write_if_changed(filepath, content, strlen(content)); FREEMEM(filepath); http://git-wip-us.apache.org/repos/asf/lucy/blob/cec0b47b/clownfish/compiler/src/CFCPerlPod.c ---------------------------------------------------------------------- diff --git a/clownfish/compiler/src/CFCPerlPod.c b/clownfish/compiler/src/CFCPerlPod.c index ae03305..d7a9c7e 100644 --- a/clownfish/compiler/src/CFCPerlPod.c +++ b/clownfish/compiler/src/CFCPerlPod.c @@ -276,7 +276,7 @@ CFCPerlPod_gen_subroutine_pod(CFCPerlPod *self, CFCFunction *func, CFCParamList *param_list = CFCFunction_get_param_list(func); int num_vars = CFCParamList_num_vars(param_list); - char *pod = CFCUtil_cat(CFCUtil_strdup(""), "=head2 ", alias, NULL); + char *pod = CFCUtil_sprintf("=head2 %s", alias); // Get documentation, which may be inherited. CFCDocuComment *docucomment = CFCFunction_get_docucomment(func); http://git-wip-us.apache.org/repos/asf/lucy/blob/cec0b47b/clownfish/compiler/src/CFCPerlSub.c ---------------------------------------------------------------------- diff --git a/clownfish/compiler/src/CFCPerlSub.c b/clownfish/compiler/src/CFCPerlSub.c index ccc9077..de38183 100644 --- a/clownfish/compiler/src/CFCPerlSub.c +++ b/clownfish/compiler/src/CFCPerlSub.c @@ -41,8 +41,7 @@ CFCPerlSub_init(CFCPerlSub *self, CFCParamList *param_list, self->class_name = CFCUtil_strdup(class_name); self->alias = CFCUtil_strdup(alias); self->use_labeled_params = use_labeled_params; - self->perl_name = CFCUtil_cat(CFCUtil_strdup(class_name), "::", alias, - NULL); + self->perl_name = CFCUtil_sprintf("%s::%s", class_name, alias); size_t c_name_len = strlen(self->perl_name) + sizeof("XS_") + 1; self->c_name = (char*)MALLOCATE(c_name_len); http://git-wip-us.apache.org/repos/asf/lucy/blob/cec0b47b/clownfish/compiler/src/CFCPerlTypeMap.c ---------------------------------------------------------------------- diff --git a/clownfish/compiler/src/CFCPerlTypeMap.c b/clownfish/compiler/src/CFCPerlTypeMap.c index 864ede4..ce05145 100644 --- a/clownfish/compiler/src/CFCPerlTypeMap.c +++ b/clownfish/compiler/src/CFCPerlTypeMap.c @@ -41,6 +41,7 @@ CFCPerlTypeMap_from_perl(CFCType *type, const char *xs_var) { if (CFCType_is_object(type)) { const char *struct_sym = CFCType_get_specifier(type); const char *vtable_var = CFCType_get_vtable_var(type); + const char *allocation; if (strcmp(struct_sym, "lucy_CharBuf") == 0 || strcmp(struct_sym, "cfish_CharBuf") == 0 || strcmp(struct_sym, "lucy_Obj") == 0 @@ -48,16 +49,14 @@ CFCPerlTypeMap_from_perl(CFCType *type, const char *xs_var) { ) { // Share buffers rather than copy between Perl scalars and // Clownfish string types. - result = CFCUtil_cat(CFCUtil_strdup(""), "(", struct_sym, - "*)XSBind_sv_to_cfish_obj(", xs_var, - ", ", vtable_var, - ", alloca(cfish_ZCB_size()))", NULL); + allocation = "alloca(cfish_ZCB_size())"; } else { - result = CFCUtil_cat(CFCUtil_strdup(""), "(", struct_sym, - "*)XSBind_sv_to_cfish_obj(", xs_var, - ", ", vtable_var, ", NULL)", NULL); + allocation = "NULL"; } + const char pattern[] = "(%s*)XSBind_sv_to_cfish_obj(%s, %s, %s)"; + result = CFCUtil_sprintf(pattern, struct_sym, xs_var, vtable_var, + allocation); } else if (CFCType_is_primitive(type)) { const char *specifier = CFCType_get_specifier(type); @@ -125,10 +124,9 @@ CFCPerlTypeMap_to_perl(CFCType *type, const char *cf_var) { char *result = NULL; if (CFCType_is_object(type)) { - result = CFCUtil_cat(CFCUtil_strdup(""), "(", cf_var, - " == NULL ? newSV(0) : " - "XSBind_cfish_to_perl((cfish_Obj*)", - cf_var, "))", NULL); + const char pattern[] = + "(%s == NULL ? newSV(0) : XSBind_cfish_to_perl((cfish_Obj*)%s))"; + result = CFCUtil_sprintf(pattern, cf_var, cf_var); } else if (CFCType_is_primitive(type)) { // Convert from a primitive type to a Perl scalar. @@ -195,8 +193,7 @@ CFCPerlTypeMap_to_perl(CFCType *type, const char *cf_var) { if (strcmp(type_str, "void*") == 0) { // Assume that void* is a reference SV -- either a hashref or an // arrayref. - result = CFCUtil_cat(CFCUtil_strdup(""), "newRV_inc((SV*)", - cf_var, ")", NULL); + result = CFCUtil_sprintf("newRV_inc((SV*)%s)", cf_var); } }
