From 21cf63687536dd166c0f8b2fa2e6bd3fa59604d0 Mon Sep 17 00:00:00 2001 From: Bill Currie Date: Mon, 20 Jan 2025 20:57:54 +0900 Subject: [PATCH] [qtypes] Remove field_offset macro And use offsetof instead: it has been standard (enough) in C for a while. --- include/QF/progs.h | 6 ++-- include/QF/qtypes.h | 3 -- libs/audio/renderer/snd_mem.c | 2 +- libs/models/alias/model_alias.c | 8 ++--- libs/models/brush/gl_model_brush.c | 2 +- libs/models/sprite/model_sprite.c | 6 ++-- libs/models/sprite/sw_model_sprite.c | 2 +- libs/util/hash.c | 2 +- libs/video/renderer/crosshair.c | 2 +- libs/video/renderer/font8x8.c | 2 +- libs/video/renderer/gl/gl_draw.c | 2 +- libs/video/renderer/gl/gl_rsurf.c | 2 +- libs/video/renderer/glsl/glsl_alias.c | 12 +++---- libs/video/renderer/glsl/glsl_bsp.c | 10 +++--- libs/video/renderer/glsl/glsl_draw.c | 4 +-- libs/video/renderer/sw/d_surf.c | 2 +- libs/video/renderer/sw/draw.c | 2 +- .../renderer/vulkan/vkgen/vkfieldarray.r | 4 +-- .../video/renderer/vulkan/vkgen/vkfieldauto.r | 4 +-- .../renderer/vulkan/vkgen/vkfieldcustom.r | 4 +-- .../video/renderer/vulkan/vkgen/vkfielddata.r | 4 +-- libs/video/renderer/vulkan/vkgen/vkfielddef.r | 2 +- .../renderer/vulkan/vkgen/vkfieldreadonly.r | 2 +- .../renderer/vulkan/vkgen/vkfieldsingle.r | 2 +- .../renderer/vulkan/vkgen/vkfieldstring.r | 2 +- libs/video/renderer/vulkan/vkgen/vkstruct.r | 4 +-- libs/video/renderer/vulkan/vkparse.c | 2 +- libs/video/renderer/vulkan/vulkan_alias.c | 32 +++++++++---------- libs/video/renderer/vulkan/vulkan_bsp.c | 8 ++--- libs/video/renderer/vulkan/vulkan_draw.c | 4 +-- libs/video/renderer/vulkan/vulkan_iqm.c | 32 +++++++++---------- libs/video/renderer/vulkan/vulkan_lighting.c | 6 ++-- libs/video/renderer/vulkan/vulkan_particles.c | 4 +-- qw/source/sv_ccmds.c | 4 +-- tools/qfbsp/source/info.c | 2 +- tools/qfbsp/source/tjunc.c | 3 +- tools/qfcc/include/expr.h | 2 +- tools/qfcc/source/expr_bool.c | 4 +-- tools/qfcc/source/obj_type.c | 6 ++-- tools/qfcc/source/value.c | 4 +-- tools/qfvis/source/qfvis.c | 4 +-- 41 files changed, 105 insertions(+), 109 deletions(-) diff --git a/include/QF/progs.h b/include/QF/progs.h index 8070cf543..3cb3c3d86 100644 --- a/include/QF/progs.h +++ b/include/QF/progs.h @@ -119,9 +119,9 @@ typedef struct pr_stashed_params_s { */ #define PR_SaveParams(pr) \ _PR_SaveParams((pr), \ - alloca (field_offset (pr_stashed_params_t, \ - params[(pr)->pr_argc \ - * (pr)->pr_param_size]))) + alloca (offsetof (pr_stashed_params_t, \ + params[(pr)->pr_argc \ + * (pr)->pr_param_size]))) /** [INTERNAL] Save the current parameters to the provided stash. diff --git a/include/QF/qtypes.h b/include/QF/qtypes.h index 14eaada42..194db3752 100644 --- a/include/QF/qtypes.h +++ b/include/QF/qtypes.h @@ -45,9 +45,6 @@ #undef countof #define countof(x) (sizeof(x)/sizeof(x[0])) -#undef field_offset -#define field_offset(type,field) ((size_t)&(((type *)0)->field)) - #define MAX_QPATH 64 #ifndef _DEF_BYTE_ diff --git a/libs/audio/renderer/snd_mem.c b/libs/audio/renderer/snd_mem.c index 7dfd86e9a..5838dc89c 100644 --- a/libs/audio/renderer/snd_mem.c +++ b/libs/audio/renderer/snd_mem.c @@ -114,7 +114,7 @@ SND_Memory_Init (void) sfxbuffer_t * SND_Memory_AllocBuffer (unsigned samples) { - size_t size = field_offset (sfxbuffer_t, data[samples]); + size_t size = offsetof (sfxbuffer_t, data[samples]); // Z_Malloc (currently) clears memory, don't need that for the whole // buffer (just the header), but Z_TagMalloc // does not // +4 for sentinel diff --git a/libs/models/alias/model_alias.c b/libs/models/alias/model_alias.c index 0c89e2d65..eb9293e12 100644 --- a/libs/models/alias/model_alias.c +++ b/libs/models/alias/model_alias.c @@ -88,7 +88,7 @@ Mod_LoadAllSkins (mod_alias_ctx_t *alias_ctx, int numskins, pinskingroup = (daliasskingroup_t *) pskintype; groupskins = LittleLong (pinskingroup->numskins); - t = field_offset (maliasskingroup_t, skindescs[groupskins]); + t = offsetof (maliasskingroup_t, skindescs[groupskins]); paliasskingroup = Hunk_AllocName (0, t, alias_ctx->mod->name); paliasskingroup->numskins = groupskins; @@ -185,8 +185,8 @@ Mod_LoadAliasGroup (mod_alias_ctx_t *alias_ctx, void *pin, int *posenum, frame->firstpose = (*posenum); frame->numposes = numframes; - paliasgroup = Hunk_AllocName (0, field_offset (maliasgroup_t, - frames[numframes]), + paliasgroup = Hunk_AllocName (0, offsetof (maliasgroup_t, + frames[numframes]), mod->name); paliasgroup->numframes = numframes; frame->frame = (byte *) paliasgroup - (byte *) header; @@ -263,7 +263,7 @@ Mod_LoadAliasModel (model_t *mod, void *buffer, cache_allocator_t allocator) // allocate space for a working header, plus all the data except the // frame data, skin and group info - size = field_offset (aliashdr_t, frames[LittleLong (pinmodel->numframes)]); + size = offsetof (aliashdr_t, frames[LittleLong (pinmodel->numframes)]); header = Hunk_AllocName (0, size, mod->name); memset (header, 0, size); alias_ctx.header = header; diff --git a/libs/models/brush/gl_model_brush.c b/libs/models/brush/gl_model_brush.c index 9a1e3a857..991e55dae 100644 --- a/libs/models/brush/gl_model_brush.c +++ b/libs/models/brush/gl_model_brush.c @@ -280,7 +280,7 @@ SubdividePolygon (int numverts, float *verts) return; } - poly = Hunk_Alloc (0, field_offset (glpoly_t, verts[numverts])); + poly = Hunk_Alloc (0, offsetof (glpoly_t, verts[numverts])); poly->next = warpface->polys; warpface->polys = poly; poly->numverts = numverts; diff --git a/libs/models/sprite/model_sprite.c b/libs/models/sprite/model_sprite.c index 1bd9ca2cc..f5819fa53 100644 --- a/libs/models/sprite/model_sprite.c +++ b/libs/models/sprite/model_sprite.c @@ -123,7 +123,7 @@ find_group_frames (mspritegroup_t **group, dspritegroup_t *dgroup, int *frame_numbers, const char *modname) { int numframes = dgroup->numframes; - size_t size = field_offset (mspritegroup_t, frames[numframes]); + size_t size = offsetof (mspritegroup_t, frames[numframes]); *group = Hunk_AllocName (0, size, modname); (*group)->numframes = numframes; (*group)->intervals = Hunk_AllocName (0, numframes * sizeof (float), @@ -193,8 +193,8 @@ Mod_LoadSpriteModel (model_t *mod, void *buffer) Sys_Error ("Mod_LoadSpriteModel: Invalid # of frames: %d", numframes); } - sprite = Hunk_AllocName (0, field_offset (msprite_t, - frames[dsprite->numframes]), + sprite = Hunk_AllocName (0, offsetof (msprite_t, + frames[dsprite->numframes]), mod->name); sprite->type = dsprite->type; sprite->beamlength = dsprite->beamlength; diff --git a/libs/models/sprite/sw_model_sprite.c b/libs/models/sprite/sw_model_sprite.c index 6834413e9..496c8351b 100644 --- a/libs/models/sprite/sw_model_sprite.c +++ b/libs/models/sprite/sw_model_sprite.c @@ -42,7 +42,7 @@ sw_Mod_SpriteLoadFrames (mod_sprite_ctx_t *ctx) for (int i = 0; i < ctx->numframes; i++) { __auto_type dframe = ctx->dframes[i]; size_t pixels = dframe->width * dframe->height; - size_t size = field_offset (mspriteframe_t, pixels[pixels]); + size_t size = offsetof (mspriteframe_t, pixels[pixels]); mspriteframe_t *frame = Hunk_AllocName (0, size, ctx->mod->name); *ctx->frames[i] = frame; Mod_LoadSpriteFrame (frame, dframe); diff --git a/libs/util/hash.c b/libs/util/hash.c index 28bf9a93f..9e253e859 100644 --- a/libs/util/hash.c +++ b/libs/util/hash.c @@ -244,7 +244,7 @@ VISIBLE hashtab_t * Hash_NewTable (int tsize, const char *(*gk)(const void*,void*), void (*f)(void*,void*), void *ud, hashctx_t **hctx) { - hashtab_t *tab = calloc (1, field_offset (hashtab_t, tab[tsize])); + hashtab_t *tab = calloc (1, offsetof (hashtab_t, tab[tsize])); if (!tab) return 0; tab->tab_size = tsize; diff --git a/libs/video/renderer/crosshair.c b/libs/video/renderer/crosshair.c index 60b237a1b..d15c6eb47 100644 --- a/libs/video/renderer/crosshair.c +++ b/libs/video/renderer/crosshair.c @@ -87,7 +87,7 @@ Draw_CrosshairPic (void) byte *data; int i, j, x, y, ind; - pic = malloc (field_offset (qpic_t, data[sizeof (crosshair_data)])); + pic = malloc (offsetof (qpic_t, data[sizeof (crosshair_data)])); pic->width = CROSSHAIR_TILEX * CROSSHAIR_WIDTH; pic->height = CROSSHAIR_TILEY * CROSSHAIR_HEIGHT; // re-arrange the crosshair_data bytes so they're layed out properly for diff --git a/libs/video/renderer/font8x8.c b/libs/video/renderer/font8x8.c index ab78882a5..de059b046 100644 --- a/libs/video/renderer/font8x8.c +++ b/libs/video/renderer/font8x8.c @@ -312,7 +312,7 @@ Draw_Font8x8Pic (void) byte *out; int i, j, x, y, ind; - pic = calloc (1, field_offset (qpic_t, data[FONT_BYTES])); + pic = calloc (1, offsetof (qpic_t, data[FONT_BYTES])); pic->width = FONT_HCHARS * FONT_WIDTH; pic->height = FONT_VCHARS * FONT_HEIGHT; // convert the bitmap data to pixel data in a 16x16 character "image" diff --git a/libs/video/renderer/gl/gl_draw.c b/libs/video/renderer/gl/gl_draw.c index 9e4cd9a0c..f0c8aaaa6 100644 --- a/libs/video/renderer/gl/gl_draw.c +++ b/libs/video/renderer/gl/gl_draw.c @@ -172,7 +172,7 @@ gl_Draw_MakePic (int width, int height, const byte *data) glpic_t *gl; qpic_t *pic; - pic = malloc (field_offset (qpic_t, data[sizeof (glpic_t)])); + pic = malloc (offsetof (qpic_t, data[sizeof (glpic_t)])); pic->width = width; pic->height = height; gl = (glpic_t *) pic->data; diff --git a/libs/video/renderer/gl/gl_rsurf.c b/libs/video/renderer/gl/gl_rsurf.c index 9a427d1f4..8af7cf703 100644 --- a/libs/video/renderer/gl/gl_rsurf.c +++ b/libs/video/renderer/gl/gl_rsurf.c @@ -806,7 +806,7 @@ GL_BuildSurfaceDisplayList (mod_brush_t *brush, msurface_t *surf) lnumverts = surf->numedges; // draw texture - poly = Hunk_Alloc (0, field_offset (glpoly_t, verts[lnumverts])); + poly = Hunk_Alloc (0, offsetof (glpoly_t, verts[lnumverts])); poly->next = surf->polys; poly->flags = surf->flags; surf->polys = poly; diff --git a/libs/video/renderer/glsl/glsl_alias.c b/libs/video/renderer/glsl/glsl_alias.c index 7e009647a..45f919976 100644 --- a/libs/video/renderer/glsl/glsl_alias.c +++ b/libs/video/renderer/glsl/glsl_alias.c @@ -168,14 +168,14 @@ set_arrays (const shaderparam_t *vert, const shaderparam_t *norm, } qfeglVertexAttribPointer (vert->location, 3, GL_UNSIGNED_SHORT, - 0, sizeof (aliasvrt_t), - pose_offs + field_offset (aliasvrt_t, vertex)); + 0, sizeof (aliasvrt_t), + pose_offs + offsetof (aliasvrt_t, vertex)); qfeglVertexAttribPointer (norm->location, 3, GL_SHORT, - 1, sizeof (aliasvrt_t), - pose_offs + field_offset (aliasvrt_t, normal)); + 1, sizeof (aliasvrt_t), + pose_offs + offsetof (aliasvrt_t, normal)); qfeglVertexAttribPointer (st->location, 2, GL_SHORT, - 0, sizeof (aliasvrt_t), - pose_offs + field_offset (aliasvrt_t, st)); + 0, sizeof (aliasvrt_t), + pose_offs + offsetof (aliasvrt_t, st)); } //#define TETRAHEDRON void diff --git a/libs/video/renderer/glsl/glsl_bsp.c b/libs/video/renderer/glsl/glsl_bsp.c index 4aa3b4afe..742064af9 100644 --- a/libs/video/renderer/glsl/glsl_bsp.c +++ b/libs/video/renderer/glsl/glsl_bsp.c @@ -489,7 +489,7 @@ build_surf_displist (model_t **models, msurface_t *surf, int base, int numverts = surf->numedges; int numtris = numverts - 2; int numindices = numtris * 3; - glslpoly_t *poly = malloc (field_offset (glslpoly_t, indices[numindices])); + glslpoly_t *poly = malloc (offsetof (glslpoly_t, indices[numindices])); poly->count = numindices; for (int i = 0, ind = 0; i < numtris; i++) { // pretend we can use a triangle fan @@ -870,12 +870,12 @@ draw_elechain (elechain_t *ec, int matloc, int vertloc, int tlstloc, continue; count = el->list->size / sizeof (GLushort); qfeglVertexAttribPointer (vertloc, 4, GL_FLOAT, - 0, sizeof (bspvert_t), - el->base + field_offset (bspvert_t, vertex)); + 0, sizeof (bspvert_t), + el->base + offsetof (bspvert_t, vertex)); if (tlstloc >= 0) qfeglVertexAttribPointer (tlstloc, 4, GL_FLOAT, - 0, sizeof (bspvert_t), - el->base + field_offset (bspvert_t,tlst)); + 0, sizeof (bspvert_t), + el->base + offsetof (bspvert_t,tlst)); qfeglDrawElements (GL_TRIANGLES, count, GL_UNSIGNED_SHORT, el->list->str); dstring_clear (el->list); diff --git a/libs/video/renderer/glsl/glsl_draw.c b/libs/video/renderer/glsl/glsl_draw.c index 827e7361f..441c35f9a 100644 --- a/libs/video/renderer/glsl/glsl_draw.c +++ b/libs/video/renderer/glsl/glsl_draw.c @@ -171,7 +171,7 @@ make_glpic (const char *name, qpic_t *p) qpic_t *pic = 0; if (p) { - pic = malloc (field_offset (qpic_t, data[sizeof (picdata_t)])); + pic = malloc (offsetof (qpic_t, data[sizeof (picdata_t)])); pic->width = p->width; pic->height = p->height; __auto_type pd = (picdata_t *) pic->data; @@ -227,7 +227,7 @@ pic_data (const char *name, int w, int h, const byte *data) qpic_t *pic; qpic_t *glpic; - pic = malloc (field_offset (qpic_t, data[w * h])); + pic = malloc (offsetof (qpic_t, data[w * h])); pic->width = w; pic->height = h; memcpy (pic->data, data, pic->width * pic->height); diff --git a/libs/video/renderer/sw/d_surf.c b/libs/video/renderer/sw/d_surf.c index 4fb553979..dfc5b4295 100644 --- a/libs/video/renderer/sw/d_surf.c +++ b/libs/video/renderer/sw/d_surf.c @@ -144,7 +144,7 @@ D_SCAlloc (int width, int size) Sys_Error ("D_SCAlloc: bad cache size %d", size); // This adds the offset of data[0] in the surfcache_t struct. - size += field_offset (surfcache_t, data); + size += offsetof (surfcache_t, data); #define SIZE_ALIGN (sizeof (surfcache_t *) - 1) size = (size + SIZE_ALIGN) & ~SIZE_ALIGN; diff --git a/libs/video/renderer/sw/draw.c b/libs/video/renderer/sw/draw.c index c566f14f1..2f311eeb8 100644 --- a/libs/video/renderer/sw/draw.c +++ b/libs/video/renderer/sw/draw.c @@ -106,7 +106,7 @@ Draw_MakePic (int width, int height, const byte *data) qpic_t *pic; int size = width * height; - pic = malloc (field_offset (qpic_t, data[size])); + pic = malloc (offsetof (qpic_t, data[size])); pic->width = width; pic->height = height; memcpy (pic->data, data, size); diff --git a/libs/video/renderer/vulkan/vkgen/vkfieldarray.r b/libs/video/renderer/vulkan/vkgen/vkfieldarray.r index b2900dfb5..6cec097c6 100644 --- a/libs/video/renderer/vulkan/vkgen/vkfieldarray.r +++ b/libs/video/renderer/vulkan/vkgen/vkfieldarray.r @@ -36,10 +36,10 @@ fprintf (output_file, "static parse_array_t parse_%s_%s_data = {\n", struct_name, field_name); [type writeParseData]; - fprintf (output_file, "\tfield_offset (%s, %s),\n", + fprintf (output_file, "\toffsetof (%s, %s),\n", struct_name, value_field); if (size_field) { - fprintf (output_file, "\tfield_offset (%s, %s),\n", + fprintf (output_file, "\toffsetof (%s, %s),\n", struct_name, size_field); } else { fprintf (output_file, "\t-1,\n"); diff --git a/libs/video/renderer/vulkan/vkgen/vkfieldauto.r b/libs/video/renderer/vulkan/vkgen/vkfieldauto.r index de4a347c9..8d30affef 100644 --- a/libs/video/renderer/vulkan/vkgen/vkfieldauto.r +++ b/libs/video/renderer/vulkan/vkgen/vkfieldauto.r @@ -27,7 +27,7 @@ -writeField { Type *field_type = [Type findType: field.type]; - fprintf (output_file, "\t{\"%s\", field_offset (%s, %s), %s, %s, %s},\n", + fprintf (output_file, "\t{\"%s\", offsetof (%s, %s), %s, %s, %s},\n", field_name, struct_name, field.name, [field_type parseType], [field_type parseFunc], [field_type parseData]); @@ -38,7 +38,7 @@ { Type *field_type = [Type findType: field.type]; fprintf (output_file, - "\t{\"%s\", &%s, (void *) field_offset (%s, %s)},\n", + "\t{\"%s\", &%s, (void *) offsetof (%s, %s)},\n", field_name, [field_type cexprType], struct_name, field.name); return self; } diff --git a/libs/video/renderer/vulkan/vkgen/vkfieldcustom.r b/libs/video/renderer/vulkan/vkgen/vkfieldcustom.r index 68831005e..3543b9bb4 100644 --- a/libs/video/renderer/vulkan/vkgen/vkfieldcustom.r +++ b/libs/video/renderer/vulkan/vkgen/vkfieldcustom.r @@ -42,7 +42,7 @@ write_parse_data (CustomField *self, string indent) struct_name, field_name); for (int i = 0, count = [fields count]; i < count; i++) { string field = [[fields getObjectAtIndex:i] string]; - fprintf (output_file, "\tfield_offset (%s, %s),\n", struct_name, field); + fprintf (output_file, "\toffsetof (%s, %s),\n", struct_name, field); } fprintf (output_file, "};\n"); @@ -80,7 +80,7 @@ write_parse_data (CustomField *self, string indent) -writeSymbol { fprintf (output_file, - "\t{\"%s\", 0/*FIXME*/, 0/*(void *) field_offset (%s, %s)*/},\n", + "\t{\"%s\", 0/*FIXME*/, 0/*(void *) offsetof (%s, %s)*/},\n", field_name, struct_name, "FIXME"); return self; } diff --git a/libs/video/renderer/vulkan/vkgen/vkfielddata.r b/libs/video/renderer/vulkan/vkgen/vkfielddata.r index d13ff8965..36b4ecebf 100644 --- a/libs/video/renderer/vulkan/vkgen/vkfielddata.r +++ b/libs/video/renderer/vulkan/vkgen/vkfielddata.r @@ -23,10 +23,10 @@ { fprintf (output_file, "static parse_data_t parse_%s_%s_data = {\n", struct_name, field_name); - fprintf (output_file, "\tfield_offset (%s, %s),\n", + fprintf (output_file, "\toffsetof (%s, %s),\n", struct_name, value_field); if (size_field) { - fprintf (output_file, "\tfield_offset (%s, %s),\n", + fprintf (output_file, "\toffsetof (%s, %s),\n", struct_name, size_field); } else { fprintf (output_file, "\tt-1,\n"); diff --git a/libs/video/renderer/vulkan/vkgen/vkfielddef.r b/libs/video/renderer/vulkan/vkgen/vkfielddef.r index 0a8c5c737..798b233bc 100644 --- a/libs/video/renderer/vulkan/vkgen/vkfielddef.r +++ b/libs/video/renderer/vulkan/vkgen/vkfielddef.r @@ -105,7 +105,7 @@ -writeSymbol { fprintf (output_file, - "\t{\"%s\", 0/*FIXME*/, (void *) field_offset (%s, %s)},\n", + "\t{\"%s\", 0/*FIXME*/, (void *) offsetof (%s, %s)},\n", field_name, struct_name, value_field); return self; } diff --git a/libs/video/renderer/vulkan/vkgen/vkfieldreadonly.r b/libs/video/renderer/vulkan/vkgen/vkfieldreadonly.r index 5ae8f7df3..1a2bd4e94 100644 --- a/libs/video/renderer/vulkan/vkgen/vkfieldreadonly.r +++ b/libs/video/renderer/vulkan/vkgen/vkfieldreadonly.r @@ -45,7 +45,7 @@ -writeSymbol { fprintf (output_file, - "\t{\"%s\", %s, (void *) field_offset (%s, %s)},\n", + "\t{\"%s\", %s, (void *) offsetof (%s, %s)},\n", field_name, [type exprType], struct_name, value_field); return self; } diff --git a/libs/video/renderer/vulkan/vkgen/vkfieldsingle.r b/libs/video/renderer/vulkan/vkgen/vkfieldsingle.r index c09788a37..46d0a5493 100644 --- a/libs/video/renderer/vulkan/vkgen/vkfieldsingle.r +++ b/libs/video/renderer/vulkan/vkgen/vkfieldsingle.r @@ -34,7 +34,7 @@ fprintf (output_file, "static parse_single_t parse_%s_%s_data = {\n", struct_name, field_name); [type writeParseData]; - fprintf (output_file, "\tfield_offset (%s, %s),\n", + fprintf (output_file, "\toffsetof (%s, %s),\n", struct_name, value_field); fprintf (output_file, "};\n"); return self; diff --git a/libs/video/renderer/vulkan/vkgen/vkfieldstring.r b/libs/video/renderer/vulkan/vkgen/vkfieldstring.r index 59a89012f..7ce751e3c 100644 --- a/libs/video/renderer/vulkan/vkgen/vkfieldstring.r +++ b/libs/video/renderer/vulkan/vkgen/vkfieldstring.r @@ -29,7 +29,7 @@ { fprintf (output_file, "static parse_string_t parse_%s_%s_data = {\n", struct_name, field_name); - fprintf (output_file, "\tfield_offset (%s, %s),\n", + fprintf (output_file, "\toffsetof (%s, %s),\n", struct_name, value_field); fprintf (output_file, "};\n"); return self; diff --git a/libs/video/renderer/vulkan/vkgen/vkstruct.r b/libs/video/renderer/vulkan/vkgen/vkstruct.r index ea1c4c72a..30c4026b4 100644 --- a/libs/video/renderer/vulkan/vkgen/vkstruct.r +++ b/libs/video/renderer/vulkan/vkgen/vkstruct.r @@ -314,7 +314,7 @@ write_cexpr (Struct *self, Array *field_defs) } Type *field_type = [Type findType: field.type]; fprintf (output_file, - "\t{\"%s\", &%s, (void *) field_offset (%s, %s)},\n", + "\t{\"%s\", &%s, (void *) offsetof (%s, %s)},\n", field.name, [field_type cexprType], [self outname], field.name); } @@ -373,7 +373,7 @@ write_table (Struct *self, PLItem *field_dict, Array *field_defs, } if (have_pNext) { fprintf (output_file, - "\t{\"@next\", field_offset (%s, pNext), " + "\t{\"@next\", offsetof (%s, pNext), " "QFArray, parse_next, 0},\n", [self outname]); } for (int i = [field_defs count]; i-- > 0; ) { diff --git a/libs/video/renderer/vulkan/vkparse.c b/libs/video/renderer/vulkan/vkparse.c index 836bf6eee..798833bb3 100644 --- a/libs/video/renderer/vulkan/vkparse.c +++ b/libs/video/renderer/vulkan/vkparse.c @@ -964,7 +964,7 @@ parse_task_params (const plitem_t *item, void **data, #include "libs/video/renderer/vulkan/vkparse.cinc" static exprsym_t qfv_renderframeset_t_symbols[] = { - {"size", &cexpr_size_t, (void *)field_offset (qfv_renderframeset_t, size)}, + {"size", &cexpr_size_t, (void *) offsetof (qfv_renderframeset_t, size)}, { } }; static exprtab_t qfv_renderframeset_t_symtab = { diff --git a/libs/video/renderer/vulkan/vulkan_alias.c b/libs/video/renderer/vulkan/vulkan_alias.c index 08ff0343e..d1f18466b 100644 --- a/libs/video/renderer/vulkan/vulkan_alias.c +++ b/libs/video/renderer/vulkan/vulkan_alias.c @@ -127,19 +127,19 @@ push_alias_constants (const mat4f_t mat, float blend, byte *colors, qfv_push_constants_t push_constants[] = { { VK_SHADER_STAGE_VERTEX_BIT, - field_offset (alias_push_constants_t, mat), + offsetof (alias_push_constants_t, mat), sizeof (mat4f_t), mat }, { VK_SHADER_STAGE_VERTEX_BIT, - field_offset (alias_push_constants_t, blend), + offsetof (alias_push_constants_t, blend), sizeof (float), &constants.blend }, { VK_SHADER_STAGE_FRAGMENT_BIT, - field_offset (alias_push_constants_t, colors), + offsetof (alias_push_constants_t, colors), sizeof (constants.colors), constants.colors }, { VK_SHADER_STAGE_FRAGMENT_BIT, - field_offset (alias_push_constants_t, base_color), + offsetof (alias_push_constants_t, base_color), sizeof (constants.base_color), &constants.base_color }, { VK_SHADER_STAGE_FRAGMENT_BIT, - field_offset (alias_push_constants_t, fog), + offsetof (alias_push_constants_t, fog), sizeof (constants.fog), &constants.fog }, }; QFV_PushConstants (device, cmd, layout, pass ? 5 : 2, push_constants); @@ -167,28 +167,28 @@ push_fwd_constants (const mat4f_t mat, float blend, byte *colors, qfv_push_constants_t push_constants[] = { { VK_SHADER_STAGE_VERTEX_BIT, - field_offset (fwd_push_constants_t, mat), + offsetof (fwd_push_constants_t, mat), sizeof (mat4f_t), mat }, { VK_SHADER_STAGE_VERTEX_BIT, - field_offset (fwd_push_constants_t, blend), + offsetof (fwd_push_constants_t, blend), sizeof (float), &constants.blend }, { VK_SHADER_STAGE_FRAGMENT_BIT, - field_offset (fwd_push_constants_t, colors), + offsetof (fwd_push_constants_t, colors), sizeof (constants.colors), constants.colors }, { VK_SHADER_STAGE_FRAGMENT_BIT, - field_offset (fwd_push_constants_t, ambient), + offsetof (fwd_push_constants_t, ambient), sizeof (constants.ambient), &constants.ambient }, { VK_SHADER_STAGE_FRAGMENT_BIT, - field_offset (fwd_push_constants_t, shadelight), + offsetof (fwd_push_constants_t, shadelight), sizeof (constants.shadelight), &constants.shadelight }, { VK_SHADER_STAGE_FRAGMENT_BIT, - field_offset (fwd_push_constants_t, lightvec), + offsetof (fwd_push_constants_t, lightvec), sizeof (constants.lightvec), &constants.lightvec }, { VK_SHADER_STAGE_FRAGMENT_BIT, - field_offset (fwd_push_constants_t, base_color), + offsetof (fwd_push_constants_t, base_color), sizeof (constants.base_color), &constants.base_color }, { VK_SHADER_STAGE_FRAGMENT_BIT, - field_offset (fwd_push_constants_t, fog), + offsetof (fwd_push_constants_t, fog), sizeof (constants.fog), &constants.fog }, }; QFV_PushConstants (device, cmd, layout, 8, push_constants); @@ -210,13 +210,13 @@ push_shadow_constants (const mat4f_t mat, float blend, uint16_t *matrix_base, qfv_push_constants_t push_constants[] = { { VK_SHADER_STAGE_VERTEX_BIT, - field_offset (shadow_push_constants_t, mat), + offsetof (shadow_push_constants_t, mat), sizeof (mat4f_t), mat }, { VK_SHADER_STAGE_VERTEX_BIT, - field_offset (shadow_push_constants_t, blend), + offsetof (shadow_push_constants_t, blend), sizeof (float), &constants.blend }, { VK_SHADER_STAGE_VERTEX_BIT, - field_offset (shadow_push_constants_t, matrix_base), + offsetof (shadow_push_constants_t, matrix_base), sizeof (uint32_t), &constants.matrix_base }, }; QFV_PushConstants (device, cmd, layout, 3, push_constants); diff --git a/libs/video/renderer/vulkan/vulkan_bsp.c b/libs/video/renderer/vulkan/vulkan_bsp.c index e11d9425f..2c03534c8 100644 --- a/libs/video/renderer/vulkan/vulkan_bsp.c +++ b/libs/video/renderer/vulkan/vulkan_bsp.c @@ -871,16 +871,16 @@ push_fragconst (QFV_BspQueue queue, VkPipelineLayout layout, qfv_push_constants_t push_constants[] = { { VK_SHADER_STAGE_FRAGMENT_BIT, - field_offset (bsp_frag_constants_t, fog), + offsetof (bsp_frag_constants_t, fog), sizeof (constants.fog), &constants.fog }, { VK_SHADER_STAGE_FRAGMENT_BIT, - field_offset (bsp_frag_constants_t, time), + offsetof (bsp_frag_constants_t, time), sizeof (constants.time), &constants.time }, { VK_SHADER_STAGE_FRAGMENT_BIT, - field_offset (bsp_frag_constants_t, alpha), + offsetof (bsp_frag_constants_t, alpha), sizeof (constants.alpha), &constants.alpha }, { VK_SHADER_STAGE_FRAGMENT_BIT, - field_offset (bsp_frag_constants_t, turb_scale), + offsetof (bsp_frag_constants_t, turb_scale), sizeof (constants.turb_scale), &constants.turb_scale }, }; QFV_PushConstants (device, cmd, layout, 4, push_constants); diff --git a/libs/video/renderer/vulkan/vulkan_draw.c b/libs/video/renderer/vulkan/vulkan_draw.c index 6764747fd..fdb661eea 100644 --- a/libs/video/renderer/vulkan/vulkan_draw.c +++ b/libs/video/renderer/vulkan/vulkan_draw.c @@ -643,7 +643,7 @@ pic_data (const char *name, int w, int h, const byte *data, vulkan_ctx_t *ctx) byte *picdata; pic = cmemalloc (dctx->pic_memsuper, - field_offset (qpic_t, data[sizeof (picdata_t)])); + offsetof (qpic_t, data[sizeof (picdata_t)])); pic->width = w; pic->height = h; __auto_type pd = (picdata_t *) pic->data; @@ -791,7 +791,7 @@ load_lmp (const char *path, vulkan_ctx_t *ctx) qpic_t *pic; pic = cmemalloc (dctx->pic_memsuper, - field_offset (qpic_t, data[sizeof (picdata_t)])); + offsetof (qpic_t, data[sizeof (picdata_t)])); pic->width = p->width; pic->height = p->height; __auto_type pd = (picdata_t *) pic->data; diff --git a/libs/video/renderer/vulkan/vulkan_iqm.c b/libs/video/renderer/vulkan/vulkan_iqm.c index a1a99da69..4da5cc841 100644 --- a/libs/video/renderer/vulkan/vulkan_iqm.c +++ b/libs/video/renderer/vulkan/vulkan_iqm.c @@ -218,19 +218,19 @@ push_iqm_constants (const mat4f_t mat, float blend, byte *colors, qfv_push_constants_t push_constants[] = { { VK_SHADER_STAGE_VERTEX_BIT, - field_offset (iqm_push_constants_t, mat), + offsetof (iqm_push_constants_t, mat), sizeof (mat4f_t), mat }, { VK_SHADER_STAGE_VERTEX_BIT, - field_offset (iqm_push_constants_t, blend), + offsetof (iqm_push_constants_t, blend), sizeof (float), &constants.blend }, { VK_SHADER_STAGE_FRAGMENT_BIT, - field_offset (iqm_push_constants_t, colors), + offsetof (iqm_push_constants_t, colors), sizeof (constants.colors), constants.colors }, { VK_SHADER_STAGE_FRAGMENT_BIT, - field_offset (iqm_push_constants_t, base_color), + offsetof (iqm_push_constants_t, base_color), sizeof (constants.base_color), &constants.base_color }, { VK_SHADER_STAGE_FRAGMENT_BIT, - field_offset (iqm_push_constants_t, fog), + offsetof (iqm_push_constants_t, fog), sizeof (constants.fog), &constants.fog }, }; QFV_PushConstants (device, cmd, layout, pass ? 5 : 2, push_constants); @@ -258,28 +258,28 @@ push_fwd_constants (const mat4f_t mat, float blend, byte *colors, qfv_push_constants_t push_constants[] = { { VK_SHADER_STAGE_VERTEX_BIT, - field_offset (fwd_push_constants_t, mat), + offsetof (fwd_push_constants_t, mat), sizeof (mat4f_t), mat }, { VK_SHADER_STAGE_VERTEX_BIT, - field_offset (fwd_push_constants_t, blend), + offsetof (fwd_push_constants_t, blend), sizeof (float), &constants.blend }, { VK_SHADER_STAGE_FRAGMENT_BIT, - field_offset (fwd_push_constants_t, colors), + offsetof (fwd_push_constants_t, colors), sizeof (constants.colors), constants.colors }, { VK_SHADER_STAGE_FRAGMENT_BIT, - field_offset (fwd_push_constants_t, ambient), + offsetof (fwd_push_constants_t, ambient), sizeof (constants.ambient), &constants.ambient }, { VK_SHADER_STAGE_FRAGMENT_BIT, - field_offset (fwd_push_constants_t, shadelight), + offsetof (fwd_push_constants_t, shadelight), sizeof (constants.shadelight), &constants.shadelight }, { VK_SHADER_STAGE_FRAGMENT_BIT, - field_offset (fwd_push_constants_t, lightvec), + offsetof (fwd_push_constants_t, lightvec), sizeof (constants.lightvec), &constants.lightvec }, { VK_SHADER_STAGE_FRAGMENT_BIT, - field_offset (fwd_push_constants_t, base_color), + offsetof (fwd_push_constants_t, base_color), sizeof (constants.base_color), &constants.base_color }, { VK_SHADER_STAGE_FRAGMENT_BIT, - field_offset (fwd_push_constants_t, fog), + offsetof (fwd_push_constants_t, fog), sizeof (constants.fog), &constants.fog }, }; QFV_PushConstants (device, cmd, layout, 8, push_constants); @@ -301,13 +301,13 @@ push_shadow_constants (const mat4f_t mat, float blend, uint16_t *matrix_base, qfv_push_constants_t push_constants[] = { { VK_SHADER_STAGE_VERTEX_BIT, - field_offset (shadow_push_constants_t, mat), + offsetof (shadow_push_constants_t, mat), sizeof (mat4f_t), mat }, { VK_SHADER_STAGE_VERTEX_BIT, - field_offset (shadow_push_constants_t, blend), + offsetof (shadow_push_constants_t, blend), sizeof (float), &constants.blend }, { VK_SHADER_STAGE_VERTEX_BIT, - field_offset (shadow_push_constants_t, matrix_base), + offsetof (shadow_push_constants_t, matrix_base), sizeof (uint32_t), &constants.matrix_base }, }; QFV_PushConstants (device, cmd, layout, 3, push_constants); diff --git a/libs/video/renderer/vulkan/vulkan_lighting.c b/libs/video/renderer/vulkan/vulkan_lighting.c index c429eef34..2de45df4e 100644 --- a/libs/video/renderer/vulkan/vulkan_lighting.c +++ b/libs/video/renderer/vulkan/vulkan_lighting.c @@ -1401,13 +1401,13 @@ lighting_draw_lights (const exprval_t **params, exprval_t *result, }; qfv_push_constants_t push_constants[] = { { VK_SHADER_STAGE_FRAGMENT_BIT, - field_offset (light_push_constants_t, fog), + offsetof (light_push_constants_t, fog), sizeof (fog), &fog }, { VK_SHADER_STAGE_FRAGMENT_BIT, - field_offset (light_push_constants_t, CascadeDepths), + offsetof (light_push_constants_t, CascadeDepths), sizeof (depths), &depths }, { VK_SHADER_STAGE_FRAGMENT_BIT, - field_offset (light_push_constants_t, queue), + offsetof (light_push_constants_t, queue), sizeof (queue), &queue }, }; QFV_PushConstants (device, cmd, layout, 3, push_constants); diff --git a/libs/video/renderer/vulkan/vulkan_particles.c b/libs/video/renderer/vulkan/vulkan_particles.c index 6d2059f88..af04cb7dc 100644 --- a/libs/video/renderer/vulkan/vulkan_particles.c +++ b/libs/video/renderer/vulkan/vulkan_particles.c @@ -361,10 +361,10 @@ particle_physics (const exprval_t **params, exprval_t *result, exprctx_t *ectx) }; qfv_push_constants_t push_constants[] = { { VK_SHADER_STAGE_COMPUTE_BIT, - field_offset (particle_push_constants_t, gravity), + offsetof (particle_push_constants_t, gravity), sizeof (vec4f_t), &constants.gravity }, { VK_SHADER_STAGE_COMPUTE_BIT, - field_offset (particle_push_constants_t, dT), + offsetof (particle_push_constants_t, dT), sizeof (float), &constants.dT }, }; QFV_PushConstants (device, cmd, layout, 2, push_constants); diff --git a/qw/source/sv_ccmds.c b/qw/source/sv_ccmds.c index 5f8c7221a..2e066264b 100644 --- a/qw/source/sv_ccmds.c +++ b/qw/source/sv_ccmds.c @@ -644,13 +644,13 @@ SV_Punish (int mode) cmd = "cuff"; cmd_do = "cuffed"; //FIXME cmd_undo = "un-cuffed"; - field_offs = field_offset (client_t, cuff_time); + field_offs = offsetof (client_t, cuff_time); break; case 1: cmd = "mute"; cmd_do = "muted"; //FIXME cmd_undo = "can speak"; - field_offs = field_offset (client_t, lockedtill); + field_offs = offsetof (client_t, lockedtill); break; } diff --git a/tools/qfbsp/source/info.c b/tools/qfbsp/source/info.c index 5eeef52fd..018d2ca98 100644 --- a/tools/qfbsp/source/info.c +++ b/tools/qfbsp/source/info.c @@ -30,7 +30,7 @@ num_textures (const void *data) return va (0, " %7d", LittleLong (d->nummiptex)); } -#define O(f) field_offset (bsp_t, f) +#define O(f) offsetof (bsp_t, f) static lumpinfo_t lump_info[] = { { "entities", O(entdata), O(entdatasize) }, { "planes", O(planes), O(numplanes) }, diff --git a/tools/qfbsp/source/tjunc.c b/tools/qfbsp/source/tjunc.c index e18ec33da..154ad555d 100644 --- a/tools/qfbsp/source/tjunc.c +++ b/tools/qfbsp/source/tjunc.c @@ -329,8 +329,7 @@ FixFaceEdges (face_t *f) if (v->t < t2 - T_EPSILON) { tjuncs++; // insert a new vertex here - fp = realloc (fp, field_offset (winding_t, - points[fp->numpoints + 1])); + fp = realloc (fp, offsetof (winding_t, points[fp->numpoints + 1])); for (k = fp->numpoints; k > j; k--) { VectorCopy (fp->points[k - 1], fp->points[k]); } diff --git a/tools/qfcc/include/expr.h b/tools/qfcc/include/expr.h index 05564a0b4..dd29630a5 100644 --- a/tools/qfcc/include/expr.h +++ b/tools/qfcc/include/expr.h @@ -252,7 +252,7 @@ typedef struct ex_value_s { #include "tools/qfcc/include/vec_types.h" }; } ex_value_t; -#define value_size (sizeof(ex_value_t) - field_offset(ex_value_t, raw_value)) +#define value_size (sizeof(ex_value_t) - offsetof(ex_value_t, raw_value)) typedef struct { const type_t *type; ///< type to view the expression diff --git a/tools/qfcc/source/expr_bool.c b/tools/qfcc/source/expr_bool.c index 34407cd33..04a976976 100644 --- a/tools/qfcc/source/expr_bool.c +++ b/tools/qfcc/source/expr_bool.c @@ -127,7 +127,7 @@ merge (ex_boollist_t *l1, ex_boollist_t *l2) return l1; if (!l1) return l2; - m = malloc (field_offset (ex_boollist_t, e[l1->size + l2->size])); + m = malloc (offsetof (ex_boollist_t, e[l1->size + l2->size])); m->size = l1->size + l2->size; memcpy (m->e, l1->e, l1->size * sizeof (expr_t *)); memcpy (m->e + l1->size, l2->e, l2->size * sizeof (expr_t *)); @@ -139,7 +139,7 @@ make_list (const expr_t *e) { ex_boollist_t *m; - m = malloc (field_offset (ex_boollist_t, e[1])); + m = malloc (offsetof (ex_boollist_t, e[1])); m->size = 1; m->e[0] = (expr_t *) e; return m; diff --git a/tools/qfcc/source/obj_type.c b/tools/qfcc/source/obj_type.c index a702a5cc9..4cad62655 100644 --- a/tools/qfcc/source/obj_type.c +++ b/tools/qfcc/source/obj_type.c @@ -81,7 +81,7 @@ qfo_new_encoding (const type_t *type, int size, defspace_t *space) qfot_type_t *enc; def_t *def; - size += field_offset (qfot_type_t, type); + size += offsetof (qfot_type_t, type); size /= sizeof (pr_type_t); def = new_def (type->encoding, 0, space, sc_static); @@ -113,7 +113,7 @@ qfo_encode_func (const type_t *type, defspace_t *space) return_type_def = qfo_encode_type (type->func.ret_type, space); for (i = 0; i < param_count; i++) param_type_defs[i] = qfo_encode_type (type->func.param_types[i], space); - size = field_offset (qfot_func_t, param_types[param_count]); + size = offsetof (qfot_func_t, param_types[param_count]); def = qfo_new_encoding (type, size, space); enc = D_POINTER (qfot_type_t, def); @@ -187,7 +187,7 @@ qfo_encode_struct (const type_t *type, defspace_t *space) num_fields++; } - size = field_offset (qfot_struct_t, fields[num_fields]); + size = offsetof (qfot_struct_t, fields[num_fields]); def = qfo_new_encoding (type, size, space); enc = D_POINTER (qfot_type_t, def); strct = &enc->strct; diff --git a/tools/qfcc/source/value.c b/tools/qfcc/source/value.c index d22dc72cc..f83cf386f 100644 --- a/tools/qfcc/source/value.c +++ b/tools/qfcc/source/value.c @@ -72,7 +72,7 @@ typedef struct { ex_pointer_t pointer; }; } immediate_t; -#define imm_size (sizeof(immediate_t) - field_offset(immediate_t, raw_imm)) +#define imm_size (sizeof(immediate_t) - offsetof(immediate_t, raw_imm)) static hashtab_t *value_table; ALLOC_STATE (ex_value_t, values); @@ -303,7 +303,7 @@ new_type_value (const type_t *type, const pr_type_t *data) { size_t typeSize = type_size (type) * sizeof (pr_type_t); ex_value_t val = {}; - if (typeSize > sizeof (val) - field_offset (ex_value_t, raw_value)) { + if (typeSize > sizeof (val) - offsetof (ex_value_t, raw_value)) { internal_error (0, "value too large"); } set_val_type (&val, type); diff --git a/tools/qfvis/source/qfvis.c b/tools/qfvis/source/qfvis.c index 56b95c74b..9ea01679c 100644 --- a/tools/qfvis/source/qfvis.c +++ b/tools/qfvis/source/qfvis.c @@ -164,7 +164,7 @@ NewWinding (threaddata_t *thread, int points) winding_t *winding; unsigned size; - size = field_offset (winding_t, points[points]); + size = offsetof (winding_t, points[points]); winding = Hunk_RawAlloc (thread->hunk, size); memset (winding, 0, size); winding->id = thread->winding_id++; @@ -179,7 +179,7 @@ CopyWinding (threaddata_t *thread, const winding_t *w) unsigned size; winding_t *copy; - size = field_offset (winding_t, points[w->numpoints]); + size = offsetof (winding_t, points[w->numpoints]); copy = Hunk_RawAlloc (thread->hunk, size); memcpy (copy, w, size); copy->original = false;