Cleanup: Py API naming
Use BPY_execute_* prefix for all Python execution commands
This commit is contained in:
@@ -72,10 +72,12 @@ void BPY_thread_restore(BPy_ThreadStatePtr tstate);
|
||||
#define BPy_BEGIN_ALLOW_THREADS { BPy_ThreadStatePtr _bpy_saved_tstate = BPY_thread_save(); (void)0
|
||||
#define BPy_END_ALLOW_THREADS BPY_thread_restore(_bpy_saved_tstate); } (void)0
|
||||
|
||||
bool BPY_execute_filepath(struct bContext *C, const char *filepath, struct ReportList *reports);
|
||||
bool BPY_execute_text(struct bContext *C, struct Text *text, struct ReportList *reports, const bool do_jump);
|
||||
bool BPY_execute_string_as_number(struct bContext *C, const char *expr, double *value, const bool verbose);
|
||||
bool BPY_execute_string_ex(struct bContext *C, const char *expr, bool use_eval);
|
||||
bool BPY_execute_string(struct bContext *C, const char *expr);
|
||||
|
||||
/* 2.5 UI Scripts */
|
||||
int BPY_filepath_exec(struct bContext *C, const char *filepath, struct ReportList *reports);
|
||||
int BPY_text_exec(struct bContext *C, struct Text *text, struct ReportList *reports, const bool do_jump);
|
||||
void BPY_text_free_code(struct Text *text);
|
||||
void BPY_modules_update(struct bContext *C); // XXX - annoying, need this for pointers that get out of date
|
||||
void BPY_modules_load_user(struct bContext *C);
|
||||
@@ -85,10 +87,6 @@ void BPY_app_handlers_reset(const short do_all);
|
||||
void BPY_driver_reset(void);
|
||||
float BPY_driver_exec(struct ChannelDriver *driver, const float evaltime);
|
||||
|
||||
int BPY_button_exec(struct bContext *C, const char *expr, double *value, const bool verbose);
|
||||
int BPY_string_exec_ex(struct bContext *C, const char *expr, bool use_eval);
|
||||
int BPY_string_exec(struct bContext *C, const char *expr);
|
||||
|
||||
void BPY_DECREF(void *pyob_ptr); /* Py_DECREF() */
|
||||
void BPY_DECREF_RNA_INVALIDATE(void *pyob_ptr);
|
||||
int BPY_context_member_get(struct bContext *C, const char *member, struct bContextDataResult *result);
|
||||
|
@@ -971,14 +971,14 @@ PyObject *PyC_FlagSet_FromBitfield(PyC_FlagSet *items, int flag)
|
||||
|
||||
|
||||
/**
|
||||
* \return -1 on error, else 0
|
||||
* \return success
|
||||
*
|
||||
* \note it is caller's responsibility to acquire & release GIL!
|
||||
*/
|
||||
int PyC_RunString_AsNumber(const char *expr, double *value, const char *filename)
|
||||
bool PyC_RunString_AsNumber(const char *expr, double *value, const char *filename)
|
||||
{
|
||||
PyObject *py_dict, *mod, *retval;
|
||||
int error_ret = 0;
|
||||
bool ok = true;
|
||||
PyObject *main_mod = NULL;
|
||||
|
||||
PyC_MainModule_Backup(&main_mod);
|
||||
@@ -998,7 +998,7 @@ int PyC_RunString_AsNumber(const char *expr, double *value, const char *filename
|
||||
retval = PyRun_String(expr, Py_eval_input, py_dict, py_dict);
|
||||
|
||||
if (retval == NULL) {
|
||||
error_ret = -1;
|
||||
ok = false;
|
||||
}
|
||||
else {
|
||||
double val;
|
||||
@@ -1024,7 +1024,7 @@ int PyC_RunString_AsNumber(const char *expr, double *value, const char *filename
|
||||
Py_DECREF(retval);
|
||||
|
||||
if (val == -1 && PyErr_Occurred()) {
|
||||
error_ret = -1;
|
||||
ok = false;
|
||||
}
|
||||
else if (!finite(val)) {
|
||||
*value = 0.0;
|
||||
@@ -1036,7 +1036,7 @@ int PyC_RunString_AsNumber(const char *expr, double *value, const char *filename
|
||||
|
||||
PyC_MainModule_Restore(main_mod);
|
||||
|
||||
return error_ret;
|
||||
return ok;
|
||||
}
|
||||
|
||||
#endif /* #ifndef MATH_STANDALONE */
|
||||
|
@@ -79,7 +79,7 @@ int PyC_FlagSet_ValueFromID(PyC_FlagSet *item, const char *identifier, int
|
||||
int PyC_FlagSet_ToBitfield(PyC_FlagSet *items, PyObject *value, int *r_value, const char *error_prefix);
|
||||
PyObject *PyC_FlagSet_FromBitfield(PyC_FlagSet *items, int flag);
|
||||
|
||||
int PyC_RunString_AsNumber(const char *expr, double *value, const char *filename);
|
||||
bool PyC_RunString_AsNumber(const char *expr, double *value, const char *filename);
|
||||
|
||||
int PyC_ParseBool(PyObject *o, void *p);
|
||||
|
||||
|
@@ -424,8 +424,9 @@ typedef struct {
|
||||
} PyModuleObject;
|
||||
#endif
|
||||
|
||||
static int python_script_exec(bContext *C, const char *fn, struct Text *text,
|
||||
struct ReportList *reports, const bool do_jump)
|
||||
static bool python_script_exec(
|
||||
bContext *C, const char *fn, struct Text *text,
|
||||
struct ReportList *reports, const bool do_jump)
|
||||
{
|
||||
Main *bmain_old = CTX_data_main(C);
|
||||
PyObject *main_mod = NULL;
|
||||
@@ -543,13 +544,13 @@ static int python_script_exec(bContext *C, const char *fn, struct Text *text,
|
||||
}
|
||||
|
||||
/* Can run a file or text block */
|
||||
int BPY_filepath_exec(bContext *C, const char *filepath, struct ReportList *reports)
|
||||
bool BPY_execute_filepath(bContext *C, const char *filepath, struct ReportList *reports)
|
||||
{
|
||||
return python_script_exec(C, filepath, NULL, reports, false);
|
||||
}
|
||||
|
||||
|
||||
int BPY_text_exec(bContext *C, struct Text *text, struct ReportList *reports, const bool do_jump)
|
||||
bool BPY_execute_text(bContext *C, struct Text *text, struct ReportList *reports, const bool do_jump)
|
||||
{
|
||||
return python_script_exec(C, NULL, text, reports, do_jump);
|
||||
}
|
||||
@@ -572,24 +573,26 @@ void BPY_DECREF_RNA_INVALIDATE(void *pyob_ptr)
|
||||
PyGILState_Release(gilstate);
|
||||
}
|
||||
|
||||
/* return -1 on error, else 0 */
|
||||
int BPY_button_exec(bContext *C, const char *expr, double *value, const bool verbose)
|
||||
/**
|
||||
* \return success
|
||||
*/
|
||||
bool BPY_execute_string_as_number(bContext *C, const char *expr, double *value, const bool verbose)
|
||||
{
|
||||
PyGILState_STATE gilstate;
|
||||
int error_ret = 0;
|
||||
bool ok = true;
|
||||
|
||||
if (!value || !expr) return -1;
|
||||
|
||||
if (expr[0] == '\0') {
|
||||
*value = 0.0;
|
||||
return error_ret;
|
||||
return ok;
|
||||
}
|
||||
|
||||
bpy_context_set(C, &gilstate);
|
||||
|
||||
error_ret = PyC_RunString_AsNumber(expr, value, "<blender button>");
|
||||
ok = PyC_RunString_AsNumber(expr, value, "<blender button>");
|
||||
|
||||
if (error_ret) {
|
||||
if (ok == false) {
|
||||
if (verbose) {
|
||||
BPy_errors_to_report_ex(CTX_wm_reports(C), false, false);
|
||||
}
|
||||
@@ -600,21 +603,21 @@ int BPY_button_exec(bContext *C, const char *expr, double *value, const bool ver
|
||||
|
||||
bpy_context_clear(C, &gilstate);
|
||||
|
||||
return error_ret;
|
||||
return ok;
|
||||
}
|
||||
|
||||
int BPY_string_exec_ex(bContext *C, const char *expr, bool use_eval)
|
||||
bool BPY_execute_string_ex(bContext *C, const char *expr, bool use_eval)
|
||||
{
|
||||
PyGILState_STATE gilstate;
|
||||
PyObject *main_mod = NULL;
|
||||
PyObject *py_dict, *retval;
|
||||
int error_ret = 0;
|
||||
bool ok = true;
|
||||
Main *bmain_back; /* XXX, quick fix for release (Copy Settings crash), needs further investigation */
|
||||
|
||||
if (!expr) return -1;
|
||||
|
||||
if (expr[0] == '\0') {
|
||||
return error_ret;
|
||||
return ok;
|
||||
}
|
||||
|
||||
bpy_context_set(C, &gilstate);
|
||||
@@ -631,7 +634,7 @@ int BPY_string_exec_ex(bContext *C, const char *expr, bool use_eval)
|
||||
bpy_import_main_set(bmain_back);
|
||||
|
||||
if (retval == NULL) {
|
||||
error_ret = -1;
|
||||
ok = false;
|
||||
|
||||
BPy_errors_to_report(CTX_wm_reports(C));
|
||||
}
|
||||
@@ -643,12 +646,12 @@ int BPY_string_exec_ex(bContext *C, const char *expr, bool use_eval)
|
||||
|
||||
bpy_context_clear(C, &gilstate);
|
||||
|
||||
return error_ret;
|
||||
return ok;
|
||||
}
|
||||
|
||||
int BPY_string_exec(bContext *C, const char *expr)
|
||||
bool BPY_execute_string(bContext *C, const char *expr)
|
||||
{
|
||||
return BPY_string_exec_ex(C, expr, true);
|
||||
return BPY_execute_string_ex(C, expr, true);
|
||||
}
|
||||
|
||||
void BPY_modules_load_user(bContext *C)
|
||||
|
@@ -201,7 +201,7 @@ static PyObject *bpyunits_to_value(PyObject *UNUSED(self), PyObject *args, PyObj
|
||||
|
||||
bUnit_ReplaceString(str, (int)str_len, uref, scale, usys, ucat);
|
||||
|
||||
if (PyC_RunString_AsNumber(str, &result, "<bpy_units_api>") != 0) {
|
||||
if (!PyC_RunString_AsNumber(str, &result, "<bpy_units_api>")) {
|
||||
if (PyErr_Occurred()) {
|
||||
PyErr_Print();
|
||||
PyErr_Clear();
|
||||
|
Reference in New Issue
Block a user