forked from blender/blender
WIP: uv-simple-select #1
@ -94,7 +94,7 @@ void python_thread_state_restore(void **python_thread_state)
|
|||||||
*python_thread_state = NULL;
|
*python_thread_state = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
static const char *PyC_UnicodeAsByte(PyObject *py_str, PyObject **coerce)
|
static const char *PyC_UnicodeAsBytes(PyObject *py_str, PyObject **coerce)
|
||||||
{
|
{
|
||||||
const char *result = PyUnicode_AsUTF8(py_str);
|
const char *result = PyUnicode_AsUTF8(py_str);
|
||||||
if (result) {
|
if (result) {
|
||||||
@ -131,8 +131,8 @@ static PyObject *init_func(PyObject * /*self*/, PyObject *args)
|
|||||||
}
|
}
|
||||||
|
|
||||||
PyObject *path_coerce = nullptr, *user_path_coerce = nullptr;
|
PyObject *path_coerce = nullptr, *user_path_coerce = nullptr;
|
||||||
path_init(PyC_UnicodeAsByte(path, &path_coerce),
|
path_init(PyC_UnicodeAsBytes(path, &path_coerce),
|
||||||
PyC_UnicodeAsByte(user_path, &user_path_coerce));
|
PyC_UnicodeAsBytes(user_path, &user_path_coerce));
|
||||||
Py_XDECREF(path_coerce);
|
Py_XDECREF(path_coerce);
|
||||||
Py_XDECREF(user_path_coerce);
|
Py_XDECREF(user_path_coerce);
|
||||||
|
|
||||||
|
@ -54,7 +54,7 @@ static PyObject *idprop_py_from_idp_string(const IDProperty *prop)
|
|||||||
}
|
}
|
||||||
|
|
||||||
#ifdef USE_STRING_COERCE
|
#ifdef USE_STRING_COERCE
|
||||||
return PyC_UnicodeFromByteAndSize(IDP_Array(prop), prop->len - 1);
|
return PyC_UnicodeFromBytesAndSize(IDP_Array(prop), prop->len - 1);
|
||||||
#else
|
#else
|
||||||
return PyUnicode_FromStringAndSize(IDP_String(prop), prop->len - 1);
|
return PyUnicode_FromStringAndSize(IDP_String(prop), prop->len - 1);
|
||||||
#endif
|
#endif
|
||||||
@ -192,7 +192,7 @@ static int BPy_IDGroup_SetData(BPy_IDProperty *self, IDProperty *prop, PyObject
|
|||||||
int alloc_len;
|
int alloc_len;
|
||||||
PyObject *value_coerce = NULL;
|
PyObject *value_coerce = NULL;
|
||||||
|
|
||||||
st = (char *)PyC_UnicodeAsByte(value, &value_coerce);
|
st = (char *)PyC_UnicodeAsBytes(value, &value_coerce);
|
||||||
alloc_len = strlen(st) + 1;
|
alloc_len = strlen(st) + 1;
|
||||||
|
|
||||||
st = PyUnicode_AsUTF8(value);
|
st = PyUnicode_AsUTF8(value);
|
||||||
@ -433,7 +433,7 @@ static IDProperty *idp_from_PyUnicode(const char *name, PyObject *ob)
|
|||||||
#ifdef USE_STRING_COERCE
|
#ifdef USE_STRING_COERCE
|
||||||
Py_ssize_t value_size;
|
Py_ssize_t value_size;
|
||||||
PyObject *value_coerce = NULL;
|
PyObject *value_coerce = NULL;
|
||||||
val.string.str = PyC_UnicodeAsByteAndSize(ob, &value_size, &value_coerce);
|
val.string.str = PyC_UnicodeAsBytesAndSize(ob, &value_size, &value_coerce);
|
||||||
val.string.len = (int)value_size + 1;
|
val.string.len = (int)value_size + 1;
|
||||||
val.string.subtype = IDP_STRING_SUB_UTF8;
|
val.string.subtype = IDP_STRING_SUB_UTF8;
|
||||||
prop = IDP_New(IDP_STRING, &val, name);
|
prop = IDP_New(IDP_STRING, &val, name);
|
||||||
|
@ -261,7 +261,7 @@ static PyObject *py_imbuf_filepath_get(Py_ImBuf *self, void *UNUSED(closure))
|
|||||||
{
|
{
|
||||||
PY_IMBUF_CHECK_OBJ(self);
|
PY_IMBUF_CHECK_OBJ(self);
|
||||||
ImBuf *ibuf = self->ibuf;
|
ImBuf *ibuf = self->ibuf;
|
||||||
return PyC_UnicodeFromByte(ibuf->name);
|
return PyC_UnicodeFromBytes(ibuf->name);
|
||||||
}
|
}
|
||||||
|
|
||||||
static int py_imbuf_filepath_set(Py_ImBuf *self, PyObject *value, void *UNUSED(closure))
|
static int py_imbuf_filepath_set(Py_ImBuf *self, PyObject *value, void *UNUSED(closure))
|
||||||
|
@ -1012,7 +1012,7 @@ PyObject *PyC_ExceptionBuffer_Simple(void)
|
|||||||
* In some cases we need to coerce strings, avoid doing this inline.
|
* In some cases we need to coerce strings, avoid doing this inline.
|
||||||
* \{ */
|
* \{ */
|
||||||
|
|
||||||
const char *PyC_UnicodeAsByteAndSize(PyObject *py_str, Py_ssize_t *size, PyObject **coerce)
|
const char *PyC_UnicodeAsBytesAndSize(PyObject *py_str, Py_ssize_t *size, PyObject **coerce)
|
||||||
{
|
{
|
||||||
const char *result;
|
const char *result;
|
||||||
|
|
||||||
@ -1039,7 +1039,7 @@ const char *PyC_UnicodeAsByteAndSize(PyObject *py_str, Py_ssize_t *size, PyObjec
|
|||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
const char *PyC_UnicodeAsByte(PyObject *py_str, PyObject **coerce)
|
const char *PyC_UnicodeAsBytes(PyObject *py_str, PyObject **coerce)
|
||||||
{
|
{
|
||||||
const char *result;
|
const char *result;
|
||||||
|
|
||||||
@ -1064,7 +1064,7 @@ const char *PyC_UnicodeAsByte(PyObject *py_str, PyObject **coerce)
|
|||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
PyObject *PyC_UnicodeFromByteAndSize(const char *str, Py_ssize_t size)
|
PyObject *PyC_UnicodeFromBytesAndSize(const char *str, Py_ssize_t size)
|
||||||
{
|
{
|
||||||
PyObject *result = PyUnicode_FromStringAndSize(str, size);
|
PyObject *result = PyUnicode_FromStringAndSize(str, size);
|
||||||
if (result) {
|
if (result) {
|
||||||
@ -1079,9 +1079,9 @@ PyObject *PyC_UnicodeFromByteAndSize(const char *str, Py_ssize_t size)
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
PyObject *PyC_UnicodeFromByte(const char *str)
|
PyObject *PyC_UnicodeFromBytes(const char *str)
|
||||||
{
|
{
|
||||||
return PyC_UnicodeFromByteAndSize(str, strlen(str));
|
return PyC_UnicodeFromBytesAndSize(str, strlen(str));
|
||||||
}
|
}
|
||||||
|
|
||||||
/** \} */
|
/** \} */
|
||||||
@ -1101,7 +1101,7 @@ PyObject *PyC_DefaultNameSpace(const char *filename)
|
|||||||
if (filename) {
|
if (filename) {
|
||||||
/* __file__ mainly for nice UI'ness
|
/* __file__ mainly for nice UI'ness
|
||||||
* NOTE: this won't map to a real file when executing text-blocks and buttons. */
|
* NOTE: this won't map to a real file when executing text-blocks and buttons. */
|
||||||
PyModule_AddObject(mod_main, "__file__", PyC_UnicodeFromByte(filename));
|
PyModule_AddObject(mod_main, "__file__", PyC_UnicodeFromBytes(filename));
|
||||||
}
|
}
|
||||||
PyModule_AddObject(mod_main, "__builtins__", builtins);
|
PyModule_AddObject(mod_main, "__builtins__", builtins);
|
||||||
Py_INCREF(builtins); /* AddObject steals a reference */
|
Py_INCREF(builtins); /* AddObject steals a reference */
|
||||||
|
@ -105,14 +105,14 @@ void PyC_Tuple_Fill(PyObject *tuple, PyObject *value);
|
|||||||
void PyC_List_Fill(PyObject *list, PyObject *value);
|
void PyC_List_Fill(PyObject *list, PyObject *value);
|
||||||
|
|
||||||
/* follow http://www.python.org/dev/peps/pep-0383/ */
|
/* follow http://www.python.org/dev/peps/pep-0383/ */
|
||||||
PyObject *PyC_UnicodeFromByte(const char *str);
|
PyObject *PyC_UnicodeFromBytes(const char *str);
|
||||||
PyObject *PyC_UnicodeFromByteAndSize(const char *str, Py_ssize_t size);
|
PyObject *PyC_UnicodeFromBytesAndSize(const char *str, Py_ssize_t size);
|
||||||
const char *PyC_UnicodeAsByte(PyObject *py_str, PyObject **coerce); /* coerce must be NULL */
|
const char *PyC_UnicodeAsBytes(PyObject *py_str, PyObject **coerce); /* coerce must be NULL */
|
||||||
/**
|
/**
|
||||||
* String conversion, escape non-unicode chars
|
* String conversion, escape non-unicode chars
|
||||||
* \param coerce: must be set to NULL.
|
* \param coerce: must be set to NULL.
|
||||||
*/
|
*/
|
||||||
const char *PyC_UnicodeAsByteAndSize(PyObject *py_str, Py_ssize_t *size, PyObject **coerce);
|
const char *PyC_UnicodeAsBytesAndSize(PyObject *py_str, Py_ssize_t *size, PyObject **coerce);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Description: This function creates a new Python dictionary object.
|
* Description: This function creates a new Python dictionary object.
|
||||||
|
@ -74,11 +74,11 @@ static PyObject *bpy_script_paths(PyObject *UNUSED(self))
|
|||||||
const char *path;
|
const char *path;
|
||||||
|
|
||||||
path = BKE_appdir_folder_id(BLENDER_SYSTEM_SCRIPTS, NULL);
|
path = BKE_appdir_folder_id(BLENDER_SYSTEM_SCRIPTS, NULL);
|
||||||
item = PyC_UnicodeFromByte(path ? path : "");
|
item = PyC_UnicodeFromBytes(path ? path : "");
|
||||||
BLI_assert(item != NULL);
|
BLI_assert(item != NULL);
|
||||||
PyTuple_SET_ITEM(ret, 0, item);
|
PyTuple_SET_ITEM(ret, 0, item);
|
||||||
path = BKE_appdir_folder_id(BLENDER_USER_SCRIPTS, NULL);
|
path = BKE_appdir_folder_id(BLENDER_USER_SCRIPTS, NULL);
|
||||||
item = PyC_UnicodeFromByte(path ? path : "");
|
item = PyC_UnicodeFromBytes(path ? path : "");
|
||||||
BLI_assert(item != NULL);
|
BLI_assert(item != NULL);
|
||||||
PyTuple_SET_ITEM(ret, 1, item);
|
PyTuple_SET_ITEM(ret, 1, item);
|
||||||
|
|
||||||
@ -90,7 +90,7 @@ static bool bpy_blend_foreach_path_cb(BPathForeachPathData *bpath_data,
|
|||||||
const char *path_src)
|
const char *path_src)
|
||||||
{
|
{
|
||||||
PyObject *py_list = bpath_data->user_data;
|
PyObject *py_list = bpath_data->user_data;
|
||||||
PyList_APPEND(py_list, PyC_UnicodeFromByte(path_src));
|
PyList_APPEND(py_list, PyC_UnicodeFromBytes(path_src));
|
||||||
return false; /* Never edits the path. */
|
return false; /* Never edits the path. */
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -238,7 +238,7 @@ static PyObject *bpy_user_resource(PyObject *UNUSED(self), PyObject *args, PyObj
|
|||||||
* but best leave it up to the script author to create */
|
* but best leave it up to the script author to create */
|
||||||
path = BKE_appdir_folder_id_user_notest(type.value_found, subdir);
|
path = BKE_appdir_folder_id_user_notest(type.value_found, subdir);
|
||||||
|
|
||||||
return PyC_UnicodeFromByte(path ? path : "");
|
return PyC_UnicodeFromBytes(path ? path : "");
|
||||||
}
|
}
|
||||||
|
|
||||||
PyDoc_STRVAR(bpy_system_resource_doc,
|
PyDoc_STRVAR(bpy_system_resource_doc,
|
||||||
@ -279,7 +279,7 @@ static PyObject *bpy_system_resource(PyObject *UNUSED(self), PyObject *args, PyO
|
|||||||
|
|
||||||
path = BKE_appdir_folder_id(type.value_found, subdir);
|
path = BKE_appdir_folder_id(type.value_found, subdir);
|
||||||
|
|
||||||
return PyC_UnicodeFromByte(path ? path : "");
|
return PyC_UnicodeFromBytes(path ? path : "");
|
||||||
}
|
}
|
||||||
|
|
||||||
PyDoc_STRVAR(
|
PyDoc_STRVAR(
|
||||||
@ -326,7 +326,7 @@ static PyObject *bpy_resource_path(PyObject *UNUSED(self), PyObject *args, PyObj
|
|||||||
|
|
||||||
path = BKE_appdir_resource_path_id_with_version(type.value_found, false, (major * 100) + minor);
|
path = BKE_appdir_resource_path_id_with_version(type.value_found, false, (major * 100) + minor);
|
||||||
|
|
||||||
return PyC_UnicodeFromByte(path ? path : "");
|
return PyC_UnicodeFromBytes(path ? path : "");
|
||||||
}
|
}
|
||||||
|
|
||||||
/* This is only exposed for tests, see: `tests/python/bl_pyapi_bpy_driver_secure_eval.py`. */
|
/* This is only exposed for tests, see: `tests/python/bl_pyapi_bpy_driver_secure_eval.py`. */
|
||||||
|
@ -312,7 +312,7 @@ static int bpy_app_debug_value_set(PyObject *UNUSED(self), PyObject *value, void
|
|||||||
PyDoc_STRVAR(bpy_app_tempdir_doc, "String, the temp directory used by blender (read-only)");
|
PyDoc_STRVAR(bpy_app_tempdir_doc, "String, the temp directory used by blender (read-only)");
|
||||||
static PyObject *bpy_app_tempdir_get(PyObject *UNUSED(self), void *UNUSED(closure))
|
static PyObject *bpy_app_tempdir_get(PyObject *UNUSED(self), void *UNUSED(closure))
|
||||||
{
|
{
|
||||||
return PyC_UnicodeFromByte(BKE_tempdir_session());
|
return PyC_UnicodeFromBytes(BKE_tempdir_session());
|
||||||
}
|
}
|
||||||
|
|
||||||
PyDoc_STRVAR(
|
PyDoc_STRVAR(
|
||||||
@ -339,7 +339,7 @@ static PyObject *bpy_app_preview_render_size_get(PyObject *UNUSED(self), void *c
|
|||||||
|
|
||||||
static PyObject *bpy_app_autoexec_fail_message_get(PyObject *UNUSED(self), void *UNUSED(closure))
|
static PyObject *bpy_app_autoexec_fail_message_get(PyObject *UNUSED(self), void *UNUSED(closure))
|
||||||
{
|
{
|
||||||
return PyC_UnicodeFromByte(G.autoexec_fail);
|
return PyC_UnicodeFromBytes(G.autoexec_fail);
|
||||||
}
|
}
|
||||||
|
|
||||||
PyDoc_STRVAR(bpy_app_binary_path_doc,
|
PyDoc_STRVAR(bpy_app_binary_path_doc,
|
||||||
@ -348,7 +348,7 @@ PyDoc_STRVAR(bpy_app_binary_path_doc,
|
|||||||
"an empty string which script authors may point to a Blender binary.");
|
"an empty string which script authors may point to a Blender binary.");
|
||||||
static PyObject *bpy_app_binary_path_get(PyObject *UNUSED(self), void *UNUSED(closure))
|
static PyObject *bpy_app_binary_path_get(PyObject *UNUSED(self), void *UNUSED(closure))
|
||||||
{
|
{
|
||||||
return PyC_UnicodeFromByte(BKE_appdir_program_path());
|
return PyC_UnicodeFromBytes(BKE_appdir_program_path());
|
||||||
}
|
}
|
||||||
|
|
||||||
static int bpy_app_binary_path_set(PyObject *UNUSED(self), PyObject *value, void *UNUSED(closure))
|
static int bpy_app_binary_path_set(PyObject *UNUSED(self), PyObject *value, void *UNUSED(closure))
|
||||||
@ -359,7 +359,7 @@ static int bpy_app_binary_path_set(PyObject *UNUSED(self), PyObject *value, void
|
|||||||
return -1;
|
return -1;
|
||||||
#endif
|
#endif
|
||||||
PyObject *value_coerce = NULL;
|
PyObject *value_coerce = NULL;
|
||||||
const char *filepath = PyC_UnicodeAsByte(value, &value_coerce);
|
const char *filepath = PyC_UnicodeAsBytes(value, &value_coerce);
|
||||||
if (filepath == NULL) {
|
if (filepath == NULL) {
|
||||||
PyErr_Format(PyExc_ValueError, "expected a string or bytes, got %s", Py_TYPE(value)->tp_name);
|
PyErr_Format(PyExc_ValueError, "expected a string or bytes, got %s", Py_TYPE(value)->tp_name);
|
||||||
return -1;
|
return -1;
|
||||||
|
@ -118,7 +118,7 @@ static bool python_script_exec(bContext *C,
|
|||||||
char *buf;
|
char *buf;
|
||||||
PyObject *filepath_dummy_py;
|
PyObject *filepath_dummy_py;
|
||||||
|
|
||||||
filepath_dummy_py = PyC_UnicodeFromByte(filepath_dummy);
|
filepath_dummy_py = PyC_UnicodeFromBytes(filepath_dummy);
|
||||||
|
|
||||||
size_t buf_len_dummy;
|
size_t buf_len_dummy;
|
||||||
buf = txt_to_buf(text, &buf_len_dummy);
|
buf = txt_to_buf(text, &buf_len_dummy);
|
||||||
|
@ -1403,7 +1403,7 @@ PyObject *pyrna_prop_to_py(PointerRNA *ptr, PropertyRNA *prop)
|
|||||||
ret = PyBytes_FromStringAndSize(buf, buf_len);
|
ret = PyBytes_FromStringAndSize(buf, buf_len);
|
||||||
}
|
}
|
||||||
else if (ELEM(subtype, PROP_FILEPATH, PROP_DIRPATH, PROP_FILENAME)) {
|
else if (ELEM(subtype, PROP_FILEPATH, PROP_DIRPATH, PROP_FILENAME)) {
|
||||||
ret = PyC_UnicodeFromByteAndSize(buf, buf_len);
|
ret = PyC_UnicodeFromBytesAndSize(buf, buf_len);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
ret = PyUnicode_FromStringAndSize(buf, buf_len);
|
ret = PyUnicode_FromStringAndSize(buf, buf_len);
|
||||||
@ -1712,7 +1712,7 @@ static int pyrna_py_to_prop(
|
|||||||
PyObject *value_coerce = NULL;
|
PyObject *value_coerce = NULL;
|
||||||
if (ELEM(subtype, PROP_FILEPATH, PROP_DIRPATH, PROP_FILENAME)) {
|
if (ELEM(subtype, PROP_FILEPATH, PROP_DIRPATH, PROP_FILENAME)) {
|
||||||
/* TODO: get size. */
|
/* TODO: get size. */
|
||||||
param = PyC_UnicodeAsByte(value, &value_coerce);
|
param = PyC_UnicodeAsBytes(value, &value_coerce);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
param = PyUnicode_AsUTF8(value);
|
param = PyUnicode_AsUTF8(value);
|
||||||
@ -6057,7 +6057,7 @@ static PyObject *pyrna_param_to_py(PointerRNA *ptr, PropertyRNA *prop, void *dat
|
|||||||
ret = PyBytes_FromStringAndSize(data_ch, data_ch_len);
|
ret = PyBytes_FromStringAndSize(data_ch, data_ch_len);
|
||||||
}
|
}
|
||||||
else if (ELEM(subtype, PROP_FILEPATH, PROP_DIRPATH, PROP_FILENAME)) {
|
else if (ELEM(subtype, PROP_FILEPATH, PROP_DIRPATH, PROP_FILENAME)) {
|
||||||
ret = PyC_UnicodeFromByteAndSize(data_ch, data_ch_len);
|
ret = PyC_UnicodeFromBytesAndSize(data_ch, data_ch_len);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
ret = PyUnicode_FromStringAndSize(data_ch, data_ch_len);
|
ret = PyUnicode_FromStringAndSize(data_ch, data_ch_len);
|
||||||
|
@ -112,7 +112,7 @@ static PyObject *pyrna_WindowManager_clipboard_get(PyObject *UNUSED(self), void
|
|||||||
{
|
{
|
||||||
int text_len = 0;
|
int text_len = 0;
|
||||||
char *text = WM_clipboard_text_get(false, &text_len);
|
char *text = WM_clipboard_text_get(false, &text_len);
|
||||||
PyObject *result = PyC_UnicodeFromByteAndSize(text ? text : "", text_len);
|
PyObject *result = PyC_UnicodeFromBytesAndSize(text ? text : "", text_len);
|
||||||
if (text != NULL) {
|
if (text != NULL) {
|
||||||
MEM_freeN(text);
|
MEM_freeN(text);
|
||||||
}
|
}
|
||||||
@ -124,7 +124,7 @@ static int pyrna_WindowManager_clipboard_set(PyObject *UNUSED(self),
|
|||||||
void *UNUSED(flag))
|
void *UNUSED(flag))
|
||||||
{
|
{
|
||||||
PyObject *value_coerce = NULL;
|
PyObject *value_coerce = NULL;
|
||||||
const char *text = PyC_UnicodeAsByte(value, &value_coerce);
|
const char *text = PyC_UnicodeAsBytes(value, &value_coerce);
|
||||||
if (text == NULL) {
|
if (text == NULL) {
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user