summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authormidipix <writeonce@midipix.org>2016-10-26 21:39:52 -0400
committermidipix <writeonce@midipix.org>2016-10-26 22:10:37 -0400
commit4671adc25c3fbfcbd819178632cd5e7857810ac0 (patch)
treead65edf347e7bc0ca68cf00a227fdda2f48f49c0 /src
parenta55d2226a03eef7084bc8adf2f9b318549541f7b (diff)
downloadapimagic-4671adc25c3fbfcbd819178632cd5e7857810ac0.tar.bz2
apimagic-4671adc25c3fbfcbd819178632cd5e7857810ac0.tar.xz
amgc_get_unit_ctx(): added error trace support.
Diffstat (limited to 'src')
-rw-r--r--src/driver/amgc_unit_ctx.c34
1 files changed, 25 insertions, 9 deletions
diff --git a/src/driver/amgc_unit_ctx.c b/src/driver/amgc_unit_ctx.c
index 54824e1..cfc2c0b 100644
--- a/src/driver/amgc_unit_ctx.c
+++ b/src/driver/amgc_unit_ctx.c
@@ -18,8 +18,9 @@
#include <apimagic/apimagic.h>
#include "apimagic_driver_impl.h"
+#include "apimagic_errinfo_impl.h"
-static int amgc_free_unit_ctx_impl(struct amgc_unit_ctx_impl * ctx, int status)
+static int amgc_free_unit_ctx_impl(struct amgc_unit_ctx_impl * ctx, int ret)
{
if (ctx) {
if (ctx->entities)
@@ -29,7 +30,7 @@ static int amgc_free_unit_ctx_impl(struct amgc_unit_ctx_impl * ctx, int status)
free(ctx);
}
- return status;
+ return ret;
}
static FILE * amgc_stdin_to_tmp(const struct amgc_driver_ctx * dctx)
@@ -120,20 +121,33 @@ int amgc_get_unit_ctx(
amgc_init_cparser_unit();
- if (!dctx || !(ctx = calloc(1,sizeof(*ctx))))
- return -1;
+ if (!dctx)
+ return AMGC_CUSTOM_ERROR(
+ dctx,AMGC_ERR_NULL_CONTEXT);
+
+ else if (!(ctx = calloc(1,sizeof(*ctx))))
+ return AMGC_SYSTEM_ERROR(dctx);
+
+ amgc_driver_set_ectx(
+ dctx,0,path);
if (strcmp(path,"-"))
fd = -1;
+
else if (!(ftmp = amgc_stdin_to_tmp(dctx)))
- return amgc_free_unit_ctx_impl(ctx,-1);
+ return amgc_free_unit_ctx_impl(
+ ctx,AMGC_SYSTEM_ERROR(dctx));
+
else if ((fd = dup(fileno(ftmp))) < 0)
- return amgc_free_unit_ctx_impl(ctx,-1);
+ return amgc_free_unit_ctx_impl(
+ ctx,AMGC_SYSTEM_ERROR(dctx));
+
else
ctx->ccunit.input = ftmp;
if (amgc_map_input(dctx,fd,path,PROT_READ,&ctx->map))
- return amgc_free_unit_ctx_impl(ctx,-1);
+ return amgc_free_unit_ctx_impl(
+ ctx,AMGC_NESTED_ERROR(dctx));
if (fd > 0)
close(fd);
@@ -148,7 +162,8 @@ int amgc_get_unit_ctx(
if ((process_unit(ctx->cctx.ccenv,&ctx->ccunit)) == false) {
if (ctx->ccunit.input)
fclose(ctx->ccunit.input);
- return amgc_free_unit_ctx_impl(ctx,-1);
+ return amgc_free_unit_ctx_impl(
+ ctx,AMGC_CUSTOM_ERROR(dctx,AMGC_ERR_FLOW_ERROR));
}
memcpy(&ctx->cctx,dctx->cctx,
@@ -162,7 +177,8 @@ int amgc_get_unit_ctx(
ctx->uctx.ccunit = &ctx->ccunit;
if (amgc_get_unit_entities(&ctx->uctx,&ctx->meta,&ctx->entities))
- return amgc_free_unit_ctx_impl(ctx,-1);
+ return amgc_free_unit_ctx_impl(
+ ctx,AMGC_CUSTOM_ERROR(dctx,AMGC_ERR_FLOW_ERROR));
ctx->uctx.entities = ctx->entities;
*pctx = &ctx->uctx;