Page MenuHome

Fix T98973: Renaming Custom Python Properties is Incorrect
Needs ReviewPublic

Authored by Guillermo (guishe) on Jun 28 2022, 4:24 AM.

Details

Summary

Fix T98973: Renaming Custom Python Properties is Incorrect
The size that is used when renaming a property is corrected, the null terminator of the new name is copied correctly.

Diff Detail

Repository
rB Blender

Event Timeline

Guillermo (guishe) requested review of this revision.Jun 28 2022, 4:24 AM
Guillermo (guishe) created this revision.
Guillermo (guishe) created this object with visibility "Guillermo (guishe)".
Guillermo (guishe) created this object with edit policy "Guillermo (guishe)".
Guillermo (guishe) changed the edit policy from "Guillermo (guishe)" to "All Users".Jun 28 2022, 4:29 AM
Guillermo (guishe) changed the visibility from "Guillermo (guishe)" to "All Users".
Guillermo (guishe) changed the edit policy from "All Users" to "Guillermo (guishe)".
Guillermo (guishe) changed the visibility from "All Users" to "Public (No Login Required)".Jun 28 2022, 4:35 AM
Guillermo (guishe) changed the edit policy from "Guillermo (guishe)" to "All Users".

I updated the diff file because it only showed the changes, now it also shows the context.

I went back to see the T98973 task and I saw the second problem that @Jon Denning (gfxcoder) highlighted, I couldn't say if the data really persists when saving the file. Opening a new project and executing the code 'cycles\0anything' in bpy.context.scene in the Blender Python Console I get True as output

Update:
I added a debug print to check the data stored at the name address:

for(int x=0; x<=MAX_IDPROP_NAME; x++)
{
  printf("%x ",self->prop->name[x]);
}

I was able to verify that the data persists when saving and opening the file, but it is no longer accessible by the null terminator.

Using PyUnicode_AsUTF8AndSize, the method gets the full decoded data, even if there is a '\0' in the middle of the input, wouldn't it be better to use PyUnicode_AsUTF8String which truncates the string to the first null terminator?

Additionally I found a new problem renaming properties, we can have 2 or more with the same key
#

import bpy
C = bpy.context
C.scene['1'] = {'foo': 1}
C.scene['2'] = {'foo': 2}

list(C.scene.keys())
#['cycles', '1', '2']

C.scene['1'] = {'foo': 56}         #Override C.scene['1']

C.scene['2'].name = '1'           #Rename successfully

list(C.scene.keys())
#['cycles', '1', '1']

Should I report it as a bug?

Guillermo (guishe) updated this revision to Diff 53041.EditedJun 29 2022, 4:31 AM

Renaming a Custom Propertie now verify that no other sister Propertie have the same name.
Now the name is correctly truncated, PyUnicode_AsUTF8AndSize decoded the entire PyObject *name, PyUnicode_AsUTF8 decode until it found a '\0'.
The variable is cleared before it is renamed.