Convert from macro

This makes everything cleaner since the macro was only used in one place, defeating the purpose.
This commit is contained in:
Justin Ethier 2021-03-13 23:07:21 -05:00
parent ed21350bf5
commit 27484cd4a4

View file

@ -2573,38 +2573,6 @@ object Cyc_string_cmp(void *data, object str1, object str2)
((string_type *) str2)->str));
}
#define Cyc_string_append_va_list(data, argc) { \
int i = 0, total_cp = 0, total_len = 1; \
int *len = alloca(sizeof(int) * argc); \
char *buffer, *bufferp, **str = alloca(sizeof(char *) * argc); \
object tmp; \
if (argc > 0) { \
Cyc_check_str(data, str1); \
str[i] = ((string_type *)str1)->str; \
len[i] = string_len((str1)); \
total_len += len[i]; \
total_cp += string_num_cp((str1)); \
} \
for (i = 1; i < argc; i++) { \
tmp = va_arg(ap, object); \
Cyc_check_str(data, tmp); \
str[i] = ((string_type *)tmp)->str; \
len[i] = string_len((tmp)); \
total_len += len[i]; \
total_cp += string_num_cp((tmp)); \
} \
buffer = bufferp = alloca(sizeof(char) * total_len); \
for (i = 0; i < argc; i++) { \
memcpy(bufferp, str[i], len[i]); \
bufferp += len[i]; \
} \
*bufferp = '\0'; \
make_string(result, buffer); \
string_num_cp((&result)) = total_cp; \
va_end(ap); \
_return_closcall1(data, cont, &result); \
}
void dispatch_string_91append(void *data, object clo, int _argc, object *_args)
{
int argc = _argc - 1; // Skip continuation
@ -2632,11 +2600,39 @@ void dispatch_string_91append(void *data, object clo, int _argc, object *_args)
return_closcall1(data, clo, &result);
}
object Cyc_string_append(void *data, object cont, int _argc, object str1, ...)
object Cyc_string_append(void *data, object cont, int argc, object str1, ...)
{
va_list ap;
va_start(ap, str1);
Cyc_string_append_va_list(data, _argc);
int i = 0, total_cp = 0, total_len = 1;
int *len = alloca(sizeof(int) * argc);
char *buffer, *bufferp, **str = alloca(sizeof(char *) * argc);
object tmp;
if (argc > 0) {
Cyc_check_str(data, str1);
str[i] = ((string_type *)str1)->str;
len[i] = string_len((str1));
total_len += len[i];
total_cp += string_num_cp((str1));
}
for (i = 1; i < argc; i++) {
tmp = va_arg(ap, object);
Cyc_check_str(data, tmp);
str[i] = ((string_type *)tmp)->str;
len[i] = string_len((tmp));
total_len += len[i];
total_cp += string_num_cp((tmp));
}
buffer = bufferp = alloca(sizeof(char) * total_len);
for (i = 0; i < argc; i++) {
memcpy(bufferp, str[i], len[i]);
bufferp += len[i];
}
*bufferp = '\0';
make_string(result, buffer);
string_num_cp((&result)) = total_cp;
va_end(ap);
_return_closcall1(data, cont, &result);
}
object Cyc_string_length(void *data, object str)