py api - added PyC_UnicodeFromByteAndSize() to match PyUnicode_FromStringAndSize()

also made RNA_property_string_get_alloc() return the length of the new string to avoid having to run strlen on it after.
This commit is contained in:
2011-10-22 10:49:35 +00:00
parent cac4fde224
commit ebe63b664b
15 changed files with 78 additions and 49 deletions

View File

@@ -67,9 +67,9 @@ PyObject *BPy_IDGroup_WrapData( ID *id, IDProperty *prop )
switch ( prop->type ) {
case IDP_STRING:
#ifdef USE_STRING_COERCE
return PyC_UnicodeFromByte(IDP_Array(prop));
return PyC_UnicodeFromByteAndSize(IDP_Array(prop), prop->len);
#else
return PyUnicode_FromString(IDP_Array(prop));
return PyUnicode_FromStringAndSize(IDP_Array(prop), prop->len);
#endif
case IDP_INT:
return PyLong_FromLong( (long)prop->data.val );
@@ -485,9 +485,9 @@ static PyObject *BPy_IDGroup_MapDataToPy(IDProperty *prop)
switch (prop->type) {
case IDP_STRING:
#ifdef USE_STRING_COERCE
return PyC_UnicodeFromByte(IDP_Array(prop));
return PyC_UnicodeFromByteAndSize(IDP_Array(prop), prop->len);
#else
return PyUnicode_FromString(IDP_Array(prop));
return PyUnicode_FromStringAndSize(IDP_Array(prop), prop->len);
#endif
break;
case IDP_FLOAT:

View File

@@ -386,9 +386,9 @@ const char *PyC_UnicodeAsByte(PyObject *py_str, PyObject **coerce)
}
}
PyObject *PyC_UnicodeFromByte(const char *str)
PyObject *PyC_UnicodeFromByteAndSize(const char *str, Py_ssize_t size)
{
PyObject *result= PyUnicode_FromString(str);
PyObject *result= PyUnicode_FromStringAndSize(str, size);
if (result) {
/* 99% of the time this is enough but we better support non unicode
* chars since blender doesnt limit this */
@@ -397,11 +397,16 @@ PyObject *PyC_UnicodeFromByte(const char *str)
else {
PyErr_Clear();
/* this means paths will always be accessible once converted, on all OS's */
result= PyUnicode_DecodeFSDefault(str);
result= PyUnicode_DecodeFSDefaultAndSize(str, size);
return result;
}
}
PyObject *PyC_UnicodeFromByte(const char *str)
{
return PyC_UnicodeFromByteAndSize(str, strlen(str));
}
/*****************************************************************************
* Description: This function creates a new Python dictionary object.
* note: dict is owned by sys.modules["__main__"] module, reference is borrowed

View File

@@ -40,8 +40,9 @@ void PyC_FileAndNum_Safe(const char **filename, int *lineno); /* checks python
int PyC_AsArray(void *array, PyObject *value, const int length, const PyTypeObject *type, const short is_double, const char *error_prefix);
/* follow http://www.python.org/dev/peps/pep-0383/ */
PyObject * PyC_UnicodeFromByte(const char *str);
const char * PyC_UnicodeAsByte(PyObject *py_str, PyObject **coerce); /* coerce must be NULL */
PyObject * PyC_UnicodeFromByte(const char *str);
PyObject * PyC_UnicodeFromByteAndSize(const char *str, Py_ssize_t size);
const char * PyC_UnicodeAsByte(PyObject *py_str, PyObject **coerce); /* coerce must be NULL */
/* name namespace function for bpy & bge */
PyObject * PyC_DefaultNameSpace(const char *filename);