Cleanup: BLI_utildefines struct macros
Use the term "AFTER" instead of "OFS" since it wasn't obvious these macros operate on everything after the struct member passed. Avoid casting to non-const types when only reading.
This commit is contained in:
@@ -624,7 +624,7 @@ void DM_to_mesh(DerivedMesh *dm, Mesh *me, Object *ob, const CustomData_MeshMask
|
||||
}
|
||||
|
||||
/* skip the listbase */
|
||||
MEMCPY_STRUCT_OFS(me, &tmp, id.prev);
|
||||
MEMCPY_STRUCT_AFTER(me, &tmp, id.prev);
|
||||
|
||||
if (take_ownership) {
|
||||
if (alloctype == CD_ASSIGN) {
|
||||
|
||||
@@ -131,7 +131,7 @@ static void brush_defaults(Brush *brush)
|
||||
|
||||
void BKE_brush_init(Brush *brush)
|
||||
{
|
||||
BLI_assert(MEMCMP_STRUCT_OFS_IS_ZERO(brush, id));
|
||||
BLI_assert(MEMCMP_STRUCT_AFTER_IS_ZERO(brush, id));
|
||||
|
||||
/* enable fake user by default */
|
||||
id_fake_user_set(&brush->id);
|
||||
|
||||
@@ -54,7 +54,7 @@
|
||||
|
||||
void BKE_camera_init(Camera *cam)
|
||||
{
|
||||
BLI_assert(MEMCMP_STRUCT_OFS_IS_ZERO(cam, id));
|
||||
BLI_assert(MEMCMP_STRUCT_AFTER_IS_ZERO(cam, id));
|
||||
|
||||
cam->lens = 50.0f;
|
||||
cam->sensor_x = DEFAULT_SENSOR_WIDTH;
|
||||
|
||||
@@ -138,7 +138,7 @@ void BKE_curve_free(Curve *cu)
|
||||
|
||||
void BKE_curve_init(Curve *cu)
|
||||
{
|
||||
/* BLI_assert(MEMCMP_STRUCT_OFS_IS_ZERO(cu, id)); */ /* cu->type is already initialized... */
|
||||
/* BLI_assert(MEMCMP_STRUCT_AFTER_IS_ZERO(cu, id)); */ /* cu->type is already initialized... */
|
||||
|
||||
copy_v3_fl(cu->size, 1.0f);
|
||||
cu->flag = CU_FRONT | CU_BACK | CU_DEFORM_BOUNDS_OFF | CU_PATH_RADIUS;
|
||||
|
||||
@@ -293,7 +293,7 @@ void BKE_image_free(Image *ima)
|
||||
/* only image block itself */
|
||||
static void image_init(Image *ima, short source, short type)
|
||||
{
|
||||
BLI_assert(MEMCMP_STRUCT_OFS_IS_ZERO(ima, id));
|
||||
BLI_assert(MEMCMP_STRUCT_AFTER_IS_ZERO(ima, id));
|
||||
|
||||
ima->ok = IMA_OK;
|
||||
|
||||
|
||||
@@ -242,7 +242,7 @@ void BKE_lattice_resize(Lattice *lt, int uNew, int vNew, int wNew, Object *ltOb)
|
||||
|
||||
void BKE_lattice_init(Lattice *lt)
|
||||
{
|
||||
BLI_assert(MEMCMP_STRUCT_OFS_IS_ZERO(lt, id));
|
||||
BLI_assert(MEMCMP_STRUCT_AFTER_IS_ZERO(lt, id));
|
||||
|
||||
lt->flag = LT_GRID;
|
||||
|
||||
|
||||
@@ -46,7 +46,7 @@
|
||||
|
||||
void BKE_light_init(Light *la)
|
||||
{
|
||||
BLI_assert(MEMCMP_STRUCT_OFS_IS_ZERO(la, id));
|
||||
BLI_assert(MEMCMP_STRUCT_AFTER_IS_ZERO(la, id));
|
||||
|
||||
la->r = la->g = la->b = la->k = 1.0f;
|
||||
la->energy = 10.0f;
|
||||
|
||||
@@ -33,7 +33,7 @@
|
||||
|
||||
void BKE_lightprobe_init(LightProbe *probe)
|
||||
{
|
||||
BLI_assert(MEMCMP_STRUCT_OFS_IS_ZERO(probe, id));
|
||||
BLI_assert(MEMCMP_STRUCT_AFTER_IS_ZERO(probe, id));
|
||||
|
||||
probe->grid_resolution_x = probe->grid_resolution_y = probe->grid_resolution_z = 4;
|
||||
probe->distinf = 2.5f;
|
||||
|
||||
@@ -74,7 +74,7 @@ static const char *modifier_name[LS_MODIFIER_NUM] = {
|
||||
|
||||
void BKE_linestyle_init(FreestyleLineStyle *linestyle)
|
||||
{
|
||||
BLI_assert(MEMCMP_STRUCT_OFS_IS_ZERO(linestyle, id));
|
||||
BLI_assert(MEMCMP_STRUCT_AFTER_IS_ZERO(linestyle, id));
|
||||
|
||||
linestyle->panel = LS_PANEL_STROKES;
|
||||
linestyle->r = linestyle->g = linestyle->b = 0.0f;
|
||||
|
||||
@@ -127,7 +127,7 @@ void BKE_material_init_gpencil_settings(Material *ma)
|
||||
|
||||
void BKE_material_init(Material *ma)
|
||||
{
|
||||
BLI_assert(MEMCMP_STRUCT_OFS_IS_ZERO(ma, id));
|
||||
BLI_assert(MEMCMP_STRUCT_AFTER_IS_ZERO(ma, id));
|
||||
|
||||
ma->r = ma->g = ma->b = 0.8;
|
||||
ma->specr = ma->specg = ma->specb = 1.0;
|
||||
|
||||
@@ -75,7 +75,7 @@ void BKE_mball_free(MetaBall *mb)
|
||||
|
||||
void BKE_mball_init(MetaBall *mb)
|
||||
{
|
||||
BLI_assert(MEMCMP_STRUCT_OFS_IS_ZERO(mb, id));
|
||||
BLI_assert(MEMCMP_STRUCT_AFTER_IS_ZERO(mb, id));
|
||||
|
||||
mb->size[0] = mb->size[1] = mb->size[2] = 1.0;
|
||||
mb->texflag = MB_AUTOSPACE;
|
||||
|
||||
@@ -492,7 +492,7 @@ static void mesh_tessface_clear_intern(Mesh *mesh, int free_customdata)
|
||||
|
||||
void BKE_mesh_init(Mesh *me)
|
||||
{
|
||||
BLI_assert(MEMCMP_STRUCT_OFS_IS_ZERO(me, id));
|
||||
BLI_assert(MEMCMP_STRUCT_AFTER_IS_ZERO(me, id));
|
||||
|
||||
me->size[0] = me->size[1] = me->size[2] = 1.0;
|
||||
me->smoothresh = DEG2RADF(30);
|
||||
|
||||
@@ -1367,7 +1367,7 @@ void BKE_mesh_nomain_to_mesh(
|
||||
}
|
||||
|
||||
/* skip the listbase */
|
||||
MEMCPY_STRUCT_OFS(mesh_dst, &tmp, id.prev);
|
||||
MEMCPY_STRUCT_AFTER(mesh_dst, &tmp, id.prev);
|
||||
|
||||
if (take_ownership) {
|
||||
if (alloctype == CD_ASSIGN) {
|
||||
|
||||
@@ -808,7 +808,7 @@ void *BKE_object_obdata_add_from_type(Main *bmain, int type, const char *name)
|
||||
|
||||
void BKE_object_init(Object *ob)
|
||||
{
|
||||
/* BLI_assert(MEMCMP_STRUCT_OFS_IS_ZERO(ob, id)); */ /* ob->type is already initialized... */
|
||||
/* BLI_assert(MEMCMP_STRUCT_AFTER_IS_ZERO(ob, id)); */ /* ob->type is already initialized... */
|
||||
|
||||
copy_v4_fl(ob->color, 1.0f);
|
||||
|
||||
|
||||
@@ -542,7 +542,7 @@ void BKE_scene_init(Scene *sce)
|
||||
SceneRenderView *srv;
|
||||
CurveMapping *mblur_shutter_curve;
|
||||
|
||||
BLI_assert(MEMCMP_STRUCT_OFS_IS_ZERO(sce, id));
|
||||
BLI_assert(MEMCMP_STRUCT_AFTER_IS_ZERO(sce, id));
|
||||
|
||||
|
||||
sce->cursor.rotation_mode = ROT_MODE_XYZ;
|
||||
|
||||
@@ -32,7 +32,7 @@
|
||||
|
||||
void BKE_speaker_init(Speaker *spk)
|
||||
{
|
||||
BLI_assert(MEMCMP_STRUCT_OFS_IS_ZERO(spk, id));
|
||||
BLI_assert(MEMCMP_STRUCT_AFTER_IS_ZERO(spk, id));
|
||||
|
||||
spk->attenuation = 1.0f;
|
||||
spk->cone_angle_inner = 360.0f;
|
||||
|
||||
@@ -205,7 +205,7 @@ void BKE_text_init(Text *ta)
|
||||
{
|
||||
TextLine *tmp;
|
||||
|
||||
BLI_assert(MEMCMP_STRUCT_OFS_IS_ZERO(ta, id));
|
||||
BLI_assert(MEMCMP_STRUCT_AFTER_IS_ZERO(ta, id));
|
||||
|
||||
ta->name = NULL;
|
||||
|
||||
|
||||
@@ -210,7 +210,7 @@ void BKE_texture_free(Tex *tex)
|
||||
|
||||
void BKE_texture_default(Tex *tex)
|
||||
{
|
||||
/* BLI_assert(MEMCMP_STRUCT_OFS_IS_ZERO(tex, id)); */ /* Not here, can be called with some pointers set. :/ */
|
||||
/* BLI_assert(MEMCMP_STRUCT_AFTER_IS_ZERO(tex, id)); */ /* Not here, can be called with some pointers set. :/ */
|
||||
|
||||
tex->type = TEX_IMAGE;
|
||||
tex->ima = NULL;
|
||||
|
||||
@@ -70,7 +70,7 @@ void BKE_world_free(World *wrld)
|
||||
|
||||
void BKE_world_init(World *wrld)
|
||||
{
|
||||
BLI_assert(MEMCMP_STRUCT_OFS_IS_ZERO(wrld, id));
|
||||
BLI_assert(MEMCMP_STRUCT_AFTER_IS_ZERO(wrld, id));
|
||||
|
||||
wrld->horr = 0.05f;
|
||||
wrld->horg = 0.05f;
|
||||
|
||||
@@ -428,29 +428,29 @@ extern "C" {
|
||||
((void *)((char *)(v) + (ofs)))
|
||||
#endif
|
||||
|
||||
/* Like offsetof(typeof(), member), for non-gcc compilers */
|
||||
#define OFFSETOF_STRUCT(_struct, _member) \
|
||||
((((char *)&((_struct)->_member)) - ((char *)(_struct))) + sizeof((_struct)->_member))
|
||||
/** Performs `offsetof(typeof(data), member) + sizeof((data)->member)` for non-gcc compilers. */
|
||||
#define OFFSETOF_STRUCT_AFTER(_struct, _member) \
|
||||
((((const char *)&((_struct)->_member)) - ((const char *)(_struct))) + sizeof((_struct)->_member))
|
||||
|
||||
/**
|
||||
* memcpy helper, skipping the first part of a struct,
|
||||
* ensures 'struct_dst' isn't const and the offset can be computed at compile time.
|
||||
* This isn't inclusive, the value of \a member isn't copied.
|
||||
*/
|
||||
#define MEMCPY_STRUCT_OFS(struct_dst, struct_src, member) { \
|
||||
#define MEMCPY_STRUCT_AFTER(struct_dst, struct_src, member) { \
|
||||
CHECK_TYPE_NONCONST(struct_dst); \
|
||||
((void)(struct_dst == struct_src), \
|
||||
memcpy((char *)(struct_dst) + OFFSETOF_STRUCT(struct_dst, member), \
|
||||
(char *)(struct_src) + OFFSETOF_STRUCT(struct_dst, member), \
|
||||
sizeof(*(struct_dst)) - OFFSETOF_STRUCT(struct_dst, member))); \
|
||||
} (void)0
|
||||
memcpy((char *)(struct_dst) + OFFSETOF_STRUCT_AFTER(struct_dst, member), \
|
||||
(const char *)(struct_src) + OFFSETOF_STRUCT_AFTER(struct_dst, member), \
|
||||
sizeof(*(struct_dst)) - OFFSETOF_STRUCT_AFTER(struct_dst, member))); \
|
||||
} ((void)0)
|
||||
|
||||
#define MEMSET_STRUCT_OFS(struct_var, value, member) { \
|
||||
#define MEMSET_STRUCT_AFTER(struct_var, value, member) { \
|
||||
CHECK_TYPE_NONCONST(struct_var); \
|
||||
memset((char *)(struct_var) + OFFSETOF_STRUCT(struct_var, member), \
|
||||
memset((char *)(struct_var) + OFFSETOF_STRUCT_AFTER(struct_var, member), \
|
||||
value, \
|
||||
sizeof(*(struct_var)) - OFFSETOF_STRUCT(struct_var, member)); \
|
||||
} (void)0
|
||||
sizeof(*(struct_var)) - OFFSETOF_STRUCT_AFTER(struct_var, member)); \
|
||||
} ((void)0)
|
||||
|
||||
/* defined
|
||||
* in memory_utils.c for now. I do not know where we should put it actually... */
|
||||
@@ -458,10 +458,10 @@ extern "C" {
|
||||
extern bool BLI_memory_is_zero(const void *arr, const size_t arr_size);
|
||||
#endif
|
||||
|
||||
#define MEMCMP_STRUCT_OFS_IS_ZERO(struct_var, member) \
|
||||
#define MEMCMP_STRUCT_AFTER_IS_ZERO(struct_var, member) \
|
||||
(BLI_memory_is_zero( \
|
||||
(char *)(struct_var) + OFFSETOF_STRUCT(struct_var, member), \
|
||||
sizeof(*(struct_var)) - OFFSETOF_STRUCT(struct_var, member)))
|
||||
(const char *)(struct_var) + OFFSETOF_STRUCT_AFTER(struct_var, member), \
|
||||
sizeof(*(struct_var)) - OFFSETOF_STRUCT_AFTER(struct_var, member)))
|
||||
|
||||
/* Warning-free macros for storing ints in pointers. Use these _only_
|
||||
* for storing an int in a pointer, not a pointer in an int (64bit)! */
|
||||
|
||||
@@ -381,10 +381,10 @@ typedef struct ProjPaintState {
|
||||
*/
|
||||
|
||||
#define PROJ_PAINT_STATE_SHARED_MEMCPY(ps_dst, ps_src) \
|
||||
MEMCPY_STRUCT_OFS(ps_dst, ps_src, is_shared_user)
|
||||
MEMCPY_STRUCT_AFTER(ps_dst, ps_src, is_shared_user)
|
||||
|
||||
#define PROJ_PAINT_STATE_SHARED_CLEAR(ps) \
|
||||
MEMSET_STRUCT_OFS(ps, 0, is_shared_user)
|
||||
MEMSET_STRUCT_AFTER(ps, 0, is_shared_user)
|
||||
|
||||
bool is_shared_user;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user