X-Git-Url: https://git.dlugolecki.net.pl/?a=blobdiff_plain;f=gom%2Fgom_internal.h;h=3c604a2eb653ce4656b3adda2c92a39c9acceb58;hb=473f146038f88434e3edd070dfa42390bd0df60f;hp=9f1e6ea03c9556bc4826129352295ae643cdf259;hpb=d8d5e051c5e0917e639a9320e9a4a01d6f0e83b3;p=gedcom-parse.git diff --git a/gom/gom_internal.h b/gom/gom_internal.h index 9f1e6ea..3c604a2 100644 --- a/gom/gom_internal.h +++ b/gom/gom_internal.h @@ -57,22 +57,15 @@ typedef enum { T_LAST } OBJ_TYPE; -/* Assumptions for context: - - In case of error, NULL is passed as context - - If not NULL, the ctxt_ptr of the context is not NULL also - - UNEXPECTED_CONTEXT is not treated as an error, but as a warning -*/ - -struct Gom_ctxt_struct { - int ctxt_type; - OBJ_TYPE obj_type; - void* ctxt_ptr; -}; - +struct Gom_ctxt_struct; typedef struct Gom_ctxt_struct *Gom_ctxt; Gom_ctxt make_gom_ctxt(int ctxt_type, OBJ_TYPE obj_type, void *ctxt_ptr); -void destroy_gom_ctxt(Gom_ctxt ctxt); +Gom_ctxt dup_gom_ctxt(Gom_ctxt ctxt, int ctxt_type); +void* safe_ctxt_cast(Gom_ctxt ctxt, OBJ_TYPE type, const char* file, int line); +int ctxt_type(Gom_ctxt ctxt); +OBJ_TYPE ctxt_obj_type(Gom_ctxt ctxt); + void gom_cast_error(const char* file, int line, OBJ_TYPE expected, OBJ_TYPE found); void gom_no_context(const char* file, int line); @@ -90,10 +83,7 @@ int gom_write_xref_list(Gedcom_write_hndl hndl, make_gom_ctxt(CTXT_TYPE, T_ ## STRUCTTYPE, CTXT_PTR) #define SAFE_CTXT_CAST(STRUCTTYPE, VAL) \ - (((VAL)->obj_type == T_ ## STRUCTTYPE) ? \ - (VAL)->ctxt_ptr : \ - (gom_cast_error(__FILE__, __LINE__, T_ ## STRUCTTYPE, (VAL)->obj_type), \ - (VAL)->ctxt_ptr)) + safe_ctxt_cast(VAL, T_ ## STRUCTTYPE, __FILE__, __LINE__) #define SAFE_FREE(PTR) \ if (PTR) { \