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>2011-11-15 13:12:10 +0400
committerCampbell Barton <ideasman42@gmail.com>2011-11-15 13:12:10 +0400
commit2ab17326135e666dd31bb0695ebc2ef426615fae (patch)
tree57fb344834d44580aa45e1c82be56115116aec48 /source/blender/python/generic/IDProp.c
parentae046bc0eba28acb4101215e7dae411f99214ea1 (diff)
support for non-null terminated byte strings in id properties (as a subtype of IDP_STRING types)
Diffstat (limited to 'source/blender/python/generic/IDProp.c')
-rw-r--r--source/blender/python/generic/IDProp.c32
1 files changed, 27 insertions, 5 deletions
diff --git a/source/blender/python/generic/IDProp.c b/source/blender/python/generic/IDProp.c
index 6d869a7eb1f..d0759a69d8f 100644
--- a/source/blender/python/generic/IDProp.c
+++ b/source/blender/python/generic/IDProp.c
@@ -64,11 +64,18 @@ PyObject *BPy_IDGroup_WrapData( ID *id, IDProperty *prop )
{
switch ( prop->type ) {
case IDP_STRING:
+
+ if (prop->subtype == IDP_STRING_SUB_BYTE) {
+ return PyBytes_FromStringAndSize(IDP_Array(prop), prop->len);
+ }
+ else {
#ifdef USE_STRING_COERCE
- return PyC_UnicodeFromByteAndSize(IDP_Array(prop), prop->len - 1);
+ return PyC_UnicodeFromByteAndSize(IDP_Array(prop), prop->len - 1);
#else
- return PyUnicode_FromStringAndSize(IDP_Array(prop), prop->len - 1);
+ return PyUnicode_FromStringAndSize(IDP_Array(prop), prop->len - 1);
#endif
+ }
+
case IDP_INT:
return PyLong_FromLong( (long)prop->data.val );
case IDP_FLOAT:
@@ -332,7 +339,8 @@ const char *BPy_IDProperty_Map_ValidateAndCreate(PyObject *name_obj, IDProperty
else if (PyUnicode_Check(ob)) {
#ifdef USE_STRING_COERCE
PyObject *value_coerce= NULL;
- val.str = (char *)PyC_UnicodeAsByte(ob, &value_coerce);
+ val.string.str = (char *)PyC_UnicodeAsByte(ob, &value_coerce);
+ val.string.subtype = IDP_STRING_SUB_UTF8;
prop = IDP_New(IDP_STRING, val, name);
Py_XDECREF(value_coerce);
#else
@@ -340,6 +348,15 @@ const char *BPy_IDProperty_Map_ValidateAndCreate(PyObject *name_obj, IDProperty
prop = IDP_New(IDP_STRING, val, name);
#endif
}
+ else if (PyBytes_Check(ob)) {
+ val.string.str= PyBytes_AS_STRING(ob);
+ val.string.len= PyBytes_GET_SIZE(ob);
+ val.string.subtype= IDP_STRING_SUB_BYTE;
+
+ prop = IDP_New(IDP_STRING, val, name);
+ //prop = IDP_NewString(PyBytes_AS_STRING(ob), name, PyBytes_GET_SIZE(ob));
+ //prop->subtype= IDP_STRING_SUB_BYTE;
+ }
else if (PySequence_Check(ob)) {
PyObject *item;
int i;
@@ -493,11 +510,16 @@ static PyObject *BPy_IDGroup_MapDataToPy(IDProperty *prop)
{
switch (prop->type) {
case IDP_STRING:
+ if (prop->subtype == IDP_STRING_SUB_BYTE) {
+ return PyBytes_FromStringAndSize(IDP_Array(prop), prop->len);
+ }
+ else {
#ifdef USE_STRING_COERCE
- return PyC_UnicodeFromByteAndSize(IDP_Array(prop), prop->len - 1);
+ return PyC_UnicodeFromByteAndSize(IDP_Array(prop), prop->len - 1);
#else
- return PyUnicode_FromStringAndSize(IDP_Array(prop), prop->len - 1);
+ return PyUnicode_FromStringAndSize(IDP_Array(prop), prop->len - 1);
#endif
+ }
break;
case IDP_FLOAT:
return PyFloat_FromDouble(*((float*)&prop->data.val));