formatting edits only to use more consisted style

This commit is contained in:
2011-12-26 12:26:11 +00:00
parent f48fb385ea
commit e17fd46c71
18 changed files with 1841 additions and 1824 deletions

View File

@@ -76,14 +76,14 @@
/* for internal use, when starting and ending python scripts */
/* incase a python script triggers another python call, stop bpy_context_clear from invalidating */
static int py_call_level= 0;
BPy_StructRNA *bpy_context_module= NULL; /* for fast access */
static int py_call_level = 0;
BPy_StructRNA *bpy_context_module = NULL; /* for fast access */
// #define TIME_PY_RUN // simple python tests. prints on exit.
#ifdef TIME_PY_RUN
#include "PIL_time.h"
static int bpy_timer_count= 0;
static int bpy_timer_count = 0;
static double bpy_timer; /* time since python starts */
static double bpy_timer_run; /* time for each python script run */
static double bpy_timer_run_tot; /* accumulate python runs */
@@ -102,18 +102,18 @@ void bpy_context_set(bContext *C, PyGILState_STATE *gilstate)
py_call_level++;
if (gilstate)
*gilstate= PyGILState_Ensure();
*gilstate = PyGILState_Ensure();
if (py_call_level==1) {
if (py_call_level == 1) {
bpy_context_update(C);
#ifdef TIME_PY_RUN
if (bpy_timer_count==0) {
if (bpy_timer_count == 0) {
/* record time from the beginning */
bpy_timer= PIL_check_seconds_timer();
bpy_timer_run= bpy_timer_run_tot= 0.0;
bpy_timer = PIL_check_seconds_timer();
bpy_timer_run = bpy_timer_run_tot = 0.0;
}
bpy_timer_run= PIL_check_seconds_timer();
bpy_timer_run = PIL_check_seconds_timer();
bpy_timer_count++;
@@ -132,7 +132,7 @@ void bpy_context_clear(bContext *UNUSED(C), PyGILState_STATE *gilstate)
if (py_call_level < 0) {
fprintf(stderr, "ERROR: Python context internal state bug. this should not happen!\n");
}
else if (py_call_level==0) {
else if (py_call_level == 0) {
/* XXX - Calling classes currently wont store the context :\,
* cant set NULL because of this. but this is very flakey still. */
#if 0
@@ -152,21 +152,21 @@ void BPY_text_free_code(Text *text)
{
if (text->compiled) {
Py_DECREF((PyObject *)text->compiled);
text->compiled= NULL;
text->compiled = NULL;
}
}
void BPY_modules_update(bContext *C)
{
#if 0 // slow, this runs all the time poll, draw etc 100's of time a sec.
PyObject *mod= PyImport_ImportModuleLevel("bpy", NULL, NULL, NULL, 0);
PyObject *mod = PyImport_ImportModuleLevel("bpy", NULL, NULL, NULL, 0);
PyModule_AddObject(mod, "data", BPY_rna_module());
PyModule_AddObject(mod, "types", BPY_rna_types()); // atm this does not need updating
#endif
/* refreshes the main struct */
BPY_update_rna_module();
bpy_context_module->ptr.data= (void *)C;
bpy_context_module->ptr.data = (void *)C;
}
void BPY_context_set(bContext *C)
@@ -179,7 +179,7 @@ extern PyObject *AUD_initPython(void);
/* defined in cycles/blender */
extern PyObject *CYCLES_initPython(void);
static struct _inittab bpy_internal_modules[]= {
static struct _inittab bpy_internal_modules[] = {
{(char *)"mathutils", PyInit_mathutils},
// {(char *)"mathutils.geometry", PyInit_mathutils_geometry},
// {(char *)"mathutils.noise", PyInit_mathutils_noise},
@@ -199,7 +199,7 @@ static struct _inittab bpy_internal_modules[]= {
void BPY_python_start(int argc, const char **argv)
{
#ifndef WITH_PYTHON_MODULE
PyThreadState *py_tstate= NULL;
PyThreadState *py_tstate = NULL;
/* not essential but nice to set our name */
static wchar_t program_path_wchar[FILE_MAX]; /* python holds a reference */
@@ -222,7 +222,7 @@ void BPY_python_start(int argc, const char **argv)
/* Python 3.2 now looks for '2.xx/python/include/python3.2d/pyconfig.h' to
* parse from the 'sysconfig' module which is used by 'site',
* so for now disable site. alternatively we could copy the file. */
Py_NoSiteFlag= 1;
Py_NoSiteFlag = 1;
Py_Initialize();
@@ -230,8 +230,8 @@ void BPY_python_start(int argc, const char **argv)
/* sigh, why do python guys not have a char** version anymore? :( */
{
int i;
PyObject *py_argv= PyList_New(argc);
for (i=0; i<argc; i++) {
PyObject *py_argv = PyList_New(argc);
for (i = 0; i < argc; i++) {
/* should fix bug #20021 - utf path name problems, by replacing
* PyUnicode_FromString, with this one */
PyList_SET_ITEM(py_argv, i, PyC_UnicodeFromByte(argv[i]));
@@ -263,7 +263,7 @@ void BPY_python_start(int argc, const char **argv)
BPY_atexit_register(); /* this can init any time */
#ifndef WITH_PYTHON_MODULE
py_tstate= PyGILState_GetThisThreadState();
py_tstate = PyGILState_GetThisThreadState();
PyEval_ReleaseThread(py_tstate);
#endif
}
@@ -287,16 +287,16 @@ void BPY_python_end(void)
#ifdef TIME_PY_RUN
// measure time since py started
bpy_timer= PIL_check_seconds_timer() - bpy_timer;
bpy_timer = PIL_check_seconds_timer() - bpy_timer;
printf("*bpy stats* - ");
printf("tot exec: %d, ", bpy_timer_count);
printf("tot run: %.4fsec, ", bpy_timer_run_tot);
if (bpy_timer_count>0)
if (bpy_timer_count > 0)
printf("average run: %.6fsec, ", (bpy_timer_run_tot/bpy_timer_count));
if (bpy_timer>0.0)
printf("tot usage %.4f%%", (bpy_timer_run_tot/bpy_timer)*100.0);
if (bpy_timer > 0.0)
printf("tot usage %.4f%%", (bpy_timer_run_tot/bpy_timer) * 100.0);
printf("\n");
@@ -310,7 +310,7 @@ static void python_script_error_jump_text(struct Text *text)
{
int lineno;
int offset;
python_script_error_jump(text->id.name+2, &lineno, &offset);
python_script_error_jump(text->id.name + 2, &lineno, &offset);
if (lineno != -1) {
/* select the line with the error */
txt_move_to(text, lineno - 1, INT_MAX, FALSE);
@@ -334,13 +334,13 @@ typedef struct {
static int python_script_exec(bContext *C, const char *fn, struct Text *text,
struct ReportList *reports, const short do_jump)
{
PyObject *main_mod= NULL;
PyObject *py_dict= NULL, *py_result= NULL;
PyObject *main_mod = NULL;
PyObject *py_dict = NULL, *py_result = NULL;
PyGILState_STATE gilstate;
BLI_assert(fn || text);
if (fn==NULL && text==NULL) {
if (fn == NULL && text == NULL) {
return 0;
}
@@ -353,9 +353,9 @@ static int python_script_exec(bContext *C, const char *fn, struct Text *text,
bpy_text_filename_get(fn_dummy, sizeof(fn_dummy), text);
if (text->compiled == NULL) { /* if it wasn't already compiled, do it now */
char *buf= txt_to_buf(text);
char *buf = txt_to_buf(text);
text->compiled= Py_CompileString(buf, fn_dummy, Py_file_input);
text->compiled = Py_CompileString(buf, fn_dummy, Py_file_input);
MEM_freeN(buf);
@@ -368,16 +368,16 @@ static int python_script_exec(bContext *C, const char *fn, struct Text *text,
}
if (text->compiled) {
py_dict= PyC_DefaultNameSpace(fn_dummy);
py_result= PyEval_EvalCode(text->compiled, py_dict, py_dict);
py_dict = PyC_DefaultNameSpace(fn_dummy);
py_result = PyEval_EvalCode(text->compiled, py_dict, py_dict);
}
}
else {
FILE *fp= fopen(fn, "r");
FILE *fp = fopen(fn, "r");
if (fp) {
py_dict= PyC_DefaultNameSpace(fn);
py_dict = PyC_DefaultNameSpace(fn);
#ifdef _WIN32
/* Previously we used PyRun_File to run directly the code on a FILE
@@ -390,14 +390,14 @@ static int python_script_exec(bContext *C, const char *fn, struct Text *text,
fclose(fp);
pystring= MEM_mallocN(strlen(fn) + 32, "pystring");
pystring[0]= '\0';
pystring = MEM_mallocN(strlen(fn) + 32, "pystring");
pystring[0] = '\0';
sprintf(pystring, "exec(open(r'%s').read())", fn);
py_result= PyRun_String(pystring, Py_file_input, py_dict, py_dict);
py_result = PyRun_String(pystring, Py_file_input, py_dict, py_dict);
MEM_freeN(pystring);
}
#else
py_result= PyRun_File(fp, fn, Py_file_input, py_dict, py_dict);
py_result = PyRun_File(fp, fn, Py_file_input, py_dict, py_dict);
fclose(fp);
#endif
}
@@ -405,7 +405,7 @@ static int python_script_exec(bContext *C, const char *fn, struct Text *text,
PyErr_Format(PyExc_IOError,
"Python file \"%s\" could not be opened: %s",
fn, strerror(errno));
py_result= NULL;
py_result = NULL;
}
}
@@ -423,11 +423,11 @@ static int python_script_exec(bContext *C, const char *fn, struct Text *text,
if (py_dict) {
#ifdef PYMODULE_CLEAR_WORKAROUND
PyModuleObject *mmod= (PyModuleObject *)PyDict_GetItemString(PyThreadState_GET()->interp->modules, "__main__");
PyObject *dict_back= mmod->md_dict;
PyModuleObject *mmod = (PyModuleObject *)PyDict_GetItemString(PyThreadState_GET()->interp->modules, "__main__");
PyObject *dict_back = mmod->md_dict;
/* freeing the module will clear the namespace,
* gives problems running classes defined in this namespace being used later. */
mmod->md_dict= NULL;
mmod->md_dict = NULL;
Py_DECREF(dict_back);
#endif
@@ -455,7 +455,7 @@ int BPY_text_exec(bContext *C, struct Text *text, struct ReportList *reports, co
void BPY_DECREF(void *pyob_ptr)
{
PyGILState_STATE gilstate= PyGILState_Ensure();
PyGILState_STATE gilstate = PyGILState_Ensure();
Py_DECREF((PyObject *)pyob_ptr);
PyGILState_Release(gilstate);
}
@@ -465,13 +465,13 @@ int BPY_button_exec(bContext *C, const char *expr, double *value, const short ve
{
PyGILState_STATE gilstate;
PyObject *py_dict, *mod, *retval;
int error_ret= 0;
PyObject *main_mod= NULL;
int error_ret = 0;
PyObject *main_mod = NULL;
if (!value || !expr) return -1;
if (expr[0]=='\0') {
*value= 0.0;
if (expr[0] == '\0') {
*value = 0.0;
return error_ret;
}
@@ -479,9 +479,9 @@ int BPY_button_exec(bContext *C, const char *expr, double *value, const short ve
PyC_MainModule_Backup(&main_mod);
py_dict= PyC_DefaultNameSpace("<blender button>");
py_dict = PyC_DefaultNameSpace("<blender button>");
mod= PyImport_ImportModule("math");
mod = PyImport_ImportModule("math");
if (mod) {
PyDict_Merge(py_dict, PyModule_GetDict(mod), 0); /* 0 - dont overwrite existing values */
Py_DECREF(mod);
@@ -491,10 +491,10 @@ int BPY_button_exec(bContext *C, const char *expr, double *value, const short ve
PyErr_Clear();
}
retval= PyRun_String(expr, Py_eval_input, py_dict, py_dict);
retval = PyRun_String(expr, Py_eval_input, py_dict, py_dict);
if (retval == NULL) {
error_ret= -1;
error_ret = -1;
}
else {
double val;
@@ -503,25 +503,25 @@ int BPY_button_exec(bContext *C, const char *expr, double *value, const short ve
/* Users my have typed in 10km, 2m
* add up all values */
int i;
val= 0.0;
val = 0.0;
for (i=0; i<PyTuple_GET_SIZE(retval); i++) {
val+= PyFloat_AsDouble(PyTuple_GET_ITEM(retval, i));
for (i = 0; i < PyTuple_GET_SIZE(retval); i++) {
val += PyFloat_AsDouble(PyTuple_GET_ITEM(retval, i));
}
}
else {
val= PyFloat_AsDouble(retval);
val = PyFloat_AsDouble(retval);
}
Py_DECREF(retval);
if (val==-1 && PyErr_Occurred()) {
error_ret= -1;
if (val == -1 && PyErr_Occurred()) {
error_ret = -1;
}
else if (!finite(val)) {
*value= 0.0;
*value = 0.0;
}
else {
*value= val;
*value = val;
}
}
@@ -544,14 +544,14 @@ int BPY_button_exec(bContext *C, const char *expr, double *value, const short ve
int BPY_string_exec(bContext *C, const char *expr)
{
PyGILState_STATE gilstate;
PyObject *main_mod= NULL;
PyObject *main_mod = NULL;
PyObject *py_dict, *retval;
int error_ret= 0;
int error_ret = 0;
Main *bmain_back; /* XXX, quick fix for release (Copy Settings crash), needs further investigation */
if (!expr) return -1;
if (expr[0]=='\0') {
if (expr[0] == '\0') {
return error_ret;
}
@@ -559,17 +559,17 @@ int BPY_string_exec(bContext *C, const char *expr)
PyC_MainModule_Backup(&main_mod);
py_dict= PyC_DefaultNameSpace("<blender string>");
py_dict = PyC_DefaultNameSpace("<blender string>");
bmain_back= bpy_import_main_get();
bmain_back = bpy_import_main_get();
bpy_import_main_set(CTX_data_main(C));
retval= PyRun_String(expr, Py_eval_input, py_dict, py_dict);
retval = PyRun_String(expr, Py_eval_input, py_dict, py_dict);
bpy_import_main_set(bmain_back);
if (retval == NULL) {
error_ret= -1;
error_ret = -1;
BPy_errors_to_report(CTX_wm_reports(C));
}
@@ -588,11 +588,11 @@ int BPY_string_exec(bContext *C, const char *expr)
void BPY_modules_load_user(bContext *C)
{
PyGILState_STATE gilstate;
Main *bmain= CTX_data_main(C);
Main *bmain = CTX_data_main(C);
Text *text;
/* can happen on file load */
if (bmain==NULL)
if (bmain == NULL)
return;
/* update pointers since this can run from a nested script
@@ -603,15 +603,15 @@ void BPY_modules_load_user(bContext *C)
bpy_context_set(C, &gilstate);
for (text=CTX_data_main(C)->text.first; text; text= text->id.next) {
if (text->flags & TXT_ISSCRIPT && BLI_testextensie(text->id.name+2, ".py")) {
for (text = CTX_data_main(C)->text.first; text; text = text->id.next) {
if (text->flags & TXT_ISSCRIPT && BLI_testextensie(text->id.name + 2, ".py")) {
if (!(G.f & G_SCRIPT_AUTOEXEC)) {
printf("scripts disabled for \"%s\", skipping '%s'\n", bmain->name, text->id.name+2);
printf("scripts disabled for \"%s\", skipping '%s'\n", bmain->name, text->id.name + 2);
}
else {
PyObject *module= bpy_text_import(text);
PyObject *module = bpy_text_import(text);
if (module==NULL) {
if (module == NULL) {
PyErr_Print();
PyErr_Clear();
}
@@ -626,43 +626,43 @@ void BPY_modules_load_user(bContext *C)
int BPY_context_member_get(bContext *C, const char *member, bContextDataResult *result)
{
PyObject *pyctx= (PyObject *)CTX_py_dict_get(C);
PyObject *item= PyDict_GetItemString(pyctx, member);
PointerRNA *ptr= NULL;
int done= 0;
PyObject *pyctx = (PyObject *)CTX_py_dict_get(C);
PyObject *item = PyDict_GetItemString(pyctx, member);
PointerRNA *ptr = NULL;
int done = 0;
if (item==NULL) {
if (item == NULL) {
/* pass */
}
else if (item==Py_None) {
else if (item == Py_None) {
/* pass */
}
else if (BPy_StructRNA_Check(item)) {
ptr= &(((BPy_StructRNA *)item)->ptr);
ptr = &(((BPy_StructRNA *)item)->ptr);
//result->ptr= ((BPy_StructRNA *)item)->ptr;
//result->ptr = ((BPy_StructRNA *)item)->ptr;
CTX_data_pointer_set(result, ptr->id.data, ptr->type, ptr->data);
done= 1;
done = 1;
}
else if (PySequence_Check(item)) {
PyObject *seq_fast= PySequence_Fast(item, "bpy_context_get sequence conversion");
if (seq_fast==NULL) {
PyObject *seq_fast = PySequence_Fast(item, "bpy_context_get sequence conversion");
if (seq_fast == NULL) {
PyErr_Print();
PyErr_Clear();
}
else {
int len= PySequence_Fast_GET_SIZE(seq_fast);
int len = PySequence_Fast_GET_SIZE(seq_fast);
int i;
for (i= 0; i < len; i++) {
PyObject *list_item= PySequence_Fast_GET_ITEM(seq_fast, i);
for (i = 0; i < len; i++) {
PyObject *list_item = PySequence_Fast_GET_ITEM(seq_fast, i);
if (BPy_StructRNA_Check(list_item)) {
/*
CollectionPointerLink *link= MEM_callocN(sizeof(CollectionPointerLink), "bpy_context_get");
link->ptr= ((BPy_StructRNA *)item)->ptr;
CollectionPointerLink *link = MEM_callocN(sizeof(CollectionPointerLink), "bpy_context_get");
link->ptr = ((BPy_StructRNA *)item)->ptr;
BLI_addtail(&result->list, link);
*/
ptr= &(((BPy_StructRNA *)list_item)->ptr);
ptr = &(((BPy_StructRNA *)list_item)->ptr);
CTX_data_list_add(result, ptr->id.data, ptr->type, ptr->data);
}
else {
@@ -672,11 +672,11 @@ int BPY_context_member_get(bContext *C, const char *member, bContextDataResult *
}
Py_DECREF(seq_fast);
done= 1;
done = 1;
}
}
if (done==0) {
if (done == 0) {
if (item) printf("PyContext '%s' not a valid type\n", member);
else printf("PyContext '%s' not found\n", member);
}
@@ -697,7 +697,7 @@ int BPY_context_member_get(bContext *C, const char *member, bContextDataResult *
static void bpy_module_free(void *mod);
extern int main_python_enter(int argc, const char **argv);
extern void main_python_exit(void);
static struct PyModuleDef bpy_proxy_def= {
static struct PyModuleDef bpy_proxy_def = {
PyModuleDef_HEAD_INIT,
"bpy", /* m_name */
NULL, /* m_doc */
@@ -718,20 +718,20 @@ typedef struct {
/* call once __file__ is set */
void bpy_module_delay_init(PyObject *bpy_proxy)
{
const int argc= 1;
const int argc = 1;
const char *argv[2];
/* updating the module dict below will loose the reference to __file__ */
PyObject *filename_obj= PyModule_GetFilenameObject(bpy_proxy);
PyObject *filename_obj = PyModule_GetFilenameObject(bpy_proxy);
const char *filename_rel= _PyUnicode_AsString(filename_obj); /* can be relative */
const char *filename_rel = _PyUnicode_AsString(filename_obj); /* can be relative */
char filename_abs[1024];
BLI_strncpy(filename_abs, filename_rel, sizeof(filename_abs));
BLI_path_cwd(filename_abs);
argv[0]= filename_abs;
argv[1]= NULL;
argv[0] = filename_abs;
argv[1] = NULL;
// printf("module found %s\n", argv[0]);
@@ -743,7 +743,7 @@ void bpy_module_delay_init(PyObject *bpy_proxy)
static void dealloc_obj_dealloc(PyObject *self);
static PyTypeObject dealloc_obj_Type= {{{0}}};
static PyTypeObject dealloc_obj_Type = {{{0}}};
/* use our own dealloc so we can free a property if we use one */
static void dealloc_obj_dealloc(PyObject *self)
@@ -757,7 +757,7 @@ static void dealloc_obj_dealloc(PyObject *self)
PyMODINIT_FUNC
PyInit_bpy(void)
{
PyObject *bpy_proxy= PyModule_Create(&bpy_proxy_def);
PyObject *bpy_proxy = PyModule_Create(&bpy_proxy_def);
/* Problem:
* 1) this init function is expected to have a private member defined - 'md_def'
@@ -777,16 +777,16 @@ PyInit_bpy(void)
dealloc_obj *dob;
/* assign dummy type */
dealloc_obj_Type.tp_name= "dealloc_obj";
dealloc_obj_Type.tp_basicsize= sizeof(dealloc_obj);
dealloc_obj_Type.tp_dealloc= dealloc_obj_dealloc;
dealloc_obj_Type.tp_flags= Py_TPFLAGS_DEFAULT;
dealloc_obj_Type.tp_name = "dealloc_obj";
dealloc_obj_Type.tp_basicsize = sizeof(dealloc_obj);
dealloc_obj_Type.tp_dealloc = dealloc_obj_dealloc;
dealloc_obj_Type.tp_flags = Py_TPFLAGS_DEFAULT;
if (PyType_Ready(&dealloc_obj_Type) < 0)
return NULL;
dob= (dealloc_obj *) dealloc_obj_Type.tp_alloc(&dealloc_obj_Type, 0);
dob->mod= bpy_proxy; /* borrow */
dob = (dealloc_obj *) dealloc_obj_Type.tp_alloc(&dealloc_obj_Type, 0);
dob->mod = bpy_proxy; /* borrow */
PyModule_AddObject(bpy_proxy, "__file__", (PyObject *)dob); /* borrow */
return bpy_proxy;