From: havoc Date: Mon, 9 May 2011 13:32:31 +0000 (+0000) Subject: added debugging code for PRVM_EDICTFIELD*/PRVM_GLOBALFIELD* macros, X-Git-Tag: xonotic-v0.5.0~185 X-Git-Url: https://git.rm.cloudns.org/?a=commitdiff_plain;h=532f07cc96cafba6c0f2d57d5fd87c2268a92667;p=xonotic%2Fdarkplaces.git added debugging code for PRVM_EDICTFIELD*/PRVM_GLOBALFIELD* macros, these now warn if the fieldoffset is invalid, and do not crash git-svn-id: svn://svn.icculus.org/twilight/trunk/darkplaces@11140 d7cf8633-e32d-0410-b094-e92efae38249 ::stable-branch::merge=01fb45d86cd8443142099a9b3064c26908ba3c69 --- diff --git a/progsvm.h b/progsvm.h index 5dead05e..e4f8e12d 100644 --- a/progsvm.h +++ b/progsvm.h @@ -115,6 +115,22 @@ typedef struct prvm_edict_s } fields; } prvm_edict_t; +extern prvm_eval_t prvm_badvalue; + +#if 1 +#define PRVM_EDICTFIELDVALUE(ed, fieldoffset) (fieldoffset < 0 ? Con_Printf("Invalid fieldoffset at %s:%i\n", __FILE__, __LINE__), &prvm_badvalue : (prvm_eval_t *)((int *)ed->fields.vp + fieldoffset)) +#define PRVM_EDICTFIELDFLOAT(ed, fieldoffset) (PRVM_EDICTFIELDVALUE(ed, fieldoffset)->_float) +#define PRVM_EDICTFIELDVECTOR(ed, fieldoffset) (PRVM_EDICTFIELDVALUE(ed, fieldoffset)->vector) +#define PRVM_EDICTFIELDSTRING(ed, fieldoffset) (PRVM_EDICTFIELDVALUE(ed, fieldoffset)->string) +#define PRVM_EDICTFIELDEDICT(ed, fieldoffset) (PRVM_EDICTFIELDVALUE(ed, fieldoffset)->edict) +#define PRVM_EDICTFIELDFUNCTION(ed, fieldoffset) (PRVM_EDICTFIELDVALUE(ed, fieldoffset)->function) +#define PRVM_GLOBALFIELDVALUE(fieldoffset) (fieldoffset < 0 ? Con_Printf("Invalid fieldoffset at %s:%i\n", __FILE__, __LINE__), &prvm_badvalue : (prvm_eval_t *)((int *)prog->globals.generic + fieldoffset)) +#define PRVM_GLOBALFIELDFLOAT(fieldoffset) (PRVM_GLOBALFIELDVALUE(fieldoffset)->_float) +#define PRVM_GLOBALFIELDVECTOR(fieldoffset) (PRVM_GLOBALFIELDVALUE(fieldoffset)->vector) +#define PRVM_GLOBALFIELDSTRING(fieldoffset) (PRVM_GLOBALFIELDVALUE(fieldoffset)->string) +#define PRVM_GLOBALFIELDEDICT(fieldoffset) (PRVM_GLOBALFIELDVALUE(fieldoffset)->edict) +#define PRVM_GLOBALFIELDFUNCTION(fieldoffset) (PRVM_GLOBALFIELDVALUE(fieldoffset)->function) +#else #define PRVM_EDICTFIELDVALUE(ed, fieldoffset) ((prvm_eval_t *)((int *)ed->fields.vp + fieldoffset)) #define PRVM_EDICTFIELDFLOAT(ed, fieldoffset) (((prvm_eval_t *)((int *)ed->fields.vp + fieldoffset))->_float) #define PRVM_EDICTFIELDVECTOR(ed, fieldoffset) (((prvm_eval_t *)((int *)ed->fields.vp + fieldoffset))->vector) @@ -127,6 +143,7 @@ typedef struct prvm_edict_s #define PRVM_GLOBALFIELDSTRING(fieldoffset) (((prvm_eval_t *)((int *)prog->globals.generic + fieldoffset))->string) #define PRVM_GLOBALFIELDEDICT(fieldoffset) (((prvm_eval_t *)((int *)prog->globals.generic + fieldoffset))->edict) #define PRVM_GLOBALFIELDFUNCTION(fieldoffset) (((prvm_eval_t *)((int *)prog->globals.generic + fieldoffset))->function) +#endif //============================================================================ #define PRVM_OP_STATE 1