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.
Details
- Reviewers
Jon Denning (gfxcoder) - Maniphest Tasks
- T98973: Renaming Custom Python Properties is Incorrect
Diff Detail
- Repository
- rB Blender
Event Timeline
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?
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.