Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCampbell Barton <ideasman42@gmail.com>2021-09-04 07:22:44 +0300
committerCampbell Barton <ideasman42@gmail.com>2021-09-04 09:59:54 +0300
commite6194e735791b42feb51e810a4910a41d999d3bf (patch)
tree95889982ba8c6bc88f5bdfb2eded77159d81ca89 /source/blender/editors/animation
parent716682365c6bcc1b5f757232ce1d2499b0d062a9 (diff)
RNA: support extracting names from paths without allocating memory
Support extracting identifiers RNA paths into fixed size buffer since the maximum size of the identifier is known all cases. - Add BLI_str_unescape_ex to support limiting the destination buffer. - Add BLI_str_quoted_substr to copy values into a fixed size buffer.
Diffstat (limited to 'source/blender/editors/animation')
-rw-r--r--source/blender/editors/animation/anim_deps.c7
-rw-r--r--source/blender/editors/animation/anim_filter.c25
-rw-r--r--source/blender/editors/animation/anim_ipo_utils.c30
-rw-r--r--source/blender/editors/animation/keyframes_general.c9
-rw-r--r--source/blender/editors/animation/keyframing.c16
5 files changed, 37 insertions, 50 deletions
diff --git a/source/blender/editors/animation/anim_deps.c b/source/blender/editors/animation/anim_deps.c
index 916d4232f03..97679723d84 100644
--- a/source/blender/editors/animation/anim_deps.c
+++ b/source/blender/editors/animation/anim_deps.c
@@ -206,16 +206,17 @@ static void animchan_sync_fcurve_scene(bAnimListElem *ale)
BLI_assert(GS(owner_id->name) == ID_SCE);
Scene *scene = (Scene *)owner_id;
FCurve *fcu = (FCurve *)ale->data;
+ Sequence *seq = NULL;
/* Only affect if F-Curve involves sequence_editor.sequences. */
- char *seq_name = BLI_str_quoted_substrN(fcu->rna_path, "sequences_all[");
- if (seq_name == NULL) {
+ char seq_name[sizeof(seq->name)];
+ if (!BLI_str_quoted_substr(fcu->rna_path, "sequences_all[", seq_name, sizeof(seq_name))) {
return;
}
/* Check if this strip is selected. */
Editing *ed = SEQ_editing_get(scene);
- Sequence *seq = SEQ_get_sequence_by_name(ed->seqbasep, seq_name, false);
+ seq = SEQ_get_sequence_by_name(ed->seqbasep, seq_name, false);
MEM_freeN(seq_name);
if (seq == NULL) {
diff --git a/source/blender/editors/animation/anim_filter.c b/source/blender/editors/animation/anim_filter.c
index 104540e2257..b12e0ae5cab 100644
--- a/source/blender/editors/animation/anim_filter.c
+++ b/source/blender/editors/animation/anim_filter.c
@@ -1061,13 +1061,14 @@ static bool skip_fcurve_selected_data(bDopeSheet *ads, FCurve *fcu, ID *owner_id
if (GS(owner_id->name) == ID_OB) {
Object *ob = (Object *)owner_id;
- char *bone_name;
+ bPoseChannel *pchan = NULL;
+ char bone_name[sizeof(pchan->name)];
/* Only consider if F-Curve involves `pose.bones`. */
- if (fcu->rna_path && (bone_name = BLI_str_quoted_substrN(fcu->rna_path, "pose.bones["))) {
+ if (fcu->rna_path &&
+ BLI_str_quoted_substr(fcu->rna_path, "pose.bones[", bone_name, sizeof(bone_name))) {
/* Get bone-name, and check if this bone is selected. */
- bPoseChannel *pchan = BKE_pose_channel_find_name(ob->pose, bone_name);
- MEM_freeN(bone_name);
+ pchan = BKE_pose_channel_find_name(ob->pose, bone_name);
/* check whether to continue or skip */
if (pchan && pchan->bone) {
@@ -1097,17 +1098,17 @@ static bool skip_fcurve_selected_data(bDopeSheet *ads, FCurve *fcu, ID *owner_id
}
else if (GS(owner_id->name) == ID_SCE) {
Scene *scene = (Scene *)owner_id;
- char *seq_name;
+ Sequence *seq = NULL;
+ char seq_name[sizeof(seq->name)];
/* Only consider if F-Curve involves `sequence_editor.sequences`. */
- if (fcu->rna_path && (seq_name = BLI_str_quoted_substrN(fcu->rna_path, "sequences_all["))) {
+ if (fcu->rna_path &&
+ BLI_str_quoted_substr(fcu->rna_path, "sequences_all[", seq_name, sizeof(seq_name))) {
/* Get strip name, and check if this strip is selected. */
- Sequence *seq = NULL;
Editing *ed = SEQ_editing_get(scene);
if (ed) {
seq = SEQ_get_sequence_by_name(ed->seqbasep, seq_name, false);
}
- MEM_freeN(seq_name);
/* Can only add this F-Curve if it is selected. */
if (ads->filterflag & ADS_FILTER_ONLYSEL) {
@@ -1139,14 +1140,14 @@ static bool skip_fcurve_selected_data(bDopeSheet *ads, FCurve *fcu, ID *owner_id
}
else if (GS(owner_id->name) == ID_NT) {
bNodeTree *ntree = (bNodeTree *)owner_id;
- char *node_name;
+ bNode *node = NULL;
+ char node_name[sizeof(node->name)];
/* Check for selected nodes. */
- if (fcu->rna_path && (node_name = BLI_str_quoted_substrN(fcu->rna_path, "nodes["))) {
- bNode *node = NULL;
+ if (fcu->rna_path &&
+ (BLI_str_quoted_substr(fcu->rna_path, "nodes[", node_name, sizeof(node_name)))) {
/* Get strip name, and check if this strip is selected. */
node = nodeFindNodebyName(ntree, node_name);
- MEM_freeN(node_name);
/* Can only add this F-Curve if it is selected. */
if (node) {
diff --git a/source/blender/editors/animation/anim_ipo_utils.c b/source/blender/editors/animation/anim_ipo_utils.c
index eda87cf1897..33b4882927a 100644
--- a/source/blender/editors/animation/anim_ipo_utils.c
+++ b/source/blender/editors/animation/anim_ipo_utils.c
@@ -106,23 +106,14 @@ int getname_anim_fcurve(char *name, ID *id, FCurve *fcu)
* - If a pointer just refers to the ID-block, then don't repeat this info
* since this just introduces clutter.
*/
- if (strstr(fcu->rna_path, "bones") && strstr(fcu->rna_path, "constraints")) {
- /* perform string 'chopping' to get "Bone Name : Constraint Name" */
- char *pchanName = BLI_str_quoted_substrN(fcu->rna_path, "bones[");
- char *constName = BLI_str_quoted_substrN(fcu->rna_path, "constraints[");
+
+ char pchanName[256], constName[256];
+ if (BLI_str_quoted_substr(fcu->rna_path, "bones[", pchanName, sizeof(pchanName)) &&
+ BLI_str_quoted_substr(fcu->rna_path, "constraints[", constName, sizeof(constName))) {
/* assemble the string to display in the UI... */
- structname = BLI_sprintfN(
- "%s : %s", pchanName ? pchanName : "", constName ? constName : "");
+ structname = BLI_sprintfN("%s : %s", pchanName, constName);
free_structname = 1;
-
- /* free the temp names */
- if (pchanName) {
- MEM_freeN(pchanName);
- }
- if (constName) {
- MEM_freeN(constName);
- }
}
else if (ptr.data != ptr.owner_id) {
PropertyRNA *nameprop = RNA_struct_name_property(ptr.type);
@@ -139,18 +130,15 @@ int getname_anim_fcurve(char *name, ID *id, FCurve *fcu)
* displaying the struct name alone is no meaningful information (and also cannot be
* filtered well), same for modifiers. So display strip name alongside as well. */
if (GS(ptr.owner_id->name) == ID_SCE) {
- if (BLI_str_startswith(fcu->rna_path, "sequence_editor.sequences_all[\"")) {
+ char stripname[256];
+ if (BLI_str_quoted_substr(
+ fcu->rna_path, "sequence_editor.sequences_all[", stripname, sizeof(stripname))) {
if (strstr(fcu->rna_path, ".transform.") || strstr(fcu->rna_path, ".crop.") ||
strstr(fcu->rna_path, ".modifiers[")) {
- char *stripname = BLI_str_quoted_substrN(fcu->rna_path, "sequences_all[");
- const char *structname_all = BLI_sprintfN(
- "%s : %s", stripname ? stripname : "", structname);
+ const char *structname_all = BLI_sprintfN("%s : %s", stripname, structname);
if (free_structname) {
MEM_freeN((void *)structname);
}
- if (stripname) {
- MEM_freeN(stripname);
- }
structname = structname_all;
free_structname = 1;
}
diff --git a/source/blender/editors/animation/keyframes_general.c b/source/blender/editors/animation/keyframes_general.c
index 9f3fe239113..ec33a42af3b 100644
--- a/source/blender/editors/animation/keyframes_general.c
+++ b/source/blender/editors/animation/keyframes_general.c
@@ -761,11 +761,10 @@ short copy_animedit_keys(bAnimContext *ac, ListBase *anim_data)
if ((aci->id_type == ID_OB) && (((Object *)aci->id)->type == OB_ARMATURE) && aci->rna_path) {
Object *ob = (Object *)aci->id;
- char *bone_name = BLI_str_quoted_substrN(aci->rna_path, "pose.bones[");
- if (bone_name) {
- bPoseChannel *pchan = BKE_pose_channel_find_name(ob->pose, bone_name);
- MEM_freeN(bone_name);
-
+ bPoseChannel *pchan;
+ char bone_name[sizeof(pchan->name)];
+ if (BLI_str_quoted_substr(aci->rna_path, "pose.bones[", bone_name, sizeof(bone_name))) {
+ pchan = BKE_pose_channel_find_name(ob->pose, bone_name);
if (pchan) {
aci->is_bone = true;
}
diff --git a/source/blender/editors/animation/keyframing.c b/source/blender/editors/animation/keyframing.c
index 292d665caca..8dc4aed9f0e 100644
--- a/source/blender/editors/animation/keyframing.c
+++ b/source/blender/editors/animation/keyframing.c
@@ -2218,11 +2218,11 @@ static int clear_anim_v3d_exec(bContext *C, wmOperator *UNUSED(op))
if (ob->mode & OB_MODE_POSE) {
if (fcu->rna_path) {
/* Get bone-name, and check if this bone is selected. */
- char *bone_name = BLI_str_quoted_substrN(fcu->rna_path, "pose.bones[");
- if (bone_name) {
- bPoseChannel *pchan = BKE_pose_channel_find_name(ob->pose, bone_name);
- MEM_freeN(bone_name);
-
+ bPoseChannel *pchan = NULL;
+ char bone_name[sizeof(pchan->name)];
+ if (BLI_str_quoted_substr(
+ fcu->rna_path, "pose.bones[", bone_name, sizeof(bone_name))) {
+ pchan = BKE_pose_channel_find_name(ob->pose, bone_name);
/* Delete if bone is selected. */
if ((pchan) && (pchan->bone)) {
if (pchan->bone->flag & BONE_SELECTED) {
@@ -2323,13 +2323,11 @@ static int delete_key_v3d_without_keying_set(bContext *C, wmOperator *op)
bPoseChannel *pchan = NULL;
/* Get bone-name, and check if this bone is selected. */
- char *bone_name = BLI_str_quoted_substrN(fcu->rna_path, "pose.bones[");
- if (bone_name == NULL) {
+ char bone_name[sizeof(pchan->name)];
+ if (!BLI_str_quoted_substr(fcu->rna_path, "pose.bones[", bone_name, sizeof(bone_name))) {
continue;
}
-
pchan = BKE_pose_channel_find_name(ob->pose, bone_name);
- MEM_freeN(bone_name);
/* skip if bone is not selected */
if ((pchan) && (pchan->bone)) {