Eliminate some temporary buffers

This commit is contained in:
Olly Betts 2022-03-03 12:27:04 +13:00
commit 5755f399a2
3 changed files with 6 additions and 25 deletions

View file

@ -981,27 +981,14 @@ String *CFFI::lispify_name(Node *n, String *ty, const char *flag, bool kw) {
/* utilities */
/* returns new string w/ parens stripped */
String *CFFI::strip_parens(String *string) {
char *s = Char(string), *p;
char *s = Char(string);
int len = Len(string);
String *res;
if (len == 0 || s[0] != '(' || s[len - 1] != ')') {
return NewString(string);
}
p = (char *) malloc(len - 2 + 1);
if (!p) {
Printf(stderr, "Malloc failed\n");
SWIG_exit(EXIT_FAILURE);
}
strncpy(p, s + 1, len - 1);
p[len - 2] = 0; /* null terminate */
res = NewString(p);
free(p);
return res;
return NewStringWithSize(s + 1, len - 2);
}
String *CFFI::trim(String *str) {

View file

@ -947,20 +947,16 @@ public:
if (!is_setter) {
/* Strip off "-get" */
char *pws_name = (char *) malloc(sizeof(char) * (len - 3));
strncpy(pws_name, pc, len - 3);
pws_name[len - 4] = 0;
if (struct_member == 2) {
/* There was a setter, so create a procedure with setter */
Printf(f_init, "scm_c_define");
Printf(f_init, "(\"%s\", " "scm_make_procedure_with_setter(getter, setter));\n", pws_name);
Printf(f_init, "(\"%.*s\", " "scm_make_procedure_with_setter(getter, setter));\n", pc, len - 4);
} else {
/* There was no setter, so make an alias to the getter */
Printf(f_init, "scm_c_define");
Printf(f_init, "(\"%s\", getter);\n", pws_name);
Printf(f_init, "(\"%.*s\", getter);\n", pc, len - 4);
}
Printf(exported_symbols, "\"%s\", ", pws_name);
free(pws_name);
Printf(exported_symbols, "\"%.*s\", ", pc, len - 4);
}
} else {
/* Register the function */

View file

@ -471,9 +471,7 @@ static void getoptions(int argc, char *argv[]) {
Swig_mark_arg(i);
} else if (strncmp(argv[i], "-I", 2) == 0) {
// Add a new directory search path
char *a = Swig_copy_string(argv[i] + 2);
Swig_add_directory((DOH *) a);
free(a);
Swig_add_directory((String_or_char*)(argv[i] + 2));
Swig_mark_arg(i);
} else if (strncmp(argv[i], "-D", 2) == 0) {
String *d = NewString(argv[i] + 2);