From 4b54820525e3a294eee02f9590d0417e988dc5f9 Mon Sep 17 00:00:00 2001 From: Sven Verdoolaege Date: Sun, 23 May 2010 18:23:04 +0200 Subject: [PATCH] add isl_ctx_peek_options --- include/isl_ctx.h | 10 ++++++++++ isl_ctx.c | 23 ++++++++++++++++++----- 2 files changed, 28 insertions(+), 5 deletions(-) diff --git a/include/isl_ctx.h b/include/isl_ctx.h index ffe66b0..240120b 100644 --- a/include/isl_ctx.h +++ b/include/isl_ctx.h @@ -121,10 +121,20 @@ struct isl_options *isl_ctx_options(isl_ctx *ctx); isl_ctx *isl_ctx_alloc_with_options(struct isl_arg *arg, __isl_take void *opt); isl_ctx *isl_ctx_alloc(); +void *isl_ctx_peek_options(isl_ctx *ctx, struct isl_arg *arg); void isl_ctx_ref(struct isl_ctx *ctx); void isl_ctx_deref(struct isl_ctx *ctx); void isl_ctx_free(isl_ctx *ctx); +#define ISL_ARG_CTX_DECL(prefix,st,arg) \ +st *isl_ctx_peek_ ## prefix(isl_ctx *ctx); + +#define ISL_ARG_CTX_DEF(prefix,st,arg) \ +st *isl_ctx_peek_ ## prefix(isl_ctx *ctx) \ +{ \ + return (st *)isl_ctx_peek_options(ctx, arg); \ +} + #if defined(__cplusplus) } #endif diff --git a/isl_ctx.c b/isl_ctx.c index e844e56..dbda731 100644 --- a/isl_ctx.c +++ b/isl_ctx.c @@ -10,20 +10,20 @@ #include "isl_ctx.h" #include "isl_vec.h" -static struct isl_options *find_nested_isl_options(struct isl_arg *arg, - void *opt) +static struct isl_options *find_nested_options(struct isl_arg *arg, + void *opt, struct isl_arg *wanted) { int i; struct isl_options *options; - if (arg == isl_options_arg) + if (arg == wanted) 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)); + options = find_nested_options(arg[i].u.child.child, + *(void **)(((char *)opt) + arg->offset), wanted); if (options) return options; } @@ -31,6 +31,19 @@ static struct isl_options *find_nested_isl_options(struct isl_arg *arg, return NULL; } +static struct isl_options *find_nested_isl_options(struct isl_arg *arg, + void *opt) +{ + return find_nested_options(arg, opt, isl_options_arg); +} + +void *isl_ctx_peek_options(isl_ctx *ctx, struct isl_arg *arg) +{ + if (!ctx) + return NULL; + return find_nested_options(ctx->user_arg, ctx->user_opt, arg); +} + isl_ctx *isl_ctx_alloc_with_options(struct isl_arg *arg, void *user_opt) { struct isl_ctx *ctx = NULL; -- 2.7.4