Changeset View
Changeset View
Standalone View
Standalone View
source/blender/makesrna/intern/rna_define.c
| Context not available. | |||||
| #include <ctype.h> | #include <ctype.h> | ||||
| #include <float.h> | #include <float.h> | ||||
| #include <limits.h> | #include <limits.h> | ||||
| #include <stdalign.h> | |||||
| #include <stddef.h> | #include <stddef.h> | ||||
| #include <stdio.h> | #include <stdio.h> | ||||
| #include <stdlib.h> | #include <stdlib.h> | ||||
| Context not available. | |||||
| #include "rna_internal.h" | #include "rna_internal.h" | ||||
| #include "CLG_log.h" | #include "CLG_log.h" | ||||
| #include "RNA_types.h" | |||||
| static CLG_LogRef LOG = {"rna.define"}; | static CLG_LogRef LOG = {"rna.define"}; | ||||
| Context not available. | |||||
| # define DESCR_CHECK(description, id1, id2) | # define DESCR_CHECK(description, id1, id2) | ||||
| #endif | #endif | ||||
| /* Functions that are no longer extern */ | |||||
| int rna_parameter_size(PropertyRNA *parm); | |||||
| void rna_addtail(ListBase *listbase, void *vlink) | void rna_addtail(ListBase *listbase, void *vlink) | ||||
| { | { | ||||
| Link *link = vlink; | Link *link = vlink; | ||||
| Context not available. | |||||
| return sizeof(char *); | return sizeof(char *); | ||||
| } | } | ||||
| case PROP_POINTER: { | case PROP_POINTER: { | ||||
| #ifdef RNA_RUNTIME | |||||
| if (parm->flag_parameter & PARM_RNAPTR) { | if (parm->flag_parameter & PARM_RNAPTR) { | ||||
| if (parm->flag & PROP_THICK_WRAP) { | if (parm->flag & PROP_THICK_WRAP) { | ||||
| return sizeof(PointerRNA); | return sizeof(PointerRNA); | ||||
| } | } | ||||
| else { | return sizeof(PointerRNA *); | ||||
| return sizeof(PointerRNA *); | } | ||||
| } | return sizeof(void *); | ||||
| } | |||||
| case PROP_COLLECTION: | |||||
| return sizeof(ListBase); | |||||
| } | |||||
| } | |||||
| return sizeof(void *); | |||||
| } | |||||
| int rna_parameter_alignment(PropertyRNA *parm) | |||||
linux_dr: I think `rna_parameter_size()` and `rna_parameter_alignment()` should be one function that… | |||||
brechtUnsubmitted Not Done Inline ActionsI don't think we need a rna_parameter_alignment function, we can use power_of_2_max_i(rna_parameter_size(parm)). These parameters are small enough that it doesn't matter if there is some wasted space. brecht: I don't think we need a `rna_parameter_alignment` function, we can use `power_of_2_max_i… | |||||
linux_drAuthorUnsubmitted Not Done Inline ActionsThere are places where the alignment isn't the same as the type size, for instance: sizeof(ParameterDynAlloc) linux_dr: There are places where the alignment isn't the same as the type size, for instance: `sizeof… | |||||
| { | |||||
| if (!parm) { | |||||
| return 1; /* default to no alignment */ | |||||
| } | |||||
| PropertyType ptype = parm->type; | |||||
| int len = parm->totarraylength; | |||||
| /* XXX in other parts is mentioned that strings can be dynamic as well */ | |||||
| if (parm->flag & PROP_DYNAMIC) { | |||||
| return alignof(ParameterDynAlloc); | |||||
| } | |||||
| if (len > 0) { | |||||
| switch (ptype) { | |||||
| case PROP_BOOLEAN: | |||||
| return alignof(bool); | |||||
| case PROP_INT: | |||||
| return alignof(int); | |||||
| case PROP_FLOAT: | |||||
| return alignof(float); | |||||
| default: | |||||
| break; | |||||
| } | |||||
| } | |||||
| else { | |||||
| switch (ptype) { | |||||
| case PROP_BOOLEAN: | |||||
| return alignof(bool); | |||||
| case PROP_INT: | |||||
| case PROP_ENUM: | |||||
| return alignof(int); | |||||
| case PROP_FLOAT: | |||||
| return alignof(float); | |||||
| case PROP_STRING: | |||||
| /* return values don't store a pointer to the original */ | |||||
| if (parm->flag & PROP_THICK_WRAP) { | |||||
| return alignof(char); | |||||
| } | } | ||||
| else { | else { | ||||
| return sizeof(void *); | return alignof(char *); | ||||
| } | } | ||||
| #else | case PROP_POINTER: { | ||||
| if (parm->flag_parameter & PARM_RNAPTR) { | if (parm->flag_parameter & PARM_RNAPTR) { | ||||
| if (parm->flag & PROP_THICK_WRAP) { | if (parm->flag & PROP_THICK_WRAP) { | ||||
| return sizeof(PointerRNA); | return alignof(PointerRNA); | ||||
| } | } | ||||
| return sizeof(PointerRNA *); | return alignof(PointerRNA *); | ||||
| } | } | ||||
| return sizeof(void *); | return alignof(void *); | ||||
| #endif | |||||
| } | } | ||||
| case PROP_COLLECTION: | case PROP_COLLECTION: | ||||
| return sizeof(ListBase); | return alignof(ListBase); | ||||
| } | } | ||||
| } | } | ||||
| return sizeof(void *); | return alignof(void *); | ||||
| } | |||||
| int rna_aligned_parameter_size(int size_so_far, PropertyRNA *this_parm, PropertyRNA *next_parm) | |||||
linux_drAuthorUnsubmitted Done Inline ActionsThis seems like it overlaps some with ParameterIterator which probably needs some changes to handle size and padding as distinct. linux_dr: This seems like it overlaps some with `ParameterIterator` which probably needs some changes to… | |||||
brechtUnsubmitted Done Inline ActionsI think this concept of "aligned parameter size" is confusing. We should be thinking in terms of aligning the offset, not the size. I think a function like this would be better: int rna_parameter_align_offset(const int offset, PropertyRNA *parm)
{
const int alignment = power_of_2_max_i(rna_parameter_size(parm));
return (offset + alignment - 1) & ~(alignment - 1);
}brecht: I think this concept of "aligned parameter size" is confusing. We should be thinking in terms… | |||||
linux_drAuthorUnsubmitted Done Inline ActionsI think I adopted the intent of this approach, even if I haven't done it the same way. linux_dr: I think I adopted the intent of this approach, even if I haven't done it the same way. | |||||
| { | |||||
| int param_size = rna_parameter_size(this_parm); | |||||
| int next_alignment = rna_parameter_alignment(next_parm); | |||||
| int mis_alignment = (size_so_far + param_size) % next_alignment; | |||||
| int padding = (mis_alignment == 0) ? 0 : (next_alignment - mis_alignment); | |||||
| return param_size + padding; | |||||
| } | } | ||||
| /* Dynamic Enums */ | /* Dynamic Enums */ | ||||
| Context not available. | |||||
I think rna_parameter_size() and rna_parameter_alignment() should be one function that populates a struct instead.