assert(options);
argc = bound_options_parse(options, argc, argv, ISL_ARG_ALL);
- ctx = isl_ctx_alloc_with_options(options->isl);
+ ctx = isl_ctx_alloc_with_options(bound_options_arg, options);
options->isl = NULL;
s = isl_stream_new_file(ctx, stdin);
isl_stream_free(s);
isl_ctx_free(ctx);
- free(options);
return r;
}
assert(options);
argc = cat_options_parse(options, argc, argv, ISL_ARG_ALL);
- ctx = isl_ctx_alloc_with_options(options->isl);
- options->isl = NULL;
+ ctx = isl_ctx_alloc_with_options(cat_options_arg, options);
map = isl_map_read_from_file(ctx, stdin, -1);
isl_map_print(map, stdout, 0, options->format);
isl_map_free(map);
isl_ctx_free(ctx);
- free(options);
return 0;
}
assert(options);
argc = isl_options_parse(options, argc, argv, ISL_ARG_ALL);
- ctx = isl_ctx_alloc_with_options(options);
+ ctx = isl_ctx_alloc_with_options(isl_options_arg, options);
map = isl_map_read_from_file(ctx, stdin, -1);
map = isl_map_transitive_closure(map, &exact);
struct isl_stats *stats;
+ int opt_allocated;
struct isl_options *opt;
+ void *user_opt;
+ struct isl_arg *user_arg;
isl_int zero;
isl_int one;
struct isl_options *isl_ctx_options(isl_ctx *ctx);
-isl_ctx *isl_ctx_alloc_with_options(struct isl_options *opt);
+isl_ctx *isl_ctx_alloc_with_options(struct isl_arg *arg, __isl_take void *opt);
isl_ctx *isl_ctx_alloc();
void isl_ctx_ref(struct isl_ctx *ctx);
void isl_ctx_deref(struct isl_ctx *ctx);
#include "isl_ctx.h"
#include "isl_vec.h"
-isl_ctx *isl_ctx_alloc_with_options(struct isl_options *opt)
+static struct isl_options *find_nested_isl_options(struct isl_arg *arg,
+ void *opt)
+{
+ int i;
+ struct isl_options *options;
+
+ if (arg == isl_options_arg)
+ return opt;
+
+ for (i = 0; arg[i].type != isl_arg_end; ++i) {
+ if (arg[i].type != isl_arg_child)
+ continue;
+ options = find_nested_isl_options(arg[i].u.child.child,
+ *(void **)(((char *)opt) + arg->offset));
+ if (options)
+ return options;
+ }
+
+ return NULL;
+}
+
+isl_ctx *isl_ctx_alloc_with_options(struct isl_arg *arg, void *user_opt)
{
struct isl_ctx *ctx = NULL;
+ struct isl_options *opt = NULL;
+ int opt_allocated = 0;
- if (!opt)
+ if (!user_opt)
return NULL;
+ opt = find_nested_isl_options(arg, user_opt);
+ if (!opt) {
+ opt = isl_options_new_with_defaults();
+ if (!opt)
+ goto error;
+ opt_allocated = 1;
+ }
+
ctx = isl_calloc_type(NULL, struct isl_ctx);
if (!ctx)
goto error;
if (!ctx->stats)
goto error;
+ ctx->user_arg = arg;
+ ctx->user_opt = user_opt;
+ ctx->opt_allocated = opt_allocated;
ctx->opt = opt;
ctx->ref = 0;
return ctx;
error:
+ isl_arg_free(arg, user_opt);
+ if (opt_allocated)
+ isl_options_free(opt);
free(ctx);
return NULL;
}
opt = isl_options_new_with_defaults();
- return isl_ctx_alloc_with_options(opt);
+ return isl_ctx_alloc_with_options(isl_options_arg, opt);
}
void isl_ctx_ref(struct isl_ctx *ctx)
isl_int_clear(ctx->one);
isl_int_clear(ctx->negone);
isl_int_clear(ctx->normalize_gcd);
- free(ctx->opt);
+ isl_arg_free(ctx->user_arg, ctx->user_opt);
+ if (ctx->opt_allocated)
+ free(ctx->opt);
free(ctx->stats);
free(ctx);
}
assert(options);
argc = pip_options_parse(options, argc, argv, ISL_ARG_ALL);
- ctx = isl_ctx_alloc_with_options(options->isl);
- options->isl = NULL;
+ ctx = isl_ctx_alloc_with_options(pip_options_arg, options);
context = isl_basic_set_read_from_file(ctx, stdin, 0);
assert(context);
isl_set_free(set);
isl_set_free(empty);
isl_ctx_free(ctx);
- free(options);
return 0;
}