return NULL;
v = make_value(V_EXN, ref(info));
- CALLOC(v->exn, 1);
+ if (ALLOC(v->exn) < 0)
+ return info->error->exn;
v->exn->info = info;
v->exn->message = message;
if (vt->tag == T_STRING && t->tag == T_REGEXP) {
struct value *rxp = make_value(V_REGEXP, ref(v->info));
rxp->regexp = make_regexp_literal(v->info, v->string->str);
+ if (rxp->regexp == NULL) {
+ report_error(v->info->error, AUG_ENOMEM, NULL);
+ };
unref(v, value);
unref(vt, type);
return rxp;
}
len += (ntypes - 1) * 4 + 1;
char *allowed_names;
- CALLOC(allowed_names, len);
+ if (ALLOC_N(allowed_names, len) < 0)
+ return NULL;
for (int i=0; i < ntypes; i++) {
if (i > 0)
strcat(allowed_names, (i == ntypes - 1) ? ", or " : ", ");
static struct value *native_call(struct info *info,
struct native *func, struct ctx *ctx) {
- struct value *argv[func->argc];
+ struct value *argv[func->argc + 1];
struct binding *b = ctx->local;
- struct value *result;
for (int i = func->argc - 1; i >= 0; i--) {
argv[i] = b->value;
b = b->next;
}
+ argv[func->argc] = NULL;
- switch(func->argc) {
- case 0:
- result = ((impl0) *func->impl)(info);
- break;
- case 1:
- result = ((impl1) *func->impl)(info, argv[0]);
- break;
- case 2:
- result = ((impl2) *func->impl)(info, argv[0], argv[1]);
- break;
- case 3:
- result = ((impl3) *func->impl)(info, argv[0], argv[1], argv[2]);
- break;
- case 4:
- result = ((impl4) *func->impl)(info, argv[0], argv[1], argv[2], argv[3]);
- break;
- case 5:
- result = ((impl5) *func->impl)(info, argv[0], argv[1], argv[2], argv[3],
- argv[4]);
- break;
- default:
- assert(0);
- abort();
- break;
- }
-
- return result;
+ return func->impl(info, argv);
}
static void type_error1(struct info *info, const char *msg, struct type *type) {
const char *s2 = v2->string->str;
v = make_value(V_STRING, ref(info));
make_ref(v->string);
- CALLOC(v->string->str, strlen(s1) + strlen(s2) + 1);
+ if (ALLOC_N(v->string->str, strlen(s1) + strlen(s2) + 1) < 0)
+ goto error;
char *s = v->string->str;
strcpy(s, s1);
strcat(s, s2);
unref(v1, value);
unref(v2, value);
return v;
+ error:
+ return exp->info->error->exn;
}
static struct value *apply(struct term *app, struct ctx *ctx) {
int define_native_intl(const char *file, int line,
struct error *error,
struct module *module, const char *name,
- int argc, void *impl, ...) {
+ int argc, func_impl impl, ...) {
assert(argc > 0); /* We have no unit type */
assert(argc <= 5);
va_list ap;
for (int i=0; i < globbuf.gl_pathc; i++) {
char *name, *p, *q;
+ int res;
p = strrchr(globbuf.gl_pathv[i], SEP);
if (p == NULL)
p = globbuf.gl_pathv[i];
q = strchr(p, '.');
name = strndup(p, q - p);
name[0] = toupper(name[0]);
- if (load_module(aug, name) == -1)
- goto error;
+ res = load_module(aug, name);
free(name);
+ if (res == -1)
+ goto error;
}
globfree(&globbuf);
return 0;