diff options
author | Campbell Barton <ideasman42@gmail.com> | 2011-12-27 01:39:16 +0400 |
---|---|---|
committer | Campbell Barton <ideasman42@gmail.com> | 2011-12-27 01:39:16 +0400 |
commit | f63e33303f3523420e6e20cd024dfe2cc649edca (patch) | |
tree | b77b6b2cc393478c2d72079fd40879c4ac3a6e82 | |
parent | 2cd5436a81da5c15ac70bd2b80c2f062cce5d02e (diff) | |
parent | 8cc96408df7f3848ce7b7d3598c0caeb327e4f8c (diff) |
svn merge ^/trunk/blender -r42871:42882
38 files changed, 2334 insertions, 1997 deletions
diff --git a/build_files/scons/tools/btools.py b/build_files/scons/tools/btools.py index 05e28ab1813..adeca5668eb 100644 --- a/build_files/scons/tools/btools.py +++ b/build_files/scons/tools/btools.py @@ -159,7 +159,8 @@ def validate_arguments(args, bc): 'WITH_BF_3DMOUSE', 'WITH_BF_STATIC3DMOUSE', 'BF_3DMOUSE', 'BF_3DMOUSE_INC', 'BF_3DMOUSE_LIB', 'BF_3DMOUSE_LIBPATH', 'BF_3DMOUSE_LIB_STATIC', 'WITH_BF_CYCLES', 'WITH_BF_CYCLES_CUDA_BINARIES' 'BF_CYCLES_CUDA_NVCC', 'BF_CYCLES_CUDA_NVCC', 'WITH_BF_CYCLES_CUDA_THREADED_COMPILE', 'WITH_BF_OIIO', 'WITH_BF_STATICOIIO', 'BF_OIIO', 'BF_OIIO_INC', 'BF_OIIO_LIB', 'BF_OIIO_LIB_STATIC', 'BF_OIIO_LIBPATH', - 'WITH_BF_BOOST', 'WITH_BF_STATICBOOST', 'BF_BOOST', 'BF_BOOST_INC', 'BF_BOOST_LIB', 'BF_BOOST_LIB_STATIC', 'BF_BOOST_LIBPATH' + 'WITH_BF_BOOST', 'WITH_BF_STATICBOOST', 'BF_BOOST', 'BF_BOOST_INC', 'BF_BOOST_LIB', 'BF_BOOST_LIB_STATIC', 'BF_BOOST_LIBPATH', + 'WITH_BF_LIBMV' ] # Have options here that scons expects to be lists diff --git a/intern/ghost/intern/GHOST_WindowX11.cpp b/intern/ghost/intern/GHOST_WindowX11.cpp index d882ae41c9c..5611644f8f2 100644 --- a/intern/ghost/intern/GHOST_WindowX11.cpp +++ b/intern/ghost/intern/GHOST_WindowX11.cpp @@ -1344,7 +1344,9 @@ installDrawingContext( if (!s_firstContext) { s_firstContext = m_context; } - glXMakeCurrent(m_display, m_window,m_context); + glXMakeCurrent(m_display, m_window,m_context); + glClearColor(0.447, 0.447, 0.447, 0); + glClear(GL_COLOR_BUFFER_BIT); success = GHOST_kSuccess; } else { success = GHOST_kFailure; diff --git a/source/blender/blenfont/intern/blf_lang.c b/source/blender/blenfont/intern/blf_lang.c index 6fd868cd074..d62cee6a987 100644 --- a/source/blender/blenfont/intern/blf_lang.c +++ b/source/blender/blenfont/intern/blf_lang.c @@ -32,6 +32,8 @@ #include <stdlib.h> #include <string.h> +#include "BKE_global.h" + #include "BLF_api.h" #include "BLF_translation.h" /* own include */ @@ -81,8 +83,13 @@ static const char *locales[] = { "catalan", "ca_AD", "czech", "cs_CZ", "ptb", "pt_BR", +#if defined (_WIN32) && !defined(FREE_WINDOWS) "Chinese (Simplified)_China.1252", "zh_CN", "Chinese (Traditional)_China.1252", "zh_TW", +#else + "chs", "zh_CN", + "cht", "zh_TW", +#endif "russian", "ru_RU", "croatian", "hr_HR", "serbian", "sr_RS", @@ -115,15 +122,50 @@ void BLF_lang_init(void) } +/* get LANG/LANGUAGE environment variable */ +static void get_language_variable(const char *varname, char *var, int maxlen) +{ + char *env= getenv(varname); + + if(env) { + char *s; + + /* store defaul locale */ + BLI_strncpy(var, env, maxlen); + + /* use first language as default */ + s= strchr(var, ':'); + if(s) + s[0]= 0; + } +} + +/* get language to be used based on locale(which might be empty when using default language) and + * LANG environment variable + */ +static void get_language(const char *locale, const char *lang, char *language, int maxlen) +{ + if(locale[0]) { + BLI_strncpy(language, locale, maxlen); + } + else { + char *s; + + BLI_strncpy(language, lang, maxlen); + + s= strchr(language, '.'); + if(s) + s[0]= 0; + } +} + /* XXX WARNING!!! IN osx somehow the previous function call jumps in this one??? (ton, ppc) */ void BLF_lang_set(const char *str) { char *locreturn; const char *short_locale; int ok= 1; -#if defined (_WIN32) && !defined(FREE_WINDOWS) - const char *long_locale = locales[ 2 * U.language]; -#endif + const char *long_locale = locales[2 * U.language]; if((U.transopts&USER_DOTRANSLATE)==0) return; @@ -149,56 +191,72 @@ void BLF_lang_set(const char *str) locreturn= setlocale(LC_ALL, long_locale); if (locreturn == NULL) { - printf("Could not change locale to %s\n", long_locale); + if(G.debug & G_DEBUG) + printf("Could not change locale to %s\n", long_locale); + ok= 0; } #else { - const char *locale; - static char default_locale[64]="\0"; + static char default_lang[64]="\0"; + static char default_language[64]="\0"; - if(default_locale[0]==0) { - char *env_language= getenv("LANGUAGE"); + if(default_lang[0]==0) + get_language_variable("LANG", default_lang, sizeof(default_lang)); - if(env_language) { - char *s; + if(default_language[0]==0) + get_language_variable("LANGUAGE", default_language, sizeof(default_language)); - /* store defaul locale */ - BLI_strncpy(default_locale, env_language, sizeof(default_locale)); + if(short_locale[0]) { + if(G.f & G_DEBUG) + printf("Setting LANG= and LANGUAGE to %s\n", short_locale); - /* use first language as default */ - s= strchr(default_locale, ':'); - if(s) s[0]= 0; - } + BLI_setenv("LANG", short_locale); + BLI_setenv("LANGUAGE", short_locale); } + else { + if(G.f & G_DEBUG) + printf("Setting LANG=%s and LANGUAGE=%s\n", default_lang, default_language); - if(short_locale[0]) - locale= short_locale; - else - locale= default_locale; - - BLI_setenv("LANG", locale); - BLI_setenv("LANGUAGE", locale); + BLI_setenv("LANG", default_lang); + BLI_setenv("LANGUAGE", default_language); + } - locreturn= setlocale(LC_ALL, locale); + locreturn= setlocale(LC_ALL, short_locale); - if (locreturn == NULL) { - char *short_locale_utf8= BLI_sprintfN("%s.UTF-8", short_locale); + if(locreturn == NULL) { + char *short_locale_utf8= NULL; - locreturn= setlocale(LC_ALL, short_locale_utf8); + if(short_locale[0]) { + short_locale_utf8= BLI_sprintfN("%s.UTF-8", short_locale); + locreturn= setlocale(LC_ALL, short_locale_utf8); + } if (locreturn == NULL) { - printf("Could not change locale to %s nor %s\n", short_locale, short_locale_utf8); + char language[65]; + + get_language(long_locale, default_lang, language, sizeof(language)); + + if(G.f & G_DEBUG) { + if(short_locale[0]) + printf("Could not change locale to %s nor %s\n", short_locale, short_locale_utf8); + else + printf("Could not reset locale\n"); + + printf("Fallback to LANG=%s and LANGUAGE=%s\n", default_lang, language); + } /* fallback to default settings */ + BLI_setenv("LANG", default_lang); + BLI_setenv("LANGUAGE", language); + locreturn= setlocale(LC_ALL, ""); - BLI_setenv("LANG", default_locale); - BLI_setenv("LANGUAGE", default_locale); ok= 0; } - MEM_freeN(short_locale_utf8); + if(short_locale_utf8) + MEM_freeN(short_locale_utf8); } } #endif diff --git a/source/blender/blenlib/intern/storage.c b/source/blender/blenlib/intern/storage.c index 001b191155d..c5b6f46b3bc 100644 --- a/source/blender/blenlib/intern/storage.c +++ b/source/blender/blenlib/intern/storage.c @@ -54,7 +54,7 @@ #include <sys/mount.h> #endif -#if defined(linux) || defined(__CYGWIN32__) || defined(__hpux) +#if defined(linux) || defined(__CYGWIN32__) || defined(__hpux) || defined(__GNU__) || defined(__GLIBC__) #include <sys/vfs.h> #endif @@ -180,7 +180,7 @@ double BLI_dir_free_space(const char *dir) if (slash) slash[1] = 0; } else strcpy(name,"/"); -#if defined (__FreeBSD__) || defined (linux) || defined (__OpenBSD__) || defined (__APPLE__) +#if defined (__FreeBSD__) || defined (linux) || defined (__OpenBSD__) || defined (__APPLE__) || defined(__GNU__) || defined(__GLIBC__) if (statfs(name, &disk)) return(-1); #endif diff --git a/source/blender/editors/include/ED_view3d.h b/source/blender/editors/include/ED_view3d.h index 85daa97343d..a8158185f90 100644 --- a/source/blender/editors/include/ED_view3d.h +++ b/source/blender/editors/include/ED_view3d.h @@ -204,7 +204,7 @@ void ED_view3d_depth_tag_update(struct RegionView3D *rv3d); /* Projection */ #define IS_CLIPPED 12000 -void ED_view3d_calc_clipping(struct BoundBox *bb, float planes[4][4], struct bglMats *mats, struct rcti *rect); +void ED_view3d_calc_clipping(struct BoundBox *bb, float planes[4][4], struct bglMats *mats, const struct rcti *rect); void project_short(struct ARegion *ar, const float vec[3], short adr[2]); void project_short_noclip(struct ARegion *ar, const float vec[3], short adr[2]); @@ -218,7 +218,7 @@ void project_float_noclip(struct ARegion *ar, const float vec[3], float adr[2]); int ED_view3d_clip_range_get(struct View3D *v3d, struct RegionView3D *rv3d, float *clipsta, float *clipend); int ED_view3d_viewplane_get(struct View3D *v3d, struct RegionView3D *rv3d, int winxi, int winyi, struct rctf *viewplane, float *clipsta, float *clipend); void ED_view3d_ob_project_mat_get(struct RegionView3D *v3d, struct Object *ob, float pmat[4][4]); -void ED_view3d_project_float(struct ARegion *a, const float vec[3], float adr[2], float mat[4][4]); +void ED_view3d_project_float(const struct ARegion *a, const float vec[3], float adr[2], float mat[4][4]); void ED_view3d_calc_camera_border(struct Scene *scene, struct ARegion *ar, struct View3D *v3d, struct RegionView3D *rv3d, struct rctf *viewborder_r, short no_shift); void ED_view3d_project_float_v3(struct ARegion *a, float *vec, float *adr, float mat[4][4]); void ED_view3d_calc_camera_border_size(struct Scene *scene, struct ARegion *ar, struct View3D *v3d, struct RegionView3D *rv3d, float size_r[2]); @@ -261,7 +261,7 @@ void view3d_set_viewcontext(struct bContext *C, struct ViewContext *vc); void view3d_operator_needs_opengl(const struct bContext *C); void view3d_region_operator_needs_opengl(struct wmWindow *win, struct ARegion *ar); int view3d_get_view_aligned_coordinate(struct ViewContext *vc, float fp[3], const int mval[2], const short do_fallback); -void view3d_get_transformation(struct ARegion *ar, struct RegionView3D *rv3d, struct Object *ob, struct bglMats *mats); +void view3d_get_transformation(const struct ARegion *ar, struct RegionView3D *rv3d, struct Object *ob, struct bglMats *mats); /* XXX should move to BLI_math */ int edge_inside_circle(short centx, short centy, short rad, short x1, short y1, short x2, short y2); diff --git a/source/blender/editors/sculpt_paint/paint_intern.h b/source/blender/editors/sculpt_paint/paint_intern.h index 3b001a8fcdc..a5e68f9a244 100644 --- a/source/blender/editors/sculpt_paint/paint_intern.h +++ b/source/blender/editors/sculpt_paint/paint_intern.h @@ -41,6 +41,7 @@ struct Mesh; struct Object; struct PaintStroke; struct PointerRNA; +struct rcti; struct Scene; struct VPaint; struct ViewContext; @@ -104,6 +105,26 @@ void PAINT_OT_image_from_view(struct wmOperatorType *ot); /* paint_utils.c */ + +/* Convert the object-space axis-aligned bounding box (expressed as + its minimum and maximum corners) into a screen-space rectangle, + returns zero if the result is empty */ +int paint_convert_bb_to_rect(struct rcti *rect, + const float bb_min[3], + const float bb_max[3], + const struct ARegion *ar, + struct RegionView3D *rv3d, + struct Object *ob); + +/* Get four planes in object-space that describe the projection of + screen_rect from screen into object-space (essentially converting a + 2D screens-space bounding box into four 3D planes) */ +void paint_calc_redraw_planes(float planes[4][4], + const struct ARegion *ar, + struct RegionView3D *rv3d, + struct Object *ob, + const struct rcti *screen_rect); + void projectf(struct bglMats *mats, const float v[3], float p[2]); float paint_calc_object_space_radius(struct ViewContext *vc, float center[3], float pixel_radius); float paint_get_tex_pixel(struct Brush* br, float u, float v); diff --git a/source/blender/editors/sculpt_paint/paint_utils.c b/source/blender/editors/sculpt_paint/paint_utils.c index f79ccbb9a55..771c6b40af6 100644 --- a/source/blender/editors/sculpt_paint/paint_utils.c +++ b/source/blender/editors/sculpt_paint/paint_utils.c @@ -67,6 +67,77 @@ #include "paint_intern.h" +/* Convert the object-space axis-aligned bounding box (expressed as + its minimum and maximum corners) into a screen-space rectangle, + returns zero if the result is empty */ +int paint_convert_bb_to_rect(rcti *rect, + const float bb_min[3], + const float bb_max[3], + const ARegion *ar, + RegionView3D *rv3d, + Object *ob) +{ + float projection_mat[4][4]; + int i, j, k; + + rect->xmin = rect->ymin = INT_MAX; + rect->xmax = rect->ymax = INT_MIN; + + /* return zero if the bounding box has non-positive volume */ + if(bb_min[0] > bb_max[0] || bb_min[1] > bb_max[1] || bb_min[2] > bb_max[2]) + return 0; + + ED_view3d_ob_project_mat_get(rv3d, ob, projection_mat); + + for(i = 0; i < 2; ++i) { + for(j = 0; j < 2; ++j) { + for(k = 0; k < 2; ++k) { + float vec[3], proj[2]; + vec[0] = i ? bb_min[0] : bb_max[0]; + vec[1] = j ? bb_min[1] : bb_max[1]; + vec[2] = k ? bb_min[2] : bb_max[2]; + /* convert corner to screen space */ + ED_view3d_project_float(ar, vec, proj, + projection_mat); + /* expand 2D rectangle */ + rect->xmin = MIN2(rect->xmin, proj[0]); + rect->xmax = MAX2(rect->xmax, proj[0]); + rect->ymin = MIN2(rect->ymin, proj[1]); + rect->ymax = MAX2(rect->ymax, proj[1]); + } + } + } + + /* return false if the rectangle has non-positive area */ + return rect->xmin < rect->xmax && rect->ymin < rect->ymax; +} + +/* Get four planes in object-space that describe the projection of + screen_rect from screen into object-space (essentially converting a + 2D screens-space bounding box into four 3D planes) */ +void paint_calc_redraw_planes(float planes[4][4], + const ARegion *ar, + RegionView3D *rv3d, + Object *ob, + const rcti *screen_rect) +{ + BoundBox bb; + bglMats mats; + rcti rect; + + memset(&bb, 0, sizeof(BoundBox)); + view3d_get_transformation(ar, rv3d, ob, &mats); + + /* use some extra space just in case */ + rect.xmin -= 2; + rect.xmax += 2; + rect.ymin -= 2; + rect.ymax += 2; + + ED_view3d_calc_clipping(&bb, planes, &mats, screen_rect); + mul_m4_fl(planes, -1.0f); +} + /* convert a point in model coordinates to 2D screen coordinates */ /* TODO: can be deleted once all calls are replaced with view3d_project_float() */ diff --git a/source/blender/editors/sculpt_paint/sculpt.c b/source/blender/editors/sculpt_paint/sculpt.c index cdfb1f971ac..bd194dc1070 100644 --- a/source/blender/editors/sculpt_paint/sculpt.c +++ b/source/blender/editors/sculpt_paint/sculpt.c @@ -248,90 +248,51 @@ typedef struct StrokeCache { /* Get a screen-space rectangle of the modified area */ static int sculpt_get_redraw_rect(ARegion *ar, RegionView3D *rv3d, - Object *ob, rcti *rect) + Object *ob, rcti *rect) { + SculptSession *ss; PBVH *pbvh= ob->sculpt->pbvh; - float bb_min[3], bb_max[3], pmat[4][4]; - int i, j, k; - - ED_view3d_ob_project_mat_get(rv3d, ob, pmat); + float bb_min[3], bb_max[3]; if(!pbvh) return 0; BLI_pbvh_redraw_BB(pbvh, bb_min, bb_max); - rect->xmin = rect->ymin = INT_MAX; - rect->xmax = rect->ymax = INT_MIN; - - if(bb_min[0] > bb_max[0] || bb_min[1] > bb_max[1] || bb_min[2] > bb_max[2]) + /* convert 3D bounding box to screen space */ + if(!paint_convert_bb_to_rect(rect, + bb_min, + bb_max, + ar, + rv3d, + ob)) { return 0; - - for(i = 0; i < 2; ++i) { - for(j = 0; j < 2; ++j) { - for(k = 0; k < 2; ++k) { - float vec[3], proj[2]; - vec[0] = i ? bb_min[0] : bb_max[0]; - vec[1] = j ? bb_min[1] : bb_max[1]; - vec[2] = k ? bb_min[2] : bb_max[2]; - ED_view3d_project_float(ar, vec, proj, pmat); - rect->xmin = MIN2(rect->xmin, proj[0]); - rect->xmax = MAX2(rect->xmax, proj[0]); - rect->ymin = MIN2(rect->ymin, proj[1]); - rect->ymax = MAX2(rect->ymax, proj[1]); - } - } } - - if (rect->xmin < rect->xmax && rect->ymin < rect->ymax) { - /* expand redraw rect with redraw rect from previous step to prevent - partial-redraw issues caused by fast strokes. This is needed here (not in sculpt_flush_update) - as it was before because redraw rectangle should be the same in both of - optimized PBVH draw function and 3d view redraw (if not -- some mesh parts could - disapper from screen (sergey) */ - SculptSession *ss = ob->sculpt; - if (ss->cache) { - if (!BLI_rcti_is_empty(&ss->cache->previous_r)) - BLI_union_rcti(rect, &ss->cache->previous_r); - } - - return 1; + /* expand redraw rect with redraw rect from previous step to + prevent partial-redraw issues caused by fast strokes. This is + needed here (not in sculpt_flush_update) as it was before + because redraw rectangle should be the same in both of + optimized PBVH draw function and 3d view redraw (if not -- some + mesh parts could disapper from screen (sergey) */ + ss = ob->sculpt; + if(ss->cache) { + if(!BLI_rcti_is_empty(&ss->cache->previous_r)) + BLI_union_rcti(rect, &ss->cache->previous_r); } - return 0; + return 1; } void sculpt_get_redraw_planes(float planes[4][4], ARegion *ar, RegionView3D *rv3d, Object *ob) { PBVH *pbvh= ob->sculpt->pbvh; - BoundBox bb; - bglMats mats; rcti rect; - memset(&bb, 0, sizeof(BoundBox)); - - view3d_get_transformation(ar, rv3d, ob, &mats); - sculpt_get_redraw_rect(ar, rv3d,ob, &rect); - -#if 1 - /* use some extra space just in case */ - rect.xmin -= 2; - rect.xmax += 2; - rect.ymin -= 2; - rect.ymax += 2; -#else - /* it was doing this before, allows to redraw a smaller - part of the screen but also gives artifaces .. */ - rect.xmin += 2; - rect.xmax -= 2; - rect.ymin += 2; - rect.ymax -= 2; -#endif + sculpt_get_redraw_rect(ar, rv3d, ob, &rect); - ED_view3d_calc_clipping(&bb, planes, &mats, &rect); - mul_m4_fl(planes, -1.0f); + paint_calc_redraw_planes(planes, ar, rv3d, ob, &rect); /* clear redraw flag from nodes */ if(pbvh) diff --git a/source/blender/editors/space_view3d/view3d_select.c b/source/blender/editors/space_view3d/view3d_select.c index 9a63d591953..44264bd0355 100644 --- a/source/blender/editors/space_view3d/view3d_select.c +++ b/source/blender/editors/space_view3d/view3d_select.c @@ -136,7 +136,7 @@ int view3d_get_view_aligned_coordinate(ViewContext *vc, float fp[3], const int m /* * ob == NULL if you want global matrices * */ -void view3d_get_transformation(ARegion *ar, RegionView3D *rv3d, Object *ob, bglMats *mats) +void view3d_get_transformation(const ARegion *ar, RegionView3D *rv3d, Object *ob, bglMats *mats) { float cpy[4][4]; int i, j; diff --git a/source/blender/editors/space_view3d/view3d_view.c b/source/blender/editors/space_view3d/view3d_view.c index 56f4874fe30..c9639376d1d 100644 --- a/source/blender/editors/space_view3d/view3d_view.c +++ b/source/blender/editors/space_view3d/view3d_view.c @@ -512,7 +512,7 @@ void VIEW3D_OT_object_as_camera(wmOperatorType *ot) /* ********************************** */ -void ED_view3d_calc_clipping(BoundBox *bb, float planes[4][4], bglMats *mats, rcti *rect) +void ED_view3d_calc_clipping(BoundBox *bb, float planes[4][4], bglMats *mats, const rcti *rect) { float modelview[4][4]; double xs, ys, p[3]; @@ -758,7 +758,7 @@ void view3d_unproject(bglMats *mats, float out[3], const short x, const short y, } /* use view3d_get_object_project_mat to get projecting mat */ -void ED_view3d_project_float(ARegion *ar, const float vec[3], float adr[2], float mat[4][4]) +void ED_view3d_project_float(const ARegion *ar, const float vec[3], float adr[2], float mat[4][4]) { float vec4[4]; diff --git a/source/blender/editors/transform/transform.c b/source/blender/editors/transform/transform.c index e9f79464e32..2ac7a520322 100644 --- a/source/blender/editors/transform/transform.c +++ b/source/blender/editors/transform/transform.c @@ -589,6 +589,9 @@ int transformEvent(TransInfo *t, wmEvent *event) } applyMouseInput(t, &t->mouse, t->mval, t->values); + + // Snapping mouse move events + t->redraw |= handleSnapping(t, event); } /* handle modal keymap first */ @@ -1031,7 +1034,7 @@ int transformEvent(TransInfo *t, wmEvent *event) // Numerical input events t->redraw |= handleNumInput(&(t->num), event); - // Snapping events + // Snapping key events t->redraw |= handleSnapping(t, event); } diff --git a/source/blender/editors/transform/transform.h b/source/blender/editors/transform/transform.h index f999cd2c669..44aaca6ff3f 100644 --- a/source/blender/editors/transform/transform.h +++ b/source/blender/editors/transform/transform.h @@ -68,15 +68,6 @@ struct ARegion; struct ReportList; struct SmallHash; -/* - The ctrl value has different meaning: - 0 : No value has been typed - - otherwise, |value| - 1 is where the cursor is located after the period - Positive : number is positive - Negative : number is negative -*/ - typedef struct TransSnapPoint { struct TransSnapPoint *next,*prev; float co[3]; @@ -97,6 +88,7 @@ typedef struct TransSnap { float snapNormal[3]; float snapTangent[3]; ListBase points; + TransSnapPoint *selectedPoint; float dist; // Distance from snapPoint to snapTarget double last; void (*applySnap)(struct TransInfo *, float *); @@ -630,6 +622,7 @@ int validSnappingNormal(TransInfo *t); void getSnapPoint(TransInfo *t, float vec[3]); void addSnapPoint(TransInfo *t); +int updateSelectedSnapPoint(TransInfo *t); void removeSnapPoint(TransInfo *t); /********************** Mouse Input ******************************/ diff --git a/source/blender/editors/transform/transform_snap.c b/source/blender/editors/transform/transform_snap.c index 9ce4779616e..4514b36f3a5 100644 --- a/source/blender/editors/transform/transform_snap.c +++ b/source/blender/editors/transform/transform_snap.c @@ -143,11 +143,16 @@ void drawSnapping(const struct bContext *C, TransInfo *t) if (validSnap(t) && activeSnap(t)) { - unsigned char col[4]; + unsigned char col[4], selectedCol[4], activeCol[4]; UI_GetThemeColor3ubv(TH_TRANSFORM, col); col[3]= 128; - glColor4ubv(col); + UI_GetThemeColor3ubv(TH_SELECT, selectedCol); + selectedCol[3]= 128; + + UI_GetThemeColor3ubv(TH_ACTIVE, activeCol); + activeCol[3]= 192; + if (t->spacetype == SPACE_VIEW3D) { TransSnapPoint *p; View3D *v3d = CTX_wm_view3d(C); @@ -162,16 +167,26 @@ void drawSnapping(const struct bContext *C, TransInfo *t) invert_m4_m4(imat, rv3d->viewmat); for (p = t->tsnap.points.first; p; p = p->next) { - drawcircball(GL_LINE_LOOP, p->co, ED_view3d_pixel_size(rv3d, p->co) * size, imat); + if (p == t->tsnap.selectedPoint) { + glColor4ubv(selectedCol); + } else { + glColor4ubv(col); + } + + drawcircball(GL_LINE_LOOP, p->co, ED_view3d_pixel_size(rv3d, p->co) * size * 0.75f, imat); } if (t->tsnap.status & POINT_INIT) { + glColor4ubv(activeCol); + drawcircball(GL_LINE_LOOP, t->tsnap.snapPoint, ED_view3d_pixel_size(rv3d, t->tsnap.snapPoint) * size, imat); } /* draw normal if needed */ if (usingSnappingNormal(t) && validSnappingNormal(t)) { + glColor4ubv(activeCol); + glBegin(GL_LINES); glVertex3f(t->tsnap.snapPoint[0], t->tsnap.snapPoint[1], t->tsnap.snapPoint[2]); glVertex3f( t->tsnap.snapPoint[0] + t->tsnap.snapNormal[0], @@ -221,7 +236,7 @@ void drawSnapping(const struct bContext *C, TransInfo *t) } } -int handleSnapping(TransInfo *UNUSED(t), wmEvent *UNUSED(event)) +int handleSnapping(TransInfo *t, wmEvent *event) { int status = 0; @@ -234,6 +249,10 @@ int handleSnapping(TransInfo *UNUSED(t), wmEvent *UNUSED(event)) status = 1; } #endif + if (event->type == MOUSEMOVE) + { + status |= updateSelectedSnapPoint(t); + } return status; } @@ -543,6 +562,8 @@ void addSnapPoint(TransInfo *t) if (t->tsnap.status & POINT_INIT) { TransSnapPoint *p = MEM_callocN(sizeof(TransSnapPoint), "SnapPoint"); + t->tsnap.selectedPoint = p; + copy_v3_v3(p->co, t->tsnap.snapPoint); BLI_addtail(&t->tsnap.points, p); @@ -551,13 +572,55 @@ void addSnapPoint(TransInfo *t) } } +int updateSelectedSnapPoint(TransInfo *t) +{ + int status = 0; + if (t->tsnap.status & MULTI_POINTS) { + TransSnapPoint *p, *closest_p = NULL; + int closest_dist = 0; + int screen_loc[2]; + + for( p = t->tsnap.points.first; p; p = p->next ) { + int dx, dy; + int dist; + + project_int(t->ar, p->co, screen_loc); + + dx = t->mval[0] - screen_loc[0]; + dy = t->mval[1] - screen_loc[1]; + + dist = dx * dx + dy * dy; + + if (dist < 100 && (closest_p == NULL || closest_dist > dist)) { + closest_p = p; + closest_dist = dist; + } + } + + if (closest_p) { + status = t->tsnap.selectedPoint == closest_p ? 0 : 1; + t->tsnap.selectedPoint = closest_p; + } + } + + return status; +} + void removeSnapPoint(TransInfo *t) { if (t->tsnap.status & MULTI_POINTS) { - BLI_freelinkN(&t->tsnap.points, t->tsnap.points.last); + updateSelectedSnapPoint(t); + + if (t->tsnap.selectedPoint) { + BLI_freelinkN(&t->tsnap.points, t->tsnap.selectedPoint); + + if (t->tsnap.points.first == NULL) { + t->tsnap.status &= ~MULTI_POINTS; + } + + t->tsnap.selectedPoint = NULL; + } - if (t->tsnap.points.first == NULL) - t->tsnap.status &= ~MULTI_POINTS; } } @@ -682,7 +745,7 @@ static float RotationBetween(TransInfo *t, float p1[3], float p2[3]) static float ResizeBetween(TransInfo *t, float p1[3], float p2[3]) { - float d1[3], d2[3], center[3]; + float d1[3], d2[3], center[3], len_d1; copy_v3_v3(center, t->center); if(t->flag & (T_EDIT|T_POSE)) { @@ -698,7 +761,9 @@ static float ResizeBetween(TransInfo *t, float p1[3], float p2[3]) mul_m3_v3(t->con.pmtx, d2); } - return len_v3(d2) / len_v3(d1); + len_d1 = len_v3(d1); + + return len_d1 != 0.0f ? len_v3(d2) / len_d1 : 1; } /********************** CALC **************************/ diff --git a/source/blender/python/generic/bpy_internal_import.c b/source/blender/python/generic/bpy_internal_import.c index d9183261329..db3519a3056 100644 --- a/source/blender/python/generic/bpy_internal_import.c +++ b/source/blender/python/generic/bpy_internal_import.c @@ -51,7 +51,7 @@ #include "BKE_text.h" /* txt_to_buf */ #include "BKE_main.h" -static Main *bpy_import_main= NULL; +static Main *bpy_import_main = NULL; /* 'builtins' is most likely PyEval_GetBuiltins() */ void bpy_import_init(PyObject *builtins) @@ -59,13 +59,13 @@ void bpy_import_init(PyObject *builtins) PyObject *item; PyObject *mod; - PyDict_SetItemString(builtins, "__import__", item=PyCFunction_New(&bpy_import_meth, NULL)); Py_DECREF(item); + PyDict_SetItemString(builtins, "__import__", item = PyCFunction_New(&bpy_import_meth, NULL)); Py_DECREF(item); /* move reload here * XXX, use import hooks */ - mod= PyImport_ImportModuleLevel((char *)"imp", NULL, NULL, NULL, 0); + mod = PyImport_ImportModuleLevel((char *)"imp", NULL, NULL, NULL, 0); if (mod) { - PyDict_SetItemString(PyModule_GetDict(mod), "reload", item=PyCFunction_New(&bpy_reload_meth, NULL)); Py_DECREF(item); + PyDict_SetItemString(PyModule_GetDict(mod), "reload", item = PyCFunction_New(&bpy_reload_meth, NULL)); Py_DECREF(item); Py_DECREF(mod); } else { @@ -79,7 +79,7 @@ static void free_compiled_text(Text *text) if (text->compiled) { Py_DECREF((PyObject *)text->compiled); } - text->compiled= NULL; + text->compiled = NULL; } struct Main *bpy_import_main_get(void) @@ -89,18 +89,18 @@ struct Main *bpy_import_main_get(void) void bpy_import_main_set(struct Main *maggie) { - bpy_import_main= maggie; + bpy_import_main = maggie; } /* returns a dummy filename for a textblock so we can tell what file a text block comes from */ void bpy_text_filename_get(char *fn, size_t fn_len, Text *text) { - BLI_snprintf(fn, fn_len, "%s%c%s", ID_BLEND_PATH(bpy_import_main, &text->id), SEP, text->id.name+2); + BLI_snprintf(fn, fn_len, "%s%c%s", ID_BLEND_PATH(bpy_import_main, &text->id), SEP, text->id.name + 2); } PyObject *bpy_text_import(Text *text) { - char *buf= NULL; + char *buf = NULL; char modulename[24]; int len; @@ -108,8 +108,8 @@ PyObject *bpy_text_import(Text *text) char fn_dummy[256]; bpy_text_filename_get(fn_dummy, sizeof(fn_dummy), text); - buf= txt_to_buf(text); - text->compiled= Py_CompileString(buf, fn_dummy, Py_file_input); + buf = txt_to_buf(text); + text->compiled = Py_CompileString(buf, fn_dummy, Py_file_input); MEM_freeN(buf); if (PyErr_Occurred()) { @@ -121,21 +121,21 @@ PyObject *bpy_text_import(Text *text) } } - len= strlen(text->id.name+2); - BLI_strncpy(modulename, text->id.name+2, len); - modulename[len - 3]= '\0'; /* remove .py */ + len = strlen(text->id.name + 2); + BLI_strncpy(modulename, text->id.name + 2, len); + modulename[len - 3] = '\0'; /* remove .py */ return PyImport_ExecCodeModule(modulename, text->compiled); } PyObject *bpy_text_import_name(const char *name, int *found) { Text *text; - char txtname[MAX_ID_NAME-2]; - int namelen= strlen(name); -//XXX Main *maggie= bpy_import_main ? bpy_import_main:G.main; - Main *maggie= bpy_import_main; + char txtname[MAX_ID_NAME - 2]; + int namelen = strlen(name); +//XXX Main *maggie = bpy_import_main ? bpy_import_main:G.main; + Main *maggie = bpy_import_main; - *found= 0; + *found = 0; if (!maggie) { printf("ERROR: bpy_import_main_set() was not called before running python. this is a bug.\n"); @@ -143,17 +143,17 @@ PyObject *bpy_text_import_name(const char *name, int *found) } /* we know this cant be importable, the name is too long for blender! */ - if (namelen >= (MAX_ID_NAME-2) - 3) return NULL; + if (namelen >= (MAX_ID_NAME - 2) - 3) return NULL; memcpy(txtname, name, namelen); memcpy(&txtname[namelen], ".py", 4); - text= BLI_findstring(&maggie->text, txtname, offsetof(ID, name) + 2); + text = BLI_findstring(&maggie->text, txtname, offsetof(ID, name) + 2); if (!text) return NULL; else - *found= 1; + *found = 1; return bpy_text_import(text); } @@ -168,32 +168,32 @@ PyObject *bpy_text_reimport(PyObject *module, int *found) Text *text; const char *name; char *filepath; - char *buf= NULL; -//XXX Main *maggie= bpy_import_main ? bpy_import_main:G.main; - Main *maggie= bpy_import_main; + char *buf = NULL; +//XXX Main *maggie = bpy_import_main ? bpy_import_main:G.main; + Main *maggie = bpy_import_main; if (!maggie) { printf("ERROR: bpy_import_main_set() was not called before running python. this is a bug.\n"); return NULL; } - *found= 0; + *found = 0; /* get name, filename from the module itself */ - if ((name= PyModule_GetName(module)) == NULL) + if ((name = PyModule_GetName(module)) == NULL) return NULL; - if ((filepath= (char *)PyModule_GetFilename(module)) == NULL) + if ((filepath = (char *)PyModule_GetFilename(module)) == NULL) return NULL; /* look up the text object */ - text= BLI_findstring(&maggie->text, BLI_path_basename(filepath), offsetof(ID, name) + 2); + text = BLI_findstring(&maggie->text, BLI_path_basename(filepath), offsetof(ID, name) + 2); /* uh-oh.... didn't find it */ if (!text) return NULL; else - *found= 1; + *found = 1; /* if previously compiled, free the object */ /* (can't see how could be NULL, but check just in case) */ @@ -202,8 +202,8 @@ PyObject *bpy_text_reimport(PyObject *module, int *found) } /* compile the buffer */ - buf= txt_to_buf(text); - text->compiled= Py_CompileString(buf, text->id.name+2, Py_file_input); + buf = txt_to_buf(text); + text->compiled = Py_CompileString(buf, text->id.name + 2, Py_file_input); MEM_freeN(buf); /* if compile failed.... return this error */ @@ -224,20 +224,22 @@ static PyObject *blender_import(PyObject *UNUSED(self), PyObject *args, PyObject { PyObject *exception, *err, *tb; char *name; - int found= 0; - PyObject *globals= NULL, *locals= NULL, *fromlist= NULL; - int level= -1; /* relative imports */ + int found = 0; + PyObject *globals = NULL, *locals = NULL, *fromlist = NULL; + int level = -1; /* relative imports */ PyObject *newmodule; //PyObject_Print(args, stderr, 0); - static const char *kwlist[]= {"name", "globals", "locals", "fromlist", "level", NULL}; + static const char *kwlist[] = {"name", "globals", "locals", "fromlist", "level", NULL}; if (!PyArg_ParseTupleAndKeywords(args, kw, "s|OOOi:bpy_import_meth", (char **)kwlist, - &name, &globals, &locals, &fromlist, &level)) + &name, &globals, &locals, &fromlist, &level)) + { return NULL; + } /* import existing builtin modules or modules that have been imported already */ - newmodule= PyImport_ImportModuleLevel(name, globals, locals, fromlist, level); + newmodule = PyImport_ImportModuleLevel(name, globals, locals, fromlist, level); if (newmodule) return newmodule; @@ -245,7 +247,7 @@ static PyObject *blender_import(PyObject *UNUSED(self), PyObject *args, PyObject PyErr_Fetch(&exception, &err, &tb); /* get the python error incase we cant import as blender text either */ /* importing from existing modules failed, see if we have this module as blender text */ - newmodule= bpy_text_import_name(name, &found); + newmodule = bpy_text_import_name(name, &found); if (newmodule) {/* found module as blender text, ignore above exception */ PyErr_Clear(); @@ -254,7 +256,7 @@ static PyObject *blender_import(PyObject *UNUSED(self), PyObject *args, PyObject Py_XDECREF(tb); /* printf("imported from text buffer...\n"); */ } - else if (found==1) { /* blender text module failed to execute but was found, use its error message */ + else if (found == 1) { /* blender text module failed to execute but was found, use its error message */ Py_XDECREF(exception); Py_XDECREF(err); Py_XDECREF(tb); @@ -276,18 +278,18 @@ static PyObject *blender_import(PyObject *UNUSED(self), PyObject *args, PyObject static PyObject *blender_reload(PyObject *UNUSED(self), PyObject *module) { PyObject *exception, *err, *tb; - PyObject *newmodule= NULL; - int found= 0; + PyObject *newmodule = NULL; + int found = 0; /* try reimporting from file */ - newmodule= PyImport_ReloadModule(module); + newmodule = PyImport_ReloadModule(module); if (newmodule) return newmodule; /* no file, try importing from memory */ PyErr_Fetch(&exception, &err, &tb); /*restore for probable later use */ - newmodule= bpy_text_reimport(module, &found); + newmodule = bpy_text_reimport(module, &found); if (newmodule) {/* found module as blender text, ignore above exception */ PyErr_Clear(); Py_XDECREF(exception); @@ -295,7 +297,7 @@ static PyObject *blender_reload(PyObject *UNUSED(self), PyObject *module) Py_XDECREF(tb); /* printf("imported from text buffer...\n"); */ } - else if (found==1) { /* blender text module failed to execute but was found, use its error message */ + else if (found == 1) { /* blender text module failed to execute but was found, use its error message */ Py_XDECREF(exception); Py_XDECREF(err); Py_XDECREF(tb); @@ -310,5 +312,5 @@ static PyObject *blender_reload(PyObject *UNUSED(self), PyObject *module) return newmodule; } -PyMethodDef bpy_import_meth= {"bpy_import_meth", (PyCFunction)blender_import, METH_VARARGS | METH_KEYWORDS, "blenders import"}; -PyMethodDef bpy_reload_meth= {"bpy_reload_meth", (PyCFunction)blender_reload, METH_O, "blenders reload"}; +PyMethodDef bpy_import_meth = {"bpy_import_meth", (PyCFunction)blender_import, METH_VARARGS | METH_KEYWORDS, "blenders import"}; +PyMethodDef bpy_reload_meth = {"bpy_reload_meth", (PyCFunction)blender_reload, METH_O, "blenders reload"}; diff --git a/source/blender/python/intern/bpy.c b/source/blender/python/intern/bpy.c index 4a49b9bc1c3..e0e3dd5519c 100644 --- a/source/blender/python/intern/bpy.c +++ b/source/blender/python/intern/bpy.c @@ -58,7 +58,7 @@ #include "../generic/blf_py_api.h" #include "../mathutils/mathutils.h" -PyObject *bpy_package_py= NULL; +PyObject *bpy_package_py = NULL; PyDoc_STRVAR(bpy_script_paths_doc, ".. function:: script_paths()\n" @@ -70,12 +70,12 @@ PyDoc_STRVAR(bpy_script_paths_doc, ); static PyObject *bpy_script_paths(PyObject *UNUSED(self)) { - PyObject *ret= PyTuple_New(2); + PyObject *ret = PyTuple_New(2); char *path; - path= BLI_get_folder(BLENDER_SYSTEM_SCRIPTS, NULL); + path = BLI_get_folder(BLENDER_SYSTEM_SCRIPTS, NULL); PyTuple_SET_ITEM(ret, 0, PyUnicode_FromString(path?path:"")); - path= BLI_get_folder(BLENDER_USER_SCRIPTS, NULL); + path = BLI_get_folder(BLENDER_USER_SCRIPTS, NULL); PyTuple_SET_ITEM(ret, 1, PyUnicode_FromString(path?path:"")); return ret; @@ -83,8 +83,8 @@ static PyObject *bpy_script_paths(PyObject *UNUSED(self)) static int bpy_blend_paths_visit_cb(void *userdata, char *UNUSED(path_dst), const char *path_src) { - PyObject *list= (PyObject *)userdata; - PyObject *item= PyUnicode_DecodeFSDefault(path_src); + PyObject *list = (PyObject *)userdata; + PyObject *item = PyUnicode_DecodeFSDefault(path_src); PyList_Append(list, item); Py_DECREF(item); return FALSE; /* never edits the path */ @@ -106,13 +106,13 @@ PyDoc_STRVAR(bpy_blend_paths_doc, ); static PyObject *bpy_blend_paths(PyObject *UNUSED(self), PyObject *args, PyObject *kw) { - int flag= 0; + int flag = 0; PyObject *list; - int absolute= FALSE; - int packed= FALSE; - int local= FALSE; - static const char *kwlist[]= {"absolute", "packed", "local", NULL}; + int absolute = FALSE; + int packed = FALSE; + int local = FALSE; + static const char *kwlist[] = {"absolute", "packed", "local", NULL}; if (!PyArg_ParseTupleAndKeywords(args, kw, "|ii:blend_paths", (char **)kwlist, &absolute, &packed)) @@ -124,7 +124,7 @@ static PyObject *bpy_blend_paths(PyObject *UNUSED(self), PyObject *args, PyObjec if (!packed) flag |= BPATH_TRAVERSE_SKIP_PACKED; if (local) flag |= BPATH_TRAVERSE_SKIP_LIBRARY; - list= PyList_New(0); + list = PyList_New(0); bpath_traverse_main(G.main, bpy_blend_paths_visit_cb, flag, (void *)list); @@ -132,13 +132,13 @@ static PyObject *bpy_blend_paths(PyObject *UNUSED(self), PyObject *args, PyObjec } -// PyDoc_STRVAR(bpy_user_resource_doc[]= // now in bpy/utils.py +// PyDoc_STRVAR(bpy_user_resource_doc[] = // now in bpy/utils.py static PyObject *bpy_user_resource(PyObject *UNUSED(self), PyObject *args, PyObject *kw) { char *type; - char *subdir= NULL; + char *subdir = NULL; int folder_id; - static const char *kwlist[]= {"type", "subdir", NULL}; + static const char *kwlist[] = {"type", "subdir", NULL}; char *path; @@ -146,20 +146,20 @@ static PyObject *bpy_user_resource(PyObject *UNUSED(self), PyObject *args, PyObj return NULL; /* stupid string compare */ - if (!strcmp(type, "DATAFILES")) folder_id= BLENDER_USER_DATAFILES; - else if (!strcmp(type, "CONFIG")) folder_id= BLENDER_USER_CONFIG; - else if (!strcmp(type, "SCRIPTS")) folder_id= BLENDER_USER_SCRIPTS; - else if (!strcmp(type, "AUTOSAVE")) folder_id= BLENDER_USER_AUTOSAVE; + if (!strcmp(type, "DATAFILES")) folder_id = BLENDER_USER_DATAFILES; + else if (!strcmp(type, "CONFIG")) folder_id = BLENDER_USER_CONFIG; + else if (!strcmp(type, "SCRIPTS")) folder_id = BLENDER_USER_SCRIPTS; + else if (!strcmp(type, "AUTOSAVE")) folder_id = BLENDER_USER_AUTOSAVE; else { PyErr_SetString(PyExc_ValueError, "invalid resource argument"); return NULL; } /* same logic as BLI_get_folder_create(), but best leave it up to the script author to create */ - path= BLI_get_folder(folder_id, subdir); + path = BLI_get_folder(folder_id, subdir); if (!path) - path= BLI_get_user_folder_notest(folder_id, subdir); + path = BLI_get_user_folder_notest(folder_id, subdir); return PyUnicode_DecodeFSDefault(path ? path : ""); } @@ -181,8 +181,8 @@ PyDoc_STRVAR(bpy_resource_path_doc, static PyObject *bpy_resource_path(PyObject *UNUSED(self), PyObject *args, PyObject *kw) { char *type; - int major= BLENDER_VERSION/100, minor= BLENDER_VERSION%100; - static const char *kwlist[]= {"type", "major", "minor", NULL}; + int major = BLENDER_VERSION / 100, minor = BLENDER_VERSION % 100; + static const char *kwlist[] = {"type", "major", "minor", NULL}; int folder_id; char *path; @@ -190,32 +190,32 @@ static PyObject *bpy_resource_path(PyObject *UNUSED(self), PyObject *args, PyObj return NULL; /* stupid string compare */ - if (!strcmp(type, "USER")) folder_id= BLENDER_RESOURCE_PATH_USER; - else if (!strcmp(type, "LOCAL")) folder_id= BLENDER_RESOURCE_PATH_LOCAL; - else if (!strcmp(type, "SYSTEM")) folder_id= BLENDER_RESOURCE_PATH_SYSTEM; + if (!strcmp(type, "USER")) folder_id = BLENDER_RESOURCE_PATH_USER; + else if (!strcmp(type, "LOCAL")) folder_id = BLENDER_RESOURCE_PATH_LOCAL; + else if (!strcmp(type, "SYSTEM")) folder_id = BLENDER_RESOURCE_PATH_SYSTEM; else { PyErr_SetString(PyExc_ValueError, "invalid resource argument"); return NULL; } - path= BLI_get_folder_version(folder_id, (major * 100) + minor, FALSE); + path = BLI_get_folder_version(folder_id, (major * 100) + minor, FALSE); return PyUnicode_DecodeFSDefault(path); } -static PyMethodDef meth_bpy_script_paths= +static PyMethodDef meth_bpy_script_paths = {"script_paths", (PyCFunction)bpy_script_paths, METH_NOARGS, bpy_script_paths_doc}; -static PyMethodDef meth_bpy_blend_paths= +static PyMethodDef meth_bpy_blend_paths = {"blend_paths", (PyCFunction)bpy_blend_paths, METH_VARARGS|METH_KEYWORDS, bpy_blend_paths_doc}; -static PyMethodDef meth_bpy_user_resource= +static PyMethodDef meth_bpy_user_resource = {"user_resource", (PyCFunction)bpy_user_resource, METH_VARARGS|METH_KEYWORDS, NULL}; -static PyMethodDef meth_bpy_resource_path= +static PyMethodDef meth_bpy_resource_path = {"resource_path", (PyCFunction)bpy_resource_path, METH_VARARGS|METH_KEYWORDS, bpy_resource_path_doc}; static PyObject *bpy_import_test(const char *modname) { - PyObject *mod= PyImport_ImportModuleLevel((char *)modname, NULL, NULL, NULL, 0); + PyObject *mod = PyImport_ImportModuleLevel((char *)modname, NULL, NULL, NULL, 0); if (mod) { Py_DECREF(mod); } @@ -238,11 +238,11 @@ void BPy_init_modules(void) PyObject *mod; /* Needs to be first since this dir is needed for future modules */ - char *modpath= BLI_get_folder(BLENDER_SYSTEM_SCRIPTS, "modules"); + char *modpath = BLI_get_folder(BLENDER_SYSTEM_SCRIPTS, "modules"); if (modpath) { // printf("bpy: found module path '%s'.\n", modpath); - PyObject *sys_path= PySys_GetObject("path"); /* borrow */ - PyObject *py_modpath= PyUnicode_FromString(modpath); + PyObject *sys_path = PySys_GetObject("path"); /* borrow */ + PyObject *py_modpath = PyUnicode_FromString(modpath); PyList_Insert(sys_path, 0, py_modpath); /* add first */ Py_DECREF(py_modpath); } @@ -252,7 +252,7 @@ void BPy_init_modules(void) /* stand alone utility modules not related to blender directly */ IDProp_Init_Types(); /* not actually a submodule, just types */ - mod= PyModule_New("_bpy"); + mod = PyModule_New("_bpy"); /* add the module so we can import it */ PyDict_SetItemString(PyImport_GetModuleDict(), "_bpy", mod); @@ -280,7 +280,7 @@ void BPy_init_modules(void) /* bpy context */ RNA_pointer_create(NULL, &RNA_Context, (void *)BPy_GetContext(), &ctx_ptr); - bpy_context_module= (BPy_StructRNA *)pyrna_struct_CreatePyObject(&ctx_ptr); + bpy_context_module = (BPy_StructRNA *)pyrna_struct_CreatePyObject(&ctx_ptr); /* odd that this is needed, 1 ref on creation and another for the module * but without we get a crash on exit */ Py_INCREF(bpy_context_module); @@ -298,5 +298,5 @@ void BPy_init_modules(void) PyModule_AddObject(mod, meth_bpy_unregister_class.ml_name, (PyObject *)PyCFunction_New(&meth_bpy_unregister_class, NULL)); /* add our own modules dir, this is a python package */ - bpy_package_py= bpy_import_test("bpy"); + bpy_package_py = bpy_import_test("bpy"); } diff --git a/source/blender/python/intern/bpy_app.c b/source/blender/python/intern/bpy_app.c index a10be098a61..d5f0cd205fa 100644 --- a/source/blender/python/intern/bpy_app.c +++ b/source/blender/python/intern/bpy_app.c @@ -59,7 +59,7 @@ extern char build_system[]; static PyTypeObject BlenderAppType; -static PyStructSequence_Field app_info_fields[]= { +static PyStructSequence_Field app_info_fields[] = { {(char *)"version", (char *)"The Blender version as a tuple of 3 numbers. eg. (2, 50, 11)"}, {(char *)"version_string", (char *)"The Blender version formatted as a string"}, {(char *)"version_char", (char *)"The Blender version character (for minor releases)"}, @@ -83,11 +83,11 @@ static PyStructSequence_Field app_info_fields[]= { {NULL} }; -static PyStructSequence_Desc app_info_desc= { +static PyStructSequence_Desc app_info_desc = { (char *)"bpy.app", /* name */ (char *)"This module contains application values that remain unchanged during runtime.", /* doc */ app_info_fields, /* fields */ - (sizeof(app_info_fields)/sizeof(PyStructSequence_Field)) - 1 + (sizeof(app_info_fields) / sizeof(PyStructSequence_Field)) - 1 }; #define DO_EXPAND(VAL) VAL ## 1 @@ -96,9 +96,9 @@ static PyStructSequence_Desc app_info_desc= { static PyObject *make_app_info(void) { PyObject *app_info; - int pos= 0; + int pos = 0; - app_info= PyStructSequence_New(&BlenderAppType); + app_info = PyStructSequence_New(&BlenderAppType); if (app_info == NULL) { return NULL; } @@ -110,8 +110,11 @@ static PyObject *make_app_info(void) #define SetObjItem(obj) \ PyStructSequence_SET_ITEM(app_info, pos++, obj) - SetObjItem(Py_BuildValue("(iii)", BLENDER_VERSION/100, BLENDER_VERSION%100, BLENDER_SUBVERSION)); - SetObjItem(PyUnicode_FromFormat("%d.%02d (sub %d)", BLENDER_VERSION/100, BLENDER_VERSION%100, BLENDER_SUBVERSION)); + SetObjItem(Py_BuildValue("(iii)", + BLENDER_VERSION / 100, BLENDER_VERSION % 100, BLENDER_SUBVERSION)); + SetObjItem(PyUnicode_FromFormat("%d.%02d (sub %d)", + BLENDER_VERSION / 100, BLENDER_VERSION % 100, BLENDER_SUBVERSION)); + #if defined(BLENDER_VERSION_CHAR) && EXPAND(BLENDER_VERSION_CHAR) != 1 SetStrItem(STRINGIFY(BLENDER_VERSION_CHAR)); #else @@ -170,7 +173,7 @@ static PyObject *bpy_app_debug_get(PyObject *UNUSED(self), void *UNUSED(closure) static int bpy_app_debug_set(PyObject *UNUSED(self), PyObject *value, void *UNUSED(closure)) { - int param= PyObject_IsTrue(value); + int param = PyObject_IsTrue(value); if (param < 0) { PyErr_SetString(PyExc_TypeError, "bpy.app.debug can only be True/False"); @@ -193,14 +196,14 @@ static PyObject *bpy_app_debug_value_get(PyObject *UNUSED(self), void *UNUSED(cl static int bpy_app_debug_value_set(PyObject *UNUSED(self), PyObject *value, void *UNUSED(closure)) { - int param= PyLong_AsSsize_t(value); + int param = PyLong_AsSsize_t(value); if (param == -1 && PyErr_Occurred()) { PyErr_SetString(PyExc_TypeError, "bpy.app.debug_value can only be set to a whole number"); return -1; } - G.rt= param; + G.rt = param; return 0; } @@ -229,7 +232,7 @@ static PyObject *bpy_app_driver_dict_get(PyObject *UNUSED(self), void *UNUSED(cl } -static PyGetSetDef bpy_app_getsets[]= { +static PyGetSetDef bpy_app_getsets[] = { {(char *)"debug", bpy_app_debug_get, bpy_app_debug_set, (char *)bpy_app_debug_doc, NULL}, {(char *)"debug_value", bpy_app_debug_value_get, bpy_app_debug_value_set, (char *)bpy_app_debug_value_doc, NULL}, {(char *)"tempdir", bpy_app_tempdir_get, NULL, (char *)bpy_app_tempdir_doc, NULL}, @@ -242,7 +245,7 @@ static void py_struct_seq_getset_init(void) /* tricky dynamic members, not to py-spec! */ PyGetSetDef *getset; - for (getset= bpy_app_getsets; getset->name; getset++) { + for (getset = bpy_app_getsets; getset->name; getset++) { PyDict_SetItemString(BlenderAppType.tp_dict, getset->name, PyDescr_NewGetSet(&BlenderAppType, getset)); } } @@ -255,12 +258,12 @@ PyObject *BPY_app_struct(void) PyStructSequence_InitType(&BlenderAppType, &app_info_desc); - ret= make_app_info(); + ret = make_app_info(); /* prevent user from creating new instances */ - BlenderAppType.tp_init= NULL; - BlenderAppType.tp_new= NULL; - BlenderAppType.tp_hash= (hashfunc)_Py_HashPointer; /* without this we can't do set(sys.modules) [#29635] */ + BlenderAppType.tp_init = NULL; + BlenderAppType.tp_new = NULL; + BlenderAppType.tp_hash = (hashfunc)_Py_HashPointer; /* without this we can't do set(sys.modules) [#29635] */ /* kindof a hack ontop of PyStructSequence */ py_struct_seq_getset_init(); diff --git a/source/blender/python/intern/bpy_app_handlers.c b/source/blender/python/intern/bpy_app_handlers.c index dc9ef9ee8e8..721bce51693 100644 --- a/source/blender/python/intern/bpy_app_handlers.c +++ b/source/blender/python/intern/bpy_app_handlers.c @@ -41,7 +41,7 @@ void bpy_app_generic_callback(struct Main *main, struct ID *id, void *arg); static PyTypeObject BlenderAppCbType; -static PyStructSequence_Field app_cb_info_fields[]= { +static PyStructSequence_Field app_cb_info_fields[] = { {(char *)"frame_change_pre", (char *)"Callback list - on frame change for playback and rendering (before)"}, {(char *)"frame_change_post", (char *)"Callback list - on frame change for playback and rendering (after)"}, {(char *)"render_pre", (char *)"Callback list - on render (before)"}, @@ -61,11 +61,11 @@ static PyStructSequence_Field app_cb_info_fields[]= { {NULL} }; -static PyStructSequence_Desc app_cb_info_desc= { +static PyStructSequence_Desc app_cb_info_desc = { (char *)"bpy.app.handlers", /* name */ (char *)"This module contains callbacks", /* doc */ app_cb_info_fields, /* fields */ - (sizeof(app_cb_info_fields)/sizeof(PyStructSequence_Field)) - 1 + (sizeof(app_cb_info_fields) / sizeof(PyStructSequence_Field)) - 1 }; /* @@ -86,7 +86,7 @@ static PyObject *bpy_app_handlers_persistent_new(PyTypeObject *UNUSED(type), PyO return NULL; if (PyFunction_Check(value)) { - PyObject **dict_ptr= _PyObject_GetDictPtr(value); + PyObject **dict_ptr = _PyObject_GetDictPtr(value); if (dict_ptr == NULL) { PyErr_SetString(PyExc_ValueError, "bpy.app.handlers.persistent wasn't able to " @@ -96,7 +96,7 @@ static PyObject *bpy_app_handlers_persistent_new(PyTypeObject *UNUSED(type), PyO else { /* set id */ if (*dict_ptr == NULL) { - *dict_ptr= PyDict_New(); + *dict_ptr = PyDict_New(); } PyDict_SetItemString(*dict_ptr, PERMINENT_CB_ID, Py_None); @@ -163,23 +163,23 @@ static PyTypeObject BPyPersistent_Type = { 0, /* tp_free */ }; -static PyObject *py_cb_array[BLI_CB_EVT_TOT]= {NULL}; +static PyObject *py_cb_array[BLI_CB_EVT_TOT] = {NULL}; static PyObject *make_app_cb_info(void) { PyObject *app_cb_info; - int pos= 0; + int pos = 0; - app_cb_info= PyStructSequence_New(&BlenderAppCbType); + app_cb_info = PyStructSequence_New(&BlenderAppCbType); if (app_cb_info == NULL) { return NULL; } - for (pos= 0; pos < BLI_CB_EVT_TOT; pos++) { + for (pos = 0; pos < BLI_CB_EVT_TOT; pos++) { if (app_cb_info_fields[pos].name == NULL) { Py_FatalError("invalid callback slots 1"); } - PyStructSequence_SET_ITEM(app_cb_info, pos, (py_cb_array[pos]= PyList_New(0))); + PyStructSequence_SET_ITEM(app_cb_info, pos, (py_cb_array[pos] = PyList_New(0))); } if (app_cb_info_fields[pos + APP_CB_OTHER_FIELDS].name != NULL) { Py_FatalError("invalid callback slots 2"); @@ -196,7 +196,7 @@ PyObject *BPY_app_handlers_struct(void) PyObject *ret; #if defined(_MSC_VER) || defined(FREE_WINDOWS) - BPyPersistent_Type.ob_base.ob_base.ob_type= &PyType_Type; + BPyPersistent_Type.ob_base.ob_base.ob_type = &PyType_Type; #endif if (PyType_Ready(&BPyPersistent_Type) < 0) { @@ -205,24 +205,24 @@ PyObject *BPY_app_handlers_struct(void) PyStructSequence_InitType(&BlenderAppCbType, &app_cb_info_desc); - ret= make_app_cb_info(); + ret = make_app_cb_info(); /* prevent user from creating new instances */ - BlenderAppCbType.tp_init= NULL; - BlenderAppCbType.tp_new= NULL; - BlenderAppCbType.tp_hash= (hashfunc)_Py_HashPointer; /* without this we can't do set(sys.modules) [#29635] */ + BlenderAppCbType.tp_init = NULL; + BlenderAppCbType.tp_new = NULL; + BlenderAppCbType.tp_hash = (hashfunc)_Py_HashPointer; /* without this we can't do set(sys.modules) [#29635] */ /* assign the C callbacks */ if (ret) { - static bCallbackFuncStore funcstore_array[BLI_CB_EVT_TOT]= {{NULL}}; + static bCallbackFuncStore funcstore_array[BLI_CB_EVT_TOT] = {{NULL}}; bCallbackFuncStore *funcstore; - int pos= 0; + int pos = 0; - for (pos= 0; pos < BLI_CB_EVT_TOT; pos++) { - funcstore= &funcstore_array[pos]; - funcstore->func= bpy_app_generic_callback; - funcstore->alloc= 0; - funcstore->arg= SET_INT_IN_POINTER(pos); + for (pos = 0; pos < BLI_CB_EVT_TOT; pos++) { + funcstore = &funcstore_array[pos]; + funcstore->func = bpy_app_generic_callback; + funcstore->alloc = 0; + funcstore->arg = SET_INT_IN_POINTER(pos); BLI_add_cb(funcstore, pos); } } @@ -232,30 +232,30 @@ PyObject *BPY_app_handlers_struct(void) void BPY_app_handlers_reset(const short do_all) { - int pos= 0; + int pos = 0; if (do_all) { - for (pos= 0; pos < BLI_CB_EVT_TOT; pos++) { + for (pos = 0; pos < BLI_CB_EVT_TOT; pos++) { /* clear list */ PyList_SetSlice(py_cb_array[pos], 0, PY_SSIZE_T_MAX, NULL); } } else { /* save string conversion thrashing */ - PyObject *perm_id_str= PyUnicode_FromString(PERMINENT_CB_ID); + PyObject *perm_id_str = PyUnicode_FromString(PERMINENT_CB_ID); - for (pos= 0; pos < BLI_CB_EVT_TOT; pos++) { + for (pos = 0; pos < BLI_CB_EVT_TOT; pos++) { /* clear only items without PERMINENT_CB_ID */ - PyObject *ls= py_cb_array[pos]; + PyObject *ls = py_cb_array[pos]; Py_ssize_t i; PyObject *item; PyObject **dict_ptr; - for (i= PyList_GET_SIZE(ls) - 1; i >= 0; i--) { + for (i = PyList_GET_SIZE(ls) - 1; i >= 0; i--) { - if ( (PyFunction_Check((item= PyList_GET_ITEM(ls, i)))) && - (dict_ptr= _PyObject_GetDictPtr(item)) && + if ( (PyFunction_Check((item = PyList_GET_ITEM(ls, i)))) && + (dict_ptr = _PyObject_GetDictPtr(item)) && (*dict_ptr) && (PyDict_GetItem(*dict_ptr, perm_id_str) != NULL)) { @@ -276,12 +276,12 @@ void BPY_app_handlers_reset(const short do_all) /* the actual callback - not necessarily called from py */ void bpy_app_generic_callback(struct Main *UNUSED(main), struct ID *id, void *arg) { - PyObject *cb_list= py_cb_array[GET_INT_FROM_POINTER(arg)]; + PyObject *cb_list = py_cb_array[GET_INT_FROM_POINTER(arg)]; Py_ssize_t cb_list_len; - if ((cb_list_len= PyList_GET_SIZE(cb_list)) > 0) { - PyGILState_STATE gilstate= PyGILState_Ensure(); + if ((cb_list_len = PyList_GET_SIZE(cb_list)) > 0) { + PyGILState_STATE gilstate = PyGILState_Ensure(); - PyObject* args= PyTuple_New(1); // save python creating each call + PyObject* args = PyTuple_New(1); // save python creating each call PyObject* func; PyObject* ret; Py_ssize_t pos; @@ -298,10 +298,10 @@ void bpy_app_generic_callback(struct Main *UNUSED(main), struct ID *id, void *ar } // Iterate the list and run the callbacks - for (pos=0; pos < cb_list_len; pos++) { - func= PyList_GET_ITEM(cb_list, pos); - ret= PyObject_Call(func, args, NULL); - if (ret==NULL) { + for (pos = 0; pos < cb_list_len; pos++) { + func = PyList_GET_ITEM(cb_list, pos); + ret = PyObject_Call(func, args, NULL); + if (ret == NULL) { PyErr_Print(); PyErr_Clear(); } diff --git a/source/blender/python/intern/bpy_driver.c b/source/blender/python/intern/bpy_driver.c index e628cb891d8..95b00b18f43 100644 --- a/source/blender/python/intern/bpy_driver.c +++ b/source/blender/python/intern/bpy_driver.c @@ -47,7 +47,7 @@ extern void BPY_update_rna_module(void); /* for pydrivers (drivers using one-line Python expressions to express relationships between targets) */ -PyObject *bpy_pydriver_Dict= NULL; +PyObject *bpy_pydriver_Dict = NULL; /* For faster execution we keep a special dictionary for pydrivers, with * the needed modules and aliases. @@ -59,32 +59,32 @@ int bpy_pydriver_create_dict(void) /* validate namespace for driver evaluation */ if (bpy_pydriver_Dict) return -1; - d= PyDict_New(); + d = PyDict_New(); if (d == NULL) return -1; else - bpy_pydriver_Dict= d; + bpy_pydriver_Dict = d; /* import some modules: builtins, bpy, math, (Blender.noise)*/ PyDict_SetItemString(d, "__builtins__", PyEval_GetBuiltins()); - mod= PyImport_ImportModule("math"); + mod = PyImport_ImportModule("math"); if (mod) { PyDict_Merge(d, PyModule_GetDict(mod), 0); /* 0 - dont overwrite existing values */ Py_DECREF(mod); } /* add bpy to global namespace */ - mod= PyImport_ImportModuleLevel((char *)"bpy", NULL, NULL, NULL, 0); + mod = PyImport_ImportModuleLevel((char *)"bpy", NULL, NULL, NULL, 0); if (mod) { PyDict_SetItemString(bpy_pydriver_Dict, "bpy", mod); Py_DECREF(mod); } /* add noise to global namespace */ - mod= PyImport_ImportModuleLevel((char *)"mathutils", NULL, NULL, NULL, 0); + mod = PyImport_ImportModuleLevel((char *)"mathutils", NULL, NULL, NULL, 0); if (mod) { - PyObject *modsub= PyDict_GetItemString(PyModule_GetDict(mod), "noise"); + PyObject *modsub = PyDict_GetItemString(PyModule_GetDict(mod), "noise"); PyDict_SetItemString(bpy_pydriver_Dict, "noise", modsub); Py_DECREF(mod); } @@ -93,9 +93,9 @@ int bpy_pydriver_create_dict(void) } /* note, this function should do nothing most runs, only when changing frame */ -static PyObject *bpy_pydriver_InternStr__frame= NULL; +static PyObject *bpy_pydriver_InternStr__frame = NULL; /* not thread safe but neither is python */ -static float bpy_pydriver_evaltime_prev= FLT_MAX; +static float bpy_pydriver_evaltime_prev = FLT_MAX; static void bpy_pydriver_update_dict(const float evaltime) { @@ -103,14 +103,14 @@ static void bpy_pydriver_update_dict(const float evaltime) /* currently only update the frame */ if (bpy_pydriver_InternStr__frame == NULL) { - bpy_pydriver_InternStr__frame= PyUnicode_FromString("frame"); + bpy_pydriver_InternStr__frame = PyUnicode_FromString("frame"); } PyDict_SetItem(bpy_pydriver_Dict, bpy_pydriver_InternStr__frame, PyFloat_FromDouble(evaltime)); - bpy_pydriver_evaltime_prev= evaltime; + bpy_pydriver_evaltime_prev = evaltime; } } @@ -122,21 +122,21 @@ static void bpy_pydriver_update_dict(const float evaltime) void BPY_driver_reset(void) { PyGILState_STATE gilstate; - int use_gil= 1; /* !PYC_INTERPRETER_ACTIVE; */ + int use_gil = 1; /* !PYC_INTERPRETER_ACTIVE; */ if (use_gil) - gilstate= PyGILState_Ensure(); + gilstate = PyGILState_Ensure(); if (bpy_pydriver_Dict) { /* free the global dict used by pydrivers */ PyDict_Clear(bpy_pydriver_Dict); Py_DECREF(bpy_pydriver_Dict); - bpy_pydriver_Dict= NULL; + bpy_pydriver_Dict = NULL; } if (bpy_pydriver_InternStr__frame) { Py_DECREF(bpy_pydriver_InternStr__frame); - bpy_pydriver_InternStr__frame= NULL; - bpy_pydriver_evaltime_prev= FLT_MAX; + bpy_pydriver_InternStr__frame = NULL; + bpy_pydriver_evaltime_prev = FLT_MAX; } if (use_gil) @@ -170,22 +170,22 @@ static void pydriver_error(ChannelDriver *driver) */ float BPY_driver_exec(ChannelDriver *driver, const float evaltime) { - PyObject *driver_vars=NULL; - PyObject *retval= NULL; + PyObject *driver_vars = NULL; + PyObject *retval = NULL; PyObject *expr_vars; /* speed up by pre-hashing string & avoids re-converting unicode strings for every execution */ PyObject *expr_code; PyGILState_STATE gilstate; int use_gil; DriverVar *dvar; - double result= 0.0; /* default return */ - char *expr= NULL; - short targets_ok= 1; + double result = 0.0; /* default return */ + char *expr = NULL; + short targets_ok = 1; int i; /* get the py expression to be evaluated */ - expr= driver->expression; - if ((expr == NULL) || (expr[0]=='\0')) + expr = driver->expression; + if ((expr == NULL) || (expr[0] == '\0')) return 0.0f; if (!(G.f & G_SCRIPT_AUTOEXEC)) { @@ -193,10 +193,10 @@ float BPY_driver_exec(ChannelDriver *driver, const float evaltime) return 0.0f; } - use_gil= 1; /* !PYC_INTERPRETER_ACTIVE; */ + use_gil = 1; /* !PYC_INTERPRETER_ACTIVE; */ if (use_gil) - gilstate= PyGILState_Ensure(); + gilstate = PyGILState_Ensure(); /* needed since drivers are updated directly after undo where 'main' is * re-allocated [#28807] */ @@ -216,51 +216,51 @@ float BPY_driver_exec(ChannelDriver *driver, const float evaltime) bpy_pydriver_update_dict(evaltime); - if (driver->expr_comp==NULL) + if (driver->expr_comp == NULL) driver->flag |= DRIVER_FLAG_RECOMPILE; /* compile the expression first if it hasn't been compiled or needs to be rebuilt */ if (driver->flag & DRIVER_FLAG_RECOMPILE) { Py_XDECREF(driver->expr_comp); - driver->expr_comp= PyTuple_New(2); + driver->expr_comp = PyTuple_New(2); - expr_code= Py_CompileString(expr, "<bpy driver>", Py_eval_input); + expr_code = Py_CompileString(expr, "<bpy driver>", Py_eval_input); PyTuple_SET_ITEM(((PyObject *)driver->expr_comp), 0, expr_code); driver->flag &= ~DRIVER_FLAG_RECOMPILE; driver->flag |= DRIVER_FLAG_RENAMEVAR; /* maybe this can be removed but for now best keep until were sure */ } else { - expr_code= PyTuple_GET_ITEM(((PyObject *)driver->expr_comp), 0); + expr_code = PyTuple_GET_ITEM(((PyObject *)driver->expr_comp), 0); } if (driver->flag & DRIVER_FLAG_RENAMEVAR) { /* may not be set */ - expr_vars= PyTuple_GET_ITEM(((PyObject *)driver->expr_comp), 1); + expr_vars = PyTuple_GET_ITEM(((PyObject *)driver->expr_comp), 1); Py_XDECREF(expr_vars); - expr_vars= PyTuple_New(BLI_countlist(&driver->variables)); + expr_vars = PyTuple_New(BLI_countlist(&driver->variables)); PyTuple_SET_ITEM(((PyObject *)driver->expr_comp), 1, expr_vars); - for (dvar= driver->variables.first, i=0; dvar; dvar= dvar->next) { + for (dvar = driver->variables.first, i = 0; dvar; dvar = dvar->next) { PyTuple_SET_ITEM(expr_vars, i++, PyUnicode_FromString(dvar->name)); } driver->flag &= ~DRIVER_FLAG_RENAMEVAR; } else { - expr_vars= PyTuple_GET_ITEM(((PyObject *)driver->expr_comp), 1); + expr_vars = PyTuple_GET_ITEM(((PyObject *)driver->expr_comp), 1); } /* add target values to a dict that will be used as '__locals__' dict */ - driver_vars= PyDict_New(); // XXX do we need to decref this? - for (dvar= driver->variables.first, i=0; dvar; dvar= dvar->next) { - PyObject *driver_arg= NULL; - float tval= 0.0f; + driver_vars = PyDict_New(); // XXX do we need to decref this? + for (dvar = driver->variables.first, i = 0; dvar; dvar = dvar->next) { + PyObject *driver_arg = NULL; + float tval = 0.0f; /* try to get variable value */ - tval= driver_get_variable_value(driver, dvar); - driver_arg= PyFloat_FromDouble((double)tval); + tval = driver_get_variable_value(driver, dvar); + driver_arg = PyFloat_FromDouble((double)tval); /* try to add to dictionary */ /* if (PyDict_SetItemString(driver_vars, dvar->name, driver_arg)) { */ @@ -269,7 +269,7 @@ float BPY_driver_exec(ChannelDriver *driver, const float evaltime) if (targets_ok) { /* first one - print some extra info for easier identification */ fprintf(stderr, "\nBPY_driver_eval() - Error while evaluating PyDriver:\n"); - targets_ok= 0; + targets_ok = 0; } fprintf(stderr, "\tBPY_driver_eval() - couldn't add variable '%s' to namespace\n", dvar->name); @@ -282,11 +282,11 @@ float BPY_driver_exec(ChannelDriver *driver, const float evaltime) #if 0 // slow, with this can avoid all Py_CompileString above. /* execute expression to get a value */ - retval= PyRun_String(expr, Py_eval_input, bpy_pydriver_Dict, driver_vars); + retval = PyRun_String(expr, Py_eval_input, bpy_pydriver_Dict, driver_vars); #else /* evaluate the compiled expression */ if (expr_code) - retval= PyEval_EvalCode((void *)expr_code, bpy_pydriver_Dict, driver_vars); + retval = PyEval_EvalCode((void *)expr_code, bpy_pydriver_Dict, driver_vars); #endif /* decref the driver vars first... */ @@ -296,10 +296,10 @@ float BPY_driver_exec(ChannelDriver *driver, const float evaltime) if (retval == NULL) { pydriver_error(driver); } - else if ((result= PyFloat_AsDouble(retval)) == -1.0 && PyErr_Occurred()) { + else if ((result = PyFloat_AsDouble(retval)) == -1.0 && PyErr_Occurred()) { pydriver_error(driver); Py_DECREF(retval); - result= 0.0; + result = 0.0; } else { /* all fine, make sure the "invalid expression" flag is cleared */ diff --git a/source/blender/python/intern/bpy_interface.c b/source/blender/python/intern/bpy_interface.c index 90d5cccc85a..7d91438e4f7 100644 --- a/source/blender/python/intern/bpy_interface.c +++ b/source/blender/python/intern/bpy_interface.c @@ -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; diff --git a/source/blender/python/intern/bpy_interface_atexit.c b/source/blender/python/intern/bpy_interface_atexit.c index a0cf3c38503..53775e7d893 100644 --- a/source/blender/python/intern/bpy_interface_atexit.c +++ b/source/blender/python/intern/bpy_interface_atexit.c @@ -40,15 +40,15 @@ static PyObject *bpy_atexit(PyObject *UNUSED(self), PyObject *UNUSED(args), PyObject *UNUSED(kw)) { /* close down enough of blender at least not to crash */ - struct bContext *C= BPy_GetContext(); + struct bContext *C = BPy_GetContext(); WM_exit_ext(C, 0); Py_RETURN_NONE; } -static PyMethodDef meth_bpy_atexit= {"bpy_atexit", (PyCFunction)bpy_atexit, METH_NOARGS, NULL}; -static PyObject *func_bpy_atregister= NULL; /* borrowed referebce, atexit holds */ +static PyMethodDef meth_bpy_atexit = {"bpy_atexit", (PyCFunction)bpy_atexit, METH_NOARGS, NULL}; +static PyObject *func_bpy_atregister = NULL; /* borrowed referebce, atexit holds */ static void atexit_func_call(const char *func_name, PyObject *atexit_func_arg) { @@ -56,15 +56,15 @@ static void atexit_func_call(const char *func_name, PyObject *atexit_func_arg) * this is intended, but if its problematic it could be changed * - campbell */ - PyObject *atexit_mod= PyImport_ImportModuleLevel((char *)"atexit", NULL, NULL, NULL, 0); - PyObject *atexit_func= PyObject_GetAttrString(atexit_mod, func_name); - PyObject *args= PyTuple_New(1); + PyObject *atexit_mod = PyImport_ImportModuleLevel((char *)"atexit", NULL, NULL, NULL, 0); + PyObject *atexit_func = PyObject_GetAttrString(atexit_mod, func_name); + PyObject *args = PyTuple_New(1); PyObject *ret; PyTuple_SET_ITEM(args, 0, atexit_func_arg); Py_INCREF(atexit_func_arg); /* only incref so we dont dec'ref along with 'args' */ - ret= PyObject_CallObject(atexit_func, args); + ret = PyObject_CallObject(atexit_func, args); Py_DECREF(atexit_mod); Py_DECREF(atexit_func); @@ -83,7 +83,7 @@ void BPY_atexit_register(void) /* atexit module owns this new function reference */ BLI_assert(func_bpy_atregister == NULL); - func_bpy_atregister= (PyObject *)PyCFunction_New(&meth_bpy_atexit, NULL); + func_bpy_atregister = (PyObject *)PyCFunction_New(&meth_bpy_atexit, NULL); atexit_func_call("register", func_bpy_atregister); } @@ -92,5 +92,5 @@ void BPY_atexit_unregister(void) BLI_assert(func_bpy_atregister != NULL); atexit_func_call("unregister", func_bpy_atregister); - func_bpy_atregister= NULL; /* don't really need to set but just incase */ + func_bpy_atregister = NULL; /* don't really need to set but just incase */ } diff --git a/source/blender/python/intern/bpy_intern_string.c b/source/blender/python/intern/bpy_intern_string.c index 4f206c4c365..7c8291d62d3 100644 --- a/source/blender/python/intern/bpy_intern_string.c +++ b/source/blender/python/intern/bpy_intern_string.c @@ -41,12 +41,12 @@ PyObject *bpy_intern_str___slots__; void bpy_intern_string_init(void) { - bpy_intern_str_register= PyUnicode_FromString("register"); - bpy_intern_str_unregister= PyUnicode_FromString("unregister"); - bpy_intern_str_bl_rna= PyUnicode_FromString("bl_rna"); - bpy_intern_str_order= PyUnicode_FromString("order"); - bpy_intern_str_attr= PyUnicode_FromString("attr"); - bpy_intern_str___slots__= PyUnicode_FromString("__slots__"); + bpy_intern_str_register = PyUnicode_FromString("register"); + bpy_intern_str_unregister = PyUnicode_FromString("unregister"); + bpy_intern_str_bl_rna = PyUnicode_FromString("bl_rna"); + bpy_intern_str_order = PyUnicode_FromString("order"); + bpy_intern_str_attr = PyUnicode_FromString("attr"); + bpy_intern_str___slots__ = PyUnicode_FromString("__slots__"); } void bpy_intern_string_exit(void) diff --git a/source/blender/python/intern/bpy_library.c b/source/blender/python/intern/bpy_library.c index a6426a02e18..ed3b758a6b4 100644 --- a/source/blender/python/intern/bpy_library.c +++ b/source/blender/python/intern/bpy_library.c @@ -76,7 +76,7 @@ static PyObject *bpy_lib_enter(BPy_Library *self, PyObject *args); static PyObject *bpy_lib_exit(BPy_Library *self, PyObject *args); static PyObject *bpy_lib_dir(BPy_Library *self); -static PyMethodDef bpy_lib_methods[]= { +static PyMethodDef bpy_lib_methods[] = { {"__enter__", (PyCFunction)bpy_lib_enter, METH_NOARGS}, {"__exit__", (PyCFunction)bpy_lib_exit, METH_VARARGS}, {"__dir__", (PyCFunction)bpy_lib_dir, METH_NOARGS}, @@ -90,7 +90,7 @@ static void bpy_lib_dealloc(BPy_Library *self) } -static PyTypeObject bpy_lib_Type= { +static PyTypeObject bpy_lib_Type = { PyVarObject_HEAD_INIT(NULL, 0) "bpy_lib", /* tp_name */ sizeof(BPy_Library), /* tp_basicsize */ @@ -184,25 +184,25 @@ PyDoc_STRVAR(bpy_lib_load_doc, ); static PyObject *bpy_lib_load(PyObject *UNUSED(self), PyObject *args, PyObject *kwds) { - static const char *kwlist[]= {"filepath", "link", "relative", NULL}; + static const char *kwlist[] = {"filepath", "link", "relative", NULL}; BPy_Library *ret; - const char* filename= NULL; - int is_rel= 0, is_link= 0; + const char* filename = NULL; + int is_rel = 0, is_link = 0; if (!PyArg_ParseTupleAndKeywords(args, kwds, "s|ii:load", (char **)kwlist, &filename, &is_link, &is_rel)) return NULL; - ret= PyObject_New(BPy_Library, &bpy_lib_Type); + ret = PyObject_New(BPy_Library, &bpy_lib_Type); BLI_strncpy(ret->relpath, filename, sizeof(ret->relpath)); BLI_strncpy(ret->abspath, filename, sizeof(ret->abspath)); BLI_path_abs(ret->abspath, G.main->name); - ret->blo_handle= NULL; + ret->blo_handle = NULL; ret->flag= (is_link ? FILE_LINK : 0) | (is_rel ? FILE_RELPATH : 0); - ret->dict= PyDict_New(); + ret->dict = PyDict_New(); return (PyObject *)ret; } @@ -213,19 +213,19 @@ static PyObject *_bpy_names(BPy_Library *self, int blocktype) LinkNode *l, *names; int totnames; - names= BLO_blendhandle_get_datablock_names(self->blo_handle, blocktype, &totnames); + names = BLO_blendhandle_get_datablock_names(self->blo_handle, blocktype, &totnames); if (names) { - int counter= 0; - list= PyList_New(totnames); - for (l= names; l; l= l->next) { + int counter = 0; + list = PyList_New(totnames); + for (l = names; l; l = l->next) { PyList_SET_ITEM(list, counter, PyUnicode_FromString((char *)l->link)); counter++; } BLI_linklist_free(names, free); /* free linklist *and* each node's data */ } else { - list= PyList_New(0); + list = PyList_New(0); } return list; @@ -235,12 +235,12 @@ static PyObject *bpy_lib_enter(BPy_Library *self, PyObject *UNUSED(args)) { PyObject *ret; BPy_Library *self_from; - PyObject *from_dict= PyDict_New(); + PyObject *from_dict = PyDict_New(); ReportList reports; BKE_reports_init(&reports, RPT_STORE); - self->blo_handle= BLO_blendhandle_from_file(self->abspath, &reports); + self->blo_handle = BLO_blendhandle_from_file(self->abspath, &reports); if (self->blo_handle == NULL) { if (BPy_reports_to_error(&reports, PyExc_IOError, TRUE) != -1) { @@ -251,11 +251,11 @@ static PyObject *bpy_lib_enter(BPy_Library *self, PyObject *UNUSED(args)) return NULL; } else { - int i= 0, code; - while ((code= BKE_idcode_iter_step(&i))) { + int i = 0, code; + while ((code = BKE_idcode_iter_step(&i))) { if (BKE_idcode_is_linkable(code)) { - const char *name_plural= BKE_idcode_to_name_plural(code); - PyObject *str= PyUnicode_FromString(name_plural); + const char *name_plural = BKE_idcode_to_name_plural(code); + PyObject *str = PyUnicode_FromString(name_plural); PyDict_SetItem(self->dict, str, PyList_New(0)); PyDict_SetItem(from_dict, str, _bpy_names(self, code)); Py_DECREF(str); @@ -264,16 +264,16 @@ static PyObject *bpy_lib_enter(BPy_Library *self, PyObject *UNUSED(args)) } /* create a dummy */ - self_from= PyObject_New(BPy_Library, &bpy_lib_Type); + self_from = PyObject_New(BPy_Library, &bpy_lib_Type); BLI_strncpy(self_from->relpath, self->relpath, sizeof(self_from->relpath)); BLI_strncpy(self_from->abspath, self->abspath, sizeof(self_from->abspath)); - self_from->blo_handle= NULL; - self_from->flag= 0; - self_from->dict= from_dict; /* owns the dict */ + self_from->blo_handle = NULL; + self_from->flag = 0; + self_from->dict = from_dict; /* owns the dict */ /* return pair */ - ret= PyTuple_New(2); + ret = PyTuple_New(2); PyTuple_SET_ITEM(ret, 0, (PyObject *)self_from); @@ -317,43 +317,43 @@ static void bpy_lib_exit_warn_type(BPy_Library *self, PyObject *item) static PyObject *bpy_lib_exit(BPy_Library *self, PyObject *UNUSED(args)) { - Main *bmain= CTX_data_main(BPy_GetContext()); - Main *mainl= NULL; - int err= 0; + Main *bmain = CTX_data_main(BPy_GetContext()); + Main *mainl = NULL; + int err = 0; flag_all_listbases_ids(LIB_PRE_EXISTING, 1); /* here appending/linking starts */ - mainl= BLO_library_append_begin(bmain, &(self->blo_handle), self->relpath); + mainl = BLO_library_append_begin(bmain, &(self->blo_handle), self->relpath); { - int i= 0, code; - while ((code= BKE_idcode_iter_step(&i))) { + int i = 0, code; + while ((code = BKE_idcode_iter_step(&i))) { if (BKE_idcode_is_linkable(code)) { - const char *name_plural= BKE_idcode_to_name_plural(code); - PyObject *ls= PyDict_GetItemString(self->dict, name_plural); + const char *name_plural = BKE_idcode_to_name_plural(code); + PyObject *ls = PyDict_GetItemString(self->dict, name_plural); // printf("lib: %s\n", name_plural); if (ls && PyList_Check(ls)) { /* loop */ - Py_ssize_t size= PyList_GET_SIZE(ls); + Py_ssize_t size = PyList_GET_SIZE(ls); Py_ssize_t i; PyObject *item; const char *item_str; - for (i= 0; i < size; i++) { - item= PyList_GET_ITEM(ls, i); - item_str= _PyUnicode_AsString(item); + for (i = 0; i < size; i++) { + item = PyList_GET_ITEM(ls, i); + item_str = _PyUnicode_AsString(item); // printf(" %s\n", item_str); if (item_str) { - ID *id= BLO_library_append_named_part(mainl, &(self->blo_handle), item_str, code); + ID *id = BLO_library_append_named_part(mainl, &(self->blo_handle), item_str, code); if (id) { #ifdef USE_RNA_DATABLOCKS PointerRNA id_ptr; RNA_id_pointer_create(id, &id_ptr); Py_DECREF(item); - item= pyrna_struct_CreatePyObject(&id_ptr); + item = pyrna_struct_CreatePyObject(&id_ptr); #endif } else { @@ -361,7 +361,7 @@ static PyObject *bpy_lib_exit(BPy_Library *self, PyObject *UNUSED(args)) /* just warn for now */ /* err = -1; */ #ifdef USE_RNA_DATABLOCKS - item= Py_None; + item = Py_None; Py_INCREF(item); #endif } @@ -374,7 +374,7 @@ static PyObject *bpy_lib_exit(BPy_Library *self, PyObject *UNUSED(args)) PyErr_Clear(); #ifdef USE_RNA_DATABLOCKS - item= Py_None; + item = Py_None; Py_INCREF(item); #endif } @@ -391,22 +391,22 @@ static PyObject *bpy_lib_exit(BPy_Library *self, PyObject *UNUSED(args)) if (err == -1) { /* exception raised above, XXX, this leaks some memory */ BLO_blendhandle_close(self->blo_handle); - self->blo_handle= NULL; + self->blo_handle = NULL; flag_all_listbases_ids(LIB_PRE_EXISTING, 0); return NULL; } else { - Library *lib= mainl->curlib; /* newly added lib, assign before append end */ + Library *lib = mainl->curlib; /* newly added lib, assign before append end */ BLO_library_append_end(NULL, mainl, &(self->blo_handle), 0, self->flag); BLO_blendhandle_close(self->blo_handle); - self->blo_handle= NULL; + self->blo_handle = NULL; { /* copied from wm_operator.c */ /* mark all library linked objects to be updated */ recalc_all_library_objects(G.main); /* append, rather than linking */ - if ((self->flag & FILE_LINK)==0) { + if ((self->flag & FILE_LINK) == 0) { BKE_library_make_local(bmain, lib, 1); } } @@ -425,14 +425,14 @@ static PyObject *bpy_lib_dir(BPy_Library *self) int bpy_lib_init(PyObject *mod_par) { - static PyMethodDef load_meth= {"load", (PyCFunction)bpy_lib_load, + static PyMethodDef load_meth = {"load", (PyCFunction)bpy_lib_load, METH_STATIC|METH_VARARGS|METH_KEYWORDS, bpy_lib_load_doc}; PyModule_AddObject(mod_par, "_library_load", PyCFunction_New(&load_meth, NULL)); /* some compilers dont like accessing this directly, delay assignment */ - bpy_lib_Type.tp_getattro= PyObject_GenericGetAttr; + bpy_lib_Type.tp_getattro = PyObject_GenericGetAttr; if (PyType_Ready(&bpy_lib_Type) < 0) return -1; diff --git a/source/blender/python/intern/bpy_operator.c b/source/blender/python/intern/bpy_operator.c index 70346a65bf9..6a6e6595ed4 100644 --- a/source/blender/python/intern/bpy_operator.c +++ b/source/blender/python/intern/bpy_operator.c @@ -66,18 +66,18 @@ static PyObject *pyop_poll(PyObject *UNUSED(self), PyObject *args) { wmOperatorType *ot; char *opname; - PyObject *context_dict= NULL; /* optional args */ + PyObject *context_dict = NULL; /* optional args */ PyObject *context_dict_back; - char *context_str= NULL; + char *context_str = NULL; PyObject *ret; - int context= WM_OP_EXEC_DEFAULT; + int context = WM_OP_EXEC_DEFAULT; /* XXX Todo, work out a better solution for passing on context, * could make a tuple from self and pack the name and Context into it... */ - bContext *C= (bContext *)BPy_GetContext(); + bContext *C = (bContext *)BPy_GetContext(); - if (C==NULL) { + if (C == NULL) { PyErr_SetString(PyExc_RuntimeError, "Context is None, cant poll any operators"); return NULL; } @@ -85,7 +85,7 @@ static PyObject *pyop_poll(PyObject *UNUSED(self), PyObject *args) if (!PyArg_ParseTuple(args, "s|Os:_bpy.ops.poll", &opname, &context_dict, &context_str)) return NULL; - ot= WM_operatortype_find(opname, TRUE); + ot = WM_operatortype_find(opname, TRUE); if (ot == NULL) { PyErr_Format(PyExc_AttributeError, @@ -95,8 +95,8 @@ static PyObject *pyop_poll(PyObject *UNUSED(self), PyObject *args) } if (context_str) { - if (RNA_enum_value_from_id(operator_context_items, context_str, &context)==0) { - char *enum_str= BPy_enum_as_string(operator_context_items); + if (RNA_enum_value_from_id(operator_context_items, context_str, &context) == 0) { + char *enum_str = BPy_enum_as_string(operator_context_items); PyErr_Format(PyExc_TypeError, "Calling operator \"bpy.ops.%s.poll\" error, " "expected a string enum in (%.200s)", @@ -106,8 +106,8 @@ static PyObject *pyop_poll(PyObject *UNUSED(self), PyObject *args) } } - if (context_dict==NULL || context_dict==Py_None) { - context_dict= NULL; + if (context_dict == NULL || context_dict == Py_None) { + context_dict = NULL; } else if (!PyDict_Check(context_dict)) { PyErr_Format(PyExc_TypeError, @@ -117,12 +117,12 @@ static PyObject *pyop_poll(PyObject *UNUSED(self), PyObject *args) return NULL; } - context_dict_back= CTX_py_dict_get(C); + context_dict_back = CTX_py_dict_get(C); CTX_py_dict_set(C, (void *)context_dict); Py_XINCREF(context_dict); /* so we done loose it */ /* main purpose of thsi function */ - ret= WM_operator_poll_context((bContext*)C, ot, context) ? Py_True : Py_False; + ret = WM_operator_poll_context((bContext *)C, ot, context) ? Py_True : Py_False; /* restore with original context dict, probably NULL but need this for nested operator calls */ Py_XDECREF(context_dict); @@ -135,24 +135,24 @@ static PyObject *pyop_poll(PyObject *UNUSED(self), PyObject *args) static PyObject *pyop_call(PyObject *UNUSED(self), PyObject *args) { wmOperatorType *ot; - int error_val= 0; + int error_val = 0; PointerRNA ptr; - int operator_ret= OPERATOR_CANCELLED; + int operator_ret = OPERATOR_CANCELLED; char *opname; - char *context_str= NULL; - PyObject *kw= NULL; /* optional args */ - PyObject *context_dict= NULL; /* optional args */ + char *context_str = NULL; + PyObject *kw = NULL; /* optional args */ + PyObject *context_dict = NULL; /* optional args */ PyObject *context_dict_back; /* note that context is an int, python does the conversion in this case */ - int context= WM_OP_EXEC_DEFAULT; + int context = WM_OP_EXEC_DEFAULT; /* XXX Todo, work out a better solution for passing on context, * could make a tuple from self and pack the name and Context into it... */ - bContext *C= (bContext *)BPy_GetContext(); + bContext *C = (bContext *)BPy_GetContext(); - if (C==NULL) { + if (C == NULL) { PyErr_SetString(PyExc_RuntimeError, "Context is None, cant poll any operators"); return NULL; } @@ -160,7 +160,7 @@ static PyObject *pyop_call(PyObject *UNUSED(self), PyObject *args) if (!PyArg_ParseTuple(args, "sO|O!s:_bpy.ops.call", &opname, &context_dict, &PyDict_Type, &kw, &context_str)) return NULL; - ot= WM_operatortype_find(opname, TRUE); + ot = WM_operatortype_find(opname, TRUE); if (ot == NULL) { PyErr_Format(PyExc_AttributeError, @@ -178,8 +178,8 @@ static PyObject *pyop_call(PyObject *UNUSED(self), PyObject *args) } if (context_str) { - if (RNA_enum_value_from_id(operator_context_items, context_str, &context)==0) { - char *enum_str= BPy_enum_as_string(operator_context_items); + if (RNA_enum_value_from_id(operator_context_items, context_str, &context) == 0) { + char *enum_str = BPy_enum_as_string(operator_context_items); PyErr_Format(PyExc_TypeError, "Calling operator \"bpy.ops.%s\" error, " "expected a string enum in (%.200s)", @@ -189,8 +189,8 @@ static PyObject *pyop_call(PyObject *UNUSED(self), PyObject *args) } } - if (context_dict==NULL || context_dict==Py_None) { - context_dict= NULL; + if (context_dict == NULL || context_dict == Py_None) { + context_dict = NULL; } else if (!PyDict_Check(context_dict)) { PyErr_Format(PyExc_TypeError, @@ -200,31 +200,31 @@ static PyObject *pyop_call(PyObject *UNUSED(self), PyObject *args) return NULL; } - context_dict_back= CTX_py_dict_get(C); + context_dict_back = CTX_py_dict_get(C); CTX_py_dict_set(C, (void *)context_dict); Py_XINCREF(context_dict); /* so we done loose it */ - if (WM_operator_poll_context((bContext*)C, ot, context) == FALSE) { - const char *msg= CTX_wm_operator_poll_msg_get(C); + if (WM_operator_poll_context((bContext *)C, ot, context) == FALSE) { + const char *msg = CTX_wm_operator_poll_msg_get(C); PyErr_Format(PyExc_RuntimeError, "Operator bpy.ops.%.200s.poll() %.200s", opname, msg ? msg : "failed, context is incorrect"); CTX_wm_operator_poll_msg_set(C, NULL); /* better set to NULL else it could be used again */ - error_val= -1; + error_val = -1; } else { WM_operator_properties_create_ptr(&ptr, ot); WM_operator_properties_sanitize(&ptr, 0); if (kw && PyDict_Size(kw)) - error_val= pyrna_pydict_to_props(&ptr, kw, 0, "Converting py args to operator properties: "); + error_val = pyrna_pydict_to_props(&ptr, kw, 0, "Converting py args to operator properties: "); - if (error_val==0) { + if (error_val == 0) { ReportList *reports; - reports= MEM_mallocN(sizeof(ReportList), "wmOperatorReportList"); + reports = MEM_mallocN(sizeof(ReportList), "wmOperatorReportList"); BKE_reports_init(reports, RPT_STORE | RPT_OP_HOLD); /* own so these dont move into global reports */ #ifdef BPY_RELEASE_GIL @@ -233,10 +233,10 @@ static PyObject *pyop_call(PyObject *UNUSED(self), PyObject *args) /* note: I havve not seen any examples of code that does this * so it may not be officially supported but seems to work ok. */ { - PyThreadState *ts= PyEval_SaveThread(); + PyThreadState *ts = PyEval_SaveThread(); #endif - operator_ret= WM_operator_call_py(C, ot, context, &ptr, reports); + operator_ret = WM_operator_call_py(C, ot, context, &ptr, reports); #ifdef BPY_RELEASE_GIL /* regain GIL */ @@ -244,11 +244,11 @@ static PyObject *pyop_call(PyObject *UNUSED(self), PyObject *args) } #endif - error_val= BPy_reports_to_error(reports, PyExc_RuntimeError, FALSE); + error_val = BPy_reports_to_error(reports, PyExc_RuntimeError, FALSE); /* operator output is nice to have in the terminal/console too */ if (reports->list.first) { - char *report_str= BKE_reports_string(reports, 0); /* all reports */ + char *report_str = BKE_reports_string(reports, 0); /* all reports */ if (report_str) { PySys_WriteStdout("%s\n", report_str); @@ -285,7 +285,7 @@ static PyObject *pyop_call(PyObject *UNUSED(self), PyObject *args) Py_XDECREF(context_dict); CTX_py_dict_set(C, (void *)context_dict_back); - if (error_val==-1) { + if (error_val == -1) { return NULL; } @@ -308,16 +308,16 @@ static PyObject *pyop_as_string(PyObject *UNUSED(self), PyObject *args) PointerRNA ptr; char *opname; - PyObject *kw= NULL; /* optional args */ - int all_args= 1; - int error_val= 0; + PyObject *kw = NULL; /* optional args */ + int all_args = 1; + int error_val = 0; - char *buf= NULL; + char *buf = NULL; PyObject *pybuf; - bContext *C= (bContext *)BPy_GetContext(); + bContext *C = (bContext *)BPy_GetContext(); - if (C==NULL) { + if (C == NULL) { PyErr_SetString(PyExc_RuntimeError, "Context is None, cant get the string representation of this object."); return NULL; } @@ -325,7 +325,7 @@ static PyObject *pyop_as_string(PyObject *UNUSED(self), PyObject *args) if (!PyArg_ParseTuple(args, "s|O!i:_bpy.ops.as_string", &opname, &PyDict_Type, &kw, &all_args)) return NULL; - ot= WM_operatortype_find(opname, TRUE); + ot = WM_operatortype_find(opname, TRUE); if (ot == NULL) { PyErr_Format(PyExc_AttributeError, @@ -339,23 +339,23 @@ static PyObject *pyop_as_string(PyObject *UNUSED(self), PyObject *args) RNA_pointer_create(NULL, ot->srna, NULL, &ptr); if (kw && PyDict_Size(kw)) - error_val= pyrna_pydict_to_props(&ptr, kw, 0, "Converting py args to operator properties: "); + error_val = pyrna_pydict_to_props(&ptr, kw, 0, "Converting py args to operator properties: "); - if (error_val==0) - buf= WM_operator_pystring(C, ot, &ptr, all_args); + if (error_val == 0) + buf = WM_operator_pystring(C, ot, &ptr, all_args); WM_operator_properties_free(&ptr); - if (error_val==-1) { + if (error_val == -1) { return NULL; } if (buf) { - pybuf= PyUnicode_FromString(buf); + pybuf = PyUnicode_FromString(buf); MEM_freeN(buf); } else { - pybuf= PyUnicode_FromString(""); + pybuf = PyUnicode_FromString(""); } return pybuf; @@ -363,13 +363,13 @@ static PyObject *pyop_as_string(PyObject *UNUSED(self), PyObject *args) static PyObject *pyop_dir(PyObject *UNUSED(self)) { - GHashIterator *iter= WM_operatortype_iter(); - PyObject *list= PyList_New(0), *name; + GHashIterator *iter = WM_operatortype_iter(); + PyObject *list = PyList_New(0), *name; for ( ; !BLI_ghashIterator_isDone(iter); BLI_ghashIterator_step(iter)) { - wmOperatorType *ot= BLI_ghashIterator_getValue(iter); + wmOperatorType *ot = BLI_ghashIterator_getValue(iter); - name= PyUnicode_FromString(ot->idname); + name = PyUnicode_FromString(ot->idname); PyList_Append(list, name); Py_DECREF(name); } @@ -382,15 +382,15 @@ static PyObject *pyop_getrna(PyObject *UNUSED(self), PyObject *value) { wmOperatorType *ot; PointerRNA ptr; - const char *opname= _PyUnicode_AsString(value); - BPy_StructRNA *pyrna= NULL; + const char *opname = _PyUnicode_AsString(value); + BPy_StructRNA *pyrna = NULL; - if (opname==NULL) { + if (opname == NULL) { PyErr_SetString(PyExc_TypeError, "_bpy.ops.get_rna() expects a string argument"); return NULL; } - ot= WM_operatortype_find(opname, TRUE); - if (ot==NULL) { + ot = WM_operatortype_find(opname, TRUE); + if (ot == NULL) { PyErr_Format(PyExc_KeyError, "_bpy.ops.get_rna(\"%s\") not found", opname); return NULL; } @@ -403,9 +403,9 @@ static PyObject *pyop_getrna(PyObject *UNUSED(self), PyObject *value) WM_operator_properties_sanitize(&ptr, 0); - pyrna= (BPy_StructRNA *)pyrna_struct_CreatePyObject(&ptr); + pyrna = (BPy_StructRNA *)pyrna_struct_CreatePyObject(&ptr); #ifdef PYRNA_FREE_SUPPORT - pyrna->freeptr= TRUE; + pyrna->freeptr = TRUE; #endif return (PyObject *)pyrna; } @@ -415,40 +415,40 @@ static PyObject *pyop_getinstance(PyObject *UNUSED(self), PyObject *value) wmOperatorType *ot; wmOperator *op; PointerRNA ptr; - const char *opname= _PyUnicode_AsString(value); - BPy_StructRNA *pyrna= NULL; + const char *opname = _PyUnicode_AsString(value); + BPy_StructRNA *pyrna = NULL; - if (opname==NULL) { + if (opname == NULL) { PyErr_SetString(PyExc_TypeError, "_bpy.ops.get_instance() expects a string argument"); return NULL; } - ot= WM_operatortype_find(opname, TRUE); - if (ot==NULL) { + ot = WM_operatortype_find(opname, TRUE); + if (ot == NULL) { PyErr_Format(PyExc_KeyError, "_bpy.ops.get_instance(\"%s\") not found", opname); return NULL; } #ifdef PYRNA_FREE_SUPPORT - op= MEM_callocN(sizeof(wmOperator), __func__); + op = MEM_callocN(sizeof(wmOperator), __func__); #else - op= PyMem_MALLOC(sizeof(wmOperator)); + op = PyMem_MALLOC(sizeof(wmOperator)); memset(op, 0, sizeof(wmOperator)); #endif BLI_strncpy(op->idname, op->idname, sizeof(op->idname)); /* incase its needed */ - op->type= ot; + op->type = ot; RNA_pointer_create(NULL, &RNA_Operator, op, &ptr); - pyrna= (BPy_StructRNA *)pyrna_struct_CreatePyObject(&ptr); + pyrna = (BPy_StructRNA *)pyrna_struct_CreatePyObject(&ptr); #ifdef PYRNA_FREE_SUPPORT - pyrna->freeptr= TRUE; + pyrna->freeptr = TRUE; #endif - op->ptr= &pyrna->ptr; + op->ptr = &pyrna->ptr; return (PyObject *)pyrna; } -static struct PyMethodDef bpy_ops_methods[]= { +static struct PyMethodDef bpy_ops_methods[] = { {"poll", (PyCFunction) pyop_poll, METH_VARARGS, NULL}, {"call", (PyCFunction) pyop_call, METH_VARARGS, NULL}, {"as_string", (PyCFunction) pyop_as_string, METH_VARARGS, NULL}, @@ -459,7 +459,7 @@ static struct PyMethodDef bpy_ops_methods[]= { {NULL, NULL, 0, NULL} }; -static struct PyModuleDef bpy_ops_module= { +static struct PyModuleDef bpy_ops_module = { PyModuleDef_HEAD_INIT, "_bpy.ops", NULL, @@ -472,7 +472,7 @@ PyObject *BPY_operator_module(void) { PyObject *submodule; - submodule= PyModule_Create(&bpy_ops_module); + submodule = PyModule_Create(&bpy_ops_module); return submodule; } diff --git a/source/blender/python/intern/bpy_operator_wrap.c b/source/blender/python/intern/bpy_operator_wrap.c index aa458925202..7860762059c 100644 --- a/source/blender/python/intern/bpy_operator_wrap.c +++ b/source/blender/python/intern/bpy_operator_wrap.c @@ -45,7 +45,7 @@ static void operator_properties_init(wmOperatorType *ot) { - PyObject *py_class= ot->ext.data; + PyObject *py_class = ot->ext.data; RNA_struct_blender_type_set(ot->ext.srna, ot); /* only call this so pyrna_deferred_register_class gives a useful error @@ -63,9 +63,9 @@ void operator_wrapper(wmOperatorType *ot, void *userdata) { /* take care not to overwrite anything set in * WM_operatortype_append_ptr before opfunc() is called */ - StructRNA *srna= ot->srna; - *ot= *((wmOperatorType *)userdata); - ot->srna= srna; /* restore */ + StructRNA *srna = ot->srna; + *ot = *((wmOperatorType *)userdata); + ot->srna = srna; /* restore */ operator_properties_init(ot); @@ -74,25 +74,25 @@ void operator_wrapper(wmOperatorType *ot, void *userdata) PropertyRNA *prop; RNA_pointer_create(NULL, ot->srna, NULL, &ptr); - prop= RNA_struct_find_property(&ptr, "type"); + prop = RNA_struct_find_property(&ptr, "type"); if (prop) { - ot->prop= prop; + ot->prop = prop; } } } void macro_wrapper(wmOperatorType *ot, void *userdata) { - wmOperatorType *data= (wmOperatorType *)userdata; + wmOperatorType *data = (wmOperatorType *)userdata; /* only copy a couple of things, the rest is set by the macro registration */ - ot->name= data->name; - ot->idname= data->idname; - ot->description= data->description; + ot->name = data->name; + ot->idname = data->idname; + ot->description = data->description; ot->flag |= data->flag; /* append flags to the one set by registration */ - ot->pyop_poll= data->pyop_poll; - ot->ui= data->ui; - ot->ext= data->ext; + ot->pyop_poll = data->pyop_poll; + ot->ui = data->ui; + ot->ext = data->ext; operator_properties_init(ot); } @@ -117,17 +117,17 @@ PyObject *PYOP_wrap_macro_define(PyObject *UNUSED(self), PyObject *args) } /* identifiers */ - srna= srna_from_self(macro, "Macro Define:"); - macroname= RNA_struct_identifier(srna); + srna = srna_from_self(macro, "Macro Define:"); + macroname = RNA_struct_identifier(srna); - ot= WM_operatortype_find(macroname, TRUE); + ot = WM_operatortype_find(macroname, TRUE); if (!ot) { PyErr_Format(PyExc_ValueError, "Macro Define: '%s' is not a valid macro or hasn't been registered yet", macroname); return NULL; } - otmacro= WM_operatortype_macro_define(ot, opname); + otmacro = WM_operatortype_macro_define(ot, opname); RNA_pointer_create(NULL, &RNA_OperatorMacro, otmacro, &ptr_otmacro); diff --git a/source/blender/python/intern/bpy_props.c b/source/blender/python/intern/bpy_props.c index d1408015089..9984e7f2fe0 100644 --- a/source/blender/python/intern/bpy_props.c +++ b/source/blender/python/intern/bpy_props.c @@ -56,13 +56,13 @@ extern BPy_StructRNA *bpy_context_module; -static EnumPropertyItem property_flag_items[]= { +static EnumPropertyItem property_flag_items[] = { {PROP_HIDDEN, "HIDDEN", 0, "Hidden", ""}, {PROP_SKIP_SAVE, "SKIP_SAVE", 0, "Skip Save", ""}, {PROP_ANIMATABLE, "ANIMATABLE", 0, "Animateable", ""}, {0, NULL, 0, NULL, NULL}}; -static EnumPropertyItem property_flag_enum_items[]= { +static EnumPropertyItem property_flag_enum_items[] = { {PROP_HIDDEN, "HIDDEN", 0, "Hidden", ""}, {PROP_SKIP_SAVE, "SKIP_SAVE", 0, "Skip Save", ""}, {PROP_ANIMATABLE, "ANIMATABLE", 0, "Animateable", ""}, @@ -70,7 +70,7 @@ static EnumPropertyItem property_flag_enum_items[]= { {0, NULL, 0, NULL, NULL}}; /* subtypes */ -static EnumPropertyItem property_subtype_string_items[]= { +static EnumPropertyItem property_subtype_string_items[] = { {PROP_FILEPATH, "FILE_PATH", 0, "File Path", ""}, {PROP_DIRPATH, "DIR_PATH", 0, "Directory Path", ""}, {PROP_FILENAME, "FILENAME", 0, "Filename", ""}, @@ -80,7 +80,7 @@ static EnumPropertyItem property_subtype_string_items[]= { {PROP_NONE, "NONE", 0, "None", ""}, {0, NULL, 0, NULL, NULL}}; -static EnumPropertyItem property_subtype_number_items[]= { +static EnumPropertyItem property_subtype_number_items[] = { {PROP_UNSIGNED, "UNSIGNED", 0, "Unsigned", ""}, {PROP_PERCENTAGE, "PERCENTAGE", 0, "Percentage", ""}, {PROP_FACTOR, "FACTOR", 0, "Factor", ""}, @@ -91,7 +91,7 @@ static EnumPropertyItem property_subtype_number_items[]= { {PROP_NONE, "NONE", 0, "None", ""}, {0, NULL, 0, NULL, NULL}}; -static EnumPropertyItem property_subtype_array_items[]= { +static EnumPropertyItem property_subtype_array_items[] = { {PROP_COLOR, "COLOR", 0, "Color", ""}, {PROP_TRANSLATION, "TRANSLATION", 0, "Translation", ""}, {PROP_DIRECTION, "DIRECTION", 0, "Direction", ""}, @@ -109,29 +109,29 @@ static EnumPropertyItem property_subtype_array_items[]= { {0, NULL, 0, NULL, NULL}}; /* PyObject's */ -static PyObject *pymeth_BoolProperty= NULL; -static PyObject *pymeth_BoolVectorProperty= NULL; -static PyObject *pymeth_IntProperty= NULL; -static PyObject *pymeth_IntVectorProperty= NULL; -static PyObject *pymeth_FloatProperty= NULL; -static PyObject *pymeth_FloatVectorProperty= NULL; -static PyObject *pymeth_StringProperty= NULL; -static PyObject *pymeth_EnumProperty= NULL; -static PyObject *pymeth_PointerProperty= NULL; -static PyObject *pymeth_CollectionProperty= NULL; -static PyObject *pymeth_RemoveProperty= NULL; +static PyObject *pymeth_BoolProperty = NULL; +static PyObject *pymeth_BoolVectorProperty = NULL; +static PyObject *pymeth_IntProperty = NULL; +static PyObject *pymeth_IntVectorProperty = NULL; +static PyObject *pymeth_FloatProperty = NULL; +static PyObject *pymeth_FloatVectorProperty = NULL; +static PyObject *pymeth_StringProperty = NULL; +static PyObject *pymeth_EnumProperty = NULL; +static PyObject *pymeth_PointerProperty = NULL; +static PyObject *pymeth_CollectionProperty = NULL; +static PyObject *pymeth_RemoveProperty = NULL; static PyObject *pyrna_struct_as_instance(PointerRNA *ptr) { - PyObject *self= NULL; + PyObject *self = NULL; /* first get self */ /* operators can store their own instance for later use */ if (ptr->data) { - void **instance= RNA_struct_instance(ptr); + void **instance = RNA_struct_instance(ptr); if (instance) { if (*instance) { - self= *instance; + self = *instance; Py_INCREF(self); } } @@ -139,7 +139,7 @@ static PyObject *pyrna_struct_as_instance(PointerRNA *ptr) /* in most cases this will run */ if (self == NULL) { - self= pyrna_struct_CreatePyObject(ptr); + self = pyrna_struct_CreatePyObject(ptr); } return self; @@ -149,7 +149,7 @@ static PyObject *pyrna_struct_as_instance(PointerRNA *ptr) static void printf_func_error(PyObject *py_func) { /* since we return to C code we can't leave the error */ - PyCodeObject *f_code= (PyCodeObject *)PyFunction_GET_CODE(py_func); + PyCodeObject *f_code = (PyCodeObject *)PyFunction_GET_CODE(py_func); PyErr_Print(); PyErr_Clear(); @@ -166,12 +166,12 @@ static void printf_func_error(PyObject *py_func) * the default args for that operator instance */ static PyObject *bpy_prop_deferred_return(PyObject *func, PyObject *kw) { - PyObject *ret= PyTuple_New(2); + PyObject *ret = PyTuple_New(2); PyTuple_SET_ITEM(ret, 0, func); Py_INCREF(func); - if (kw==NULL) - kw= PyDict_New(); + if (kw == NULL) + kw = PyDict_New(); else Py_INCREF(kw); @@ -184,12 +184,12 @@ static PyObject *bpy_prop_deferred_return(PyObject *func, PyObject *kw) static void bpy_prop_update_cb(struct bContext *C, struct PointerRNA *ptr, struct PropertyRNA *prop) { PyGILState_STATE gilstate; - PyObject **py_data= (PyObject **)RNA_property_py_data_get(prop); + PyObject **py_data = (PyObject **)RNA_property_py_data_get(prop); PyObject *py_func; PyObject *args; PyObject *self; PyObject *ret; - const int is_write_ok= pyrna_write_check(); + const int is_write_ok = pyrna_write_check(); BLI_assert(py_data != NULL); @@ -199,16 +199,16 @@ static void bpy_prop_update_cb(struct bContext *C, struct PointerRNA *ptr, struc bpy_context_set(C, &gilstate); - py_func= py_data[BPY_DATA_CB_SLOT_UPDATE]; + py_func = py_data[BPY_DATA_CB_SLOT_UPDATE]; - args= PyTuple_New(2); - self= pyrna_struct_as_instance(ptr); + args = PyTuple_New(2); + self = pyrna_struct_as_instance(ptr); PyTuple_SET_ITEM(args, 0, self); PyTuple_SET_ITEM(args, 1, (PyObject *)bpy_context_module); Py_INCREF(bpy_context_module); - ret= PyObject_CallObject(py_func, args); + ret = PyObject_CallObject(py_func, args); Py_DECREF(args); @@ -241,7 +241,7 @@ static int bpy_prop_callback_check(PyObject *py_func, int argcount) return -1; } else { - PyCodeObject *f_code= (PyCodeObject *)PyFunction_GET_CODE(py_func); + PyCodeObject *f_code = (PyCodeObject *)PyFunction_GET_CODE(py_func); if (f_code->co_argcount != argcount) { PyErr_Format(PyExc_TypeError, "update keyword: expected a function taking %d arguments, not %d", @@ -259,9 +259,9 @@ static int bpy_prop_callback_assign(struct PropertyRNA *prop, PyObject *update_c { /* assume this is already checked for type and arg length */ if (update_cb) { - PyObject **py_data= MEM_callocN(sizeof(PyObject *) * BPY_DATA_CB_SLOT_SIZE, __func__); + PyObject **py_data = MEM_callocN(sizeof(PyObject *) * BPY_DATA_CB_SLOT_SIZE, __func__); RNA_def_property_update_runtime(prop, (void *)bpy_prop_update_cb); - py_data[BPY_DATA_CB_SLOT_UPDATE]= update_cb; + py_data[BPY_DATA_CB_SLOT_UPDATE] = update_cb; RNA_def_py_data(prop, py_data); RNA_def_property_flag(prop, PROP_CONTEXT_PROPERTY_UPDATE); @@ -274,7 +274,7 @@ static int bpy_prop_callback_assign(struct PropertyRNA *prop, PyObject *update_c static int py_long_as_int(PyObject *py_long, int *r_int) { if (PyLong_CheckExact(py_long)) { - *r_int= (int)PyLong_AS_LONG(py_long); + *r_int = (int)PyLong_AS_LONG(py_long); return 0; } else { @@ -287,9 +287,9 @@ static int py_long_as_int(PyObject *py_long, int *r_int) #define BPY_PROPDEF_HEAD(_func) \ if (PyTuple_GET_SIZE(args) == 1) { \ PyObject *ret; \ - self= PyTuple_GET_ITEM(args, 0); \ - args= PyTuple_New(0); \ - ret= BPy_##_func(self, args, kw); \ + self = PyTuple_GET_ITEM(args, 0); \ + args = PyTuple_New(0); \ + ret = BPy_##_func(self, args, kw); \ Py_DECREF(args); \ return ret; \ } \ @@ -297,8 +297,8 @@ static int py_long_as_int(PyObject *py_long, int *r_int) PyErr_SetString(PyExc_ValueError, "all args must be keywords"); \ return NULL; \ } \ - srna= srna_from_self(self, #_func"(...):"); \ - if (srna==NULL) { \ + srna = srna_from_self(self, #_func"(...):"); \ + if (srna == NULL) { \ if (PyErr_Occurred()) \ return NULL; \ return bpy_prop_deferred_return(pymeth_##_func, kw); \ @@ -310,7 +310,7 @@ static int py_long_as_int(PyObject *py_long, int *r_int) if (id_len >= MAX_IDPROP_NAME) { \ PyErr_Format(PyExc_TypeError, \ #_func"(): '%.200s' too long, max length is %d", \ - id, MAX_IDPROP_NAME-1); \ + id, MAX_IDPROP_NAME - 1); \ return NULL; \ } \ if (RNA_def_property_free_identifier(srna, id) == -1) { \ @@ -322,7 +322,7 @@ static int py_long_as_int(PyObject *py_long, int *r_int) if (pyopts && pyrna_set_to_enum_bitfield(_property_flag_items, \ pyopts, \ &opts, \ - #_func"(options={...}):")) \ + #_func"(options={ ...}):")) \ { \ return NULL; \ } \ @@ -331,7 +331,7 @@ static int py_long_as_int(PyObject *py_long, int *r_int) BPY_PROPDEF_CHECK(_func, _property_flag_items) \ if (pysubtype && RNA_enum_value_from_id(_subtype, \ pysubtype, \ - &subtype)==0) \ + &subtype) == 0) \ { \ PyErr_Format(PyExc_TypeError, \ #_func"(subtype='%s'): invalid subtype", \ @@ -393,17 +393,17 @@ static PyObject *BPy_BoolProperty(PyObject *self, PyObject *args, PyObject *kw) BPY_PROPDEF_HEAD(BoolProperty) if (srna) { - static const char *kwlist[]= {"attr", "name", "description", "default", + static const char *kwlist[] = {"attr", "name", "description", "default", "options", "subtype", "update", NULL}; - const char *id=NULL, *name="", *description=""; + const char *id = NULL, *name = "", *description = ""; int id_len; - int def=0; + int def = 0; PropertyRNA *prop; - PyObject *pyopts= NULL; - int opts=0; - char *pysubtype= NULL; - int subtype= PROP_NONE; - PyObject *update_cb= NULL; + PyObject *pyopts = NULL; + int opts = 0; + char *pysubtype = NULL; + int subtype = PROP_NONE; + PyObject *update_cb = NULL; if (!PyArg_ParseTupleAndKeywords(args, kw, "s#|ssiO!sO:BoolProperty", @@ -421,13 +421,13 @@ static PyObject *BPy_BoolProperty(PyObject *self, PyObject *args, PyObject *kw) return NULL; } - prop= RNA_def_property(srna, id, PROP_BOOLEAN, subtype); + prop = RNA_def_property(srna, id, PROP_BOOLEAN, subtype); RNA_def_property_boolean_default(prop, def); RNA_def_property_ui_text(prop, name, description); if (pyopts) { if (opts & PROP_HIDDEN) RNA_def_property_flag(prop, PROP_HIDDEN); - if ((opts & PROP_ANIMATABLE)==0) RNA_def_property_clear_flag(prop, PROP_ANIMATABLE); + if ((opts & PROP_ANIMATABLE) == 0) RNA_def_property_clear_flag(prop, PROP_ANIMATABLE); if (opts & PROP_SKIP_SAVE) RNA_def_property_flag(prop, PROP_SKIP_SAVE); } bpy_prop_callback_assign(prop, update_cb); @@ -461,19 +461,19 @@ static PyObject *BPy_BoolVectorProperty(PyObject *self, PyObject *args, PyObject BPY_PROPDEF_HEAD(BoolVectorProperty) if (srna) { - static const char *kwlist[]= {"attr", "name", "description", "default", + static const char *kwlist[] = {"attr", "name", "description", "default", "options", "subtype", "size", "update", NULL}; - const char *id=NULL, *name="", *description=""; + const char *id = NULL, *name = "", *description = ""; int id_len; - int def[PYRNA_STACK_ARRAY]={0}; - int size=3; + int def[PYRNA_STACK_ARRAY] = {0}; + int size = 3; PropertyRNA *prop; - PyObject *pydef= NULL; - PyObject *pyopts= NULL; - int opts=0; - char *pysubtype= NULL; - int subtype= PROP_NONE; - PyObject *update_cb= NULL; + PyObject *pydef = NULL; + PyObject *pyopts = NULL; + int opts = 0; + char *pysubtype = NULL; + int subtype = PROP_NONE; + PyObject *update_cb = NULL; if (!PyArg_ParseTupleAndKeywords(args, kw, "s#|ssOO!siO:BoolVectorProperty", @@ -501,15 +501,15 @@ static PyObject *BPy_BoolVectorProperty(PyObject *self, PyObject *args, PyObject return NULL; } - // prop= RNA_def_boolean_array(srna, id, size, pydef ? def:NULL, name, description); - prop= RNA_def_property(srna, id, PROP_BOOLEAN, subtype); + // prop = RNA_def_boolean_array(srna, id, size, pydef ? def:NULL, name, description); + prop = RNA_def_property(srna, id, PROP_BOOLEAN, subtype); RNA_def_property_array(prop, size); if (pydef) RNA_def_property_boolean_array_default(prop, def); RNA_def_property_ui_text(prop, name, description); if (pyopts) { if (opts & PROP_HIDDEN) RNA_def_property_flag(prop, PROP_HIDDEN); - if ((opts & PROP_ANIMATABLE)==0) RNA_def_property_clear_flag(prop, PROP_ANIMATABLE); + if ((opts & PROP_ANIMATABLE) == 0) RNA_def_property_clear_flag(prop, PROP_ANIMATABLE); if (opts & PROP_SKIP_SAVE) RNA_def_property_flag(prop, PROP_SKIP_SAVE); } bpy_prop_callback_assign(prop, update_cb); @@ -539,17 +539,17 @@ static PyObject *BPy_IntProperty(PyObject *self, PyObject *args, PyObject *kw) BPY_PROPDEF_HEAD(IntProperty) if (srna) { - static const char *kwlist[]= {"attr", "name", "description", "default", + static const char *kwlist[] = {"attr", "name", "description", "default", "min", "max", "soft_min", "soft_max", "step", "options", "subtype", "update", NULL}; - const char *id=NULL, *name="", *description=""; + const char *id = NULL, *name = "", *description = ""; int id_len; - int min=INT_MIN, max=INT_MAX, soft_min=INT_MIN, soft_max=INT_MAX, step=1, def=0; + int min = INT_MIN, max = INT_MAX, soft_min = INT_MIN, soft_max = INT_MAX, step = 1, def = 0; PropertyRNA *prop; - PyObject *pyopts= NULL; - int opts=0; - char *pysubtype= NULL; - int subtype= PROP_NONE; - PyObject *update_cb= NULL; + PyObject *pyopts = NULL; + int opts = 0; + char *pysubtype = NULL; + int subtype = PROP_NONE; + PyObject *update_cb = NULL; if (!PyArg_ParseTupleAndKeywords(args, kw, "s#|ssiiiiiiO!sO:IntProperty", @@ -568,7 +568,7 @@ static PyObject *BPy_IntProperty(PyObject *self, PyObject *args, PyObject *kw) return NULL; } - prop= RNA_def_property(srna, id, PROP_INT, subtype); + prop = RNA_def_property(srna, id, PROP_INT, subtype); RNA_def_property_int_default(prop, def); RNA_def_property_range(prop, min, max); RNA_def_property_ui_text(prop, name, description); @@ -576,7 +576,7 @@ static PyObject *BPy_IntProperty(PyObject *self, PyObject *args, PyObject *kw) if (pyopts) { if (opts & PROP_HIDDEN) RNA_def_property_flag(prop, PROP_HIDDEN); - if ((opts & PROP_ANIMATABLE)==0) RNA_def_property_clear_flag(prop, PROP_ANIMATABLE); + if ((opts & PROP_ANIMATABLE) == 0) RNA_def_property_clear_flag(prop, PROP_ANIMATABLE); if (opts & PROP_SKIP_SAVE) RNA_def_property_flag(prop, PROP_SKIP_SAVE); } bpy_prop_callback_assign(prop, update_cb); @@ -609,20 +609,21 @@ static PyObject *BPy_IntVectorProperty(PyObject *self, PyObject *args, PyObject BPY_PROPDEF_HEAD(IntVectorProperty) if (srna) { - static const char *kwlist[]= {"attr", "name", "description", "default", + static const char *kwlist[] = {"attr", "name", "description", "default", "min", "max", "soft_min", "soft_max", "step", "options", "subtype", "size", "update", NULL}; - const char *id=NULL, *name="", *description=""; + const char *id = NULL, *name = "", *description = ""; int id_len; - int min=INT_MIN, max=INT_MAX, soft_min=INT_MIN, soft_max=INT_MAX, step=1, def[PYRNA_STACK_ARRAY]={0}; - int size=3; + int min = INT_MIN, max = INT_MAX, soft_min = INT_MIN, soft_max = INT_MAX, step = 1; + int def[PYRNA_STACK_ARRAY] = {0}; + int size = 3; PropertyRNA *prop; - PyObject *pydef= NULL; - PyObject *pyopts= NULL; - int opts=0; - char *pysubtype= NULL; - int subtype= PROP_NONE; - PyObject *update_cb= NULL; + PyObject *pydef = NULL; + PyObject *pyopts = NULL; + int opts = 0; + char *pysubtype = NULL; + int subtype = PROP_NONE; + PyObject *update_cb = NULL; if (!PyArg_ParseTupleAndKeywords(args, kw, "s#|ssOiiiiiO!siO:IntVectorProperty", @@ -652,7 +653,7 @@ static PyObject *BPy_IntVectorProperty(PyObject *self, PyObject *args, PyObject return NULL; } - prop= RNA_def_property(srna, id, PROP_INT, subtype); + prop = RNA_def_property(srna, id, PROP_INT, subtype); RNA_def_property_array(prop, size); if (pydef) RNA_def_property_int_array_default(prop, def); RNA_def_property_range(prop, min, max); @@ -661,7 +662,7 @@ static PyObject *BPy_IntVectorProperty(PyObject *self, PyObject *args, PyObject if (pyopts) { if (opts & PROP_HIDDEN) RNA_def_property_flag(prop, PROP_HIDDEN); - if ((opts & PROP_ANIMATABLE)==0) RNA_def_property_clear_flag(prop, PROP_ANIMATABLE); + if ((opts & PROP_ANIMATABLE) == 0) RNA_def_property_clear_flag(prop, PROP_ANIMATABLE); if (opts & PROP_SKIP_SAVE) RNA_def_property_flag(prop, PROP_SKIP_SAVE); } bpy_prop_callback_assign(prop, update_cb); @@ -692,21 +693,21 @@ static PyObject *BPy_FloatProperty(PyObject *self, PyObject *args, PyObject *kw) BPY_PROPDEF_HEAD(FloatProperty) if (srna) { - static const char *kwlist[]= {"attr", "name", "description", "default", + static const char *kwlist[] = {"attr", "name", "description", "default", "min", "max", "soft_min", "soft_max", "step", "precision", "options", "subtype", "unit", "update", NULL}; - const char *id=NULL, *name="", *description=""; + const char *id = NULL, *name = "", *description = ""; int id_len; - float min=-FLT_MAX, max=FLT_MAX, soft_min=-FLT_MAX, soft_max=FLT_MAX, step=3, def=0.0f; - int precision= 2; + float min = -FLT_MAX, max = FLT_MAX, soft_min = -FLT_MAX, soft_max = FLT_MAX, step = 3, def = 0.0f; + int precision = 2; PropertyRNA *prop; - PyObject *pyopts= NULL; - int opts=0; - char *pysubtype= NULL; - int subtype= PROP_NONE; - char *pyunit= NULL; - int unit= PROP_UNIT_NONE; - PyObject *update_cb= NULL; + PyObject *pyopts = NULL; + int opts = 0; + char *pysubtype = NULL; + int subtype = PROP_NONE; + char *pyunit = NULL; + int unit = PROP_UNIT_NONE; + PyObject *update_cb = NULL; if (!PyArg_ParseTupleAndKeywords(args, kw, "s#|ssffffffiO!ssO:FloatProperty", @@ -722,7 +723,7 @@ static PyObject *BPy_FloatProperty(PyObject *self, PyObject *args, PyObject *kw) BPY_PROPDEF_SUBTYPE_CHECK(FloatProperty, property_flag_items, property_subtype_number_items) - if (pyunit && RNA_enum_value_from_id(property_unit_items, pyunit, &unit)==0) { + if (pyunit && RNA_enum_value_from_id(property_unit_items, pyunit, &unit) == 0) { PyErr_Format(PyExc_TypeError, "FloatProperty(unit='%s'): invalid unit", pyunit); return NULL; } @@ -731,7 +732,7 @@ static PyObject *BPy_FloatProperty(PyObject *self, PyObject *args, PyObject *kw) return NULL; } - prop= RNA_def_property(srna, id, PROP_FLOAT, subtype | unit); + prop = RNA_def_property(srna, id, PROP_FLOAT, subtype | unit); RNA_def_property_float_default(prop, def); RNA_def_property_range(prop, min, max); RNA_def_property_ui_text(prop, name, description); @@ -739,7 +740,7 @@ static PyObject *BPy_FloatProperty(PyObject *self, PyObject *args, PyObject *kw) if (pyopts) { if (opts & PROP_HIDDEN) RNA_def_property_flag(prop, PROP_HIDDEN); - if ((opts & PROP_ANIMATABLE)==0) RNA_def_property_clear_flag(prop, PROP_ANIMATABLE); + if ((opts & PROP_ANIMATABLE) == 0) RNA_def_property_clear_flag(prop, PROP_ANIMATABLE); if (opts & PROP_SKIP_SAVE) RNA_def_property_flag(prop, PROP_SKIP_SAVE); } bpy_prop_callback_assign(prop, update_cb); @@ -773,22 +774,22 @@ static PyObject *BPy_FloatVectorProperty(PyObject *self, PyObject *args, PyObjec BPY_PROPDEF_HEAD(FloatVectorProperty) if (srna) { - static const char *kwlist[]= {"attr", "name", "description", "default", + static const char *kwlist[] = {"attr", "name", "description", "default", "min", "max", "soft_min", "soft_max", "step", "precision", "options", "subtype", "unit", "size", "update", NULL}; - const char *id=NULL, *name="", *description=""; + const char *id = NULL, *name = "", *description = ""; int id_len; - float min=-FLT_MAX, max=FLT_MAX, soft_min=-FLT_MAX, soft_max=FLT_MAX, step=3, def[PYRNA_STACK_ARRAY]={0.0f}; - int precision= 2, size=3; + float min = -FLT_MAX, max = FLT_MAX, soft_min = -FLT_MAX, soft_max = FLT_MAX, step = 3, def[PYRNA_STACK_ARRAY] = {0.0f}; + int precision = 2, size = 3; PropertyRNA *prop; - PyObject *pydef= NULL; - PyObject *pyopts= NULL; - int opts=0; - char *pysubtype= NULL; - int subtype= PROP_NONE; - char *pyunit= NULL; - int unit= PROP_UNIT_NONE; - PyObject *update_cb= NULL; + PyObject *pydef = NULL; + PyObject *pyopts = NULL; + int opts = 0; + char *pysubtype = NULL; + int subtype = PROP_NONE; + char *pyunit = NULL; + int unit = PROP_UNIT_NONE; + PyObject *update_cb = NULL; if (!PyArg_ParseTupleAndKeywords(args, kw, "s#|ssOfffffiO!ssiO:FloatVectorProperty", @@ -804,7 +805,7 @@ static PyObject *BPy_FloatVectorProperty(PyObject *self, PyObject *args, PyObjec BPY_PROPDEF_SUBTYPE_CHECK(FloatVectorProperty, property_flag_items, property_subtype_array_items) - if (pyunit && RNA_enum_value_from_id(property_unit_items, pyunit, &unit)==0) { + if (pyunit && RNA_enum_value_from_id(property_unit_items, pyunit, &unit) == 0) { PyErr_Format(PyExc_TypeError, "FloatVectorProperty(unit='%s'): invalid unit", pyunit); return NULL; } @@ -823,7 +824,7 @@ static PyObject *BPy_FloatVectorProperty(PyObject *self, PyObject *args, PyObjec return NULL; } - prop= RNA_def_property(srna, id, PROP_FLOAT, subtype | unit); + prop = RNA_def_property(srna, id, PROP_FLOAT, subtype | unit); RNA_def_property_array(prop, size); if (pydef) RNA_def_property_float_array_default(prop, def); RNA_def_property_range(prop, min, max); @@ -832,7 +833,7 @@ static PyObject *BPy_FloatVectorProperty(PyObject *self, PyObject *args, PyObjec if (pyopts) { if (opts & PROP_HIDDEN) RNA_def_property_flag(prop, PROP_HIDDEN); - if ((opts & PROP_ANIMATABLE)==0) RNA_def_property_clear_flag(prop, PROP_ANIMATABLE); + if ((opts & PROP_ANIMATABLE) == 0) RNA_def_property_clear_flag(prop, PROP_ANIMATABLE); if (opts & PROP_SKIP_SAVE) RNA_def_property_flag(prop, PROP_SKIP_SAVE); } bpy_prop_callback_assign(prop, update_cb); @@ -861,17 +862,17 @@ static PyObject *BPy_StringProperty(PyObject *self, PyObject *args, PyObject *kw BPY_PROPDEF_HEAD(StringProperty) if (srna) { - static const char *kwlist[]= {"attr", "name", "description", "default", + static const char *kwlist[] = {"attr", "name", "description", "default", "maxlen", "options", "subtype", "update", NULL}; - const char *id=NULL, *name="", *description="", *def=""; + const char *id = NULL, *name = "", *description = "", *def = ""; int id_len; - int maxlen=0; + int maxlen = 0; PropertyRNA *prop; - PyObject *pyopts= NULL; - int opts=0; - char *pysubtype= NULL; - int subtype= PROP_NONE; - PyObject *update_cb= NULL; + PyObject *pyopts = NULL; + int opts = 0; + char *pysubtype = NULL; + int subtype = PROP_NONE; + PyObject *update_cb = NULL; if (!PyArg_ParseTupleAndKeywords(args, kw, "s#|sssiO!sO:StringProperty", @@ -889,14 +890,14 @@ static PyObject *BPy_StringProperty(PyObject *self, PyObject *args, PyObject *kw return NULL; } - prop= RNA_def_property(srna, id, PROP_STRING, subtype); + prop = RNA_def_property(srna, id, PROP_STRING, subtype); if (maxlen != 0) RNA_def_property_string_maxlength(prop, maxlen + 1); /* +1 since it includes null terminator */ if (def) RNA_def_property_string_default(prop, def); RNA_def_property_ui_text(prop, name, description); if (pyopts) { if (opts & PROP_HIDDEN) RNA_def_property_flag(prop, PROP_HIDDEN); - if ((opts & PROP_ANIMATABLE)==0) RNA_def_property_clear_flag(prop, PROP_ANIMATABLE); + if ((opts & PROP_ANIMATABLE) == 0) RNA_def_property_clear_flag(prop, PROP_ANIMATABLE); if (opts & PROP_SKIP_SAVE) RNA_def_property_flag(prop, PROP_SKIP_SAVE); } bpy_prop_callback_assign(prop, update_cb); @@ -909,11 +910,11 @@ static PyObject *BPy_StringProperty(PyObject *self, PyObject *args, PyObject *kw /* copies orig to buf, then sets orig to buf, returns copy length */ static size_t strswapbufcpy(char *buf, const char **orig) { - const char *src= *orig; - char *dst= buf; - size_t i= 0; - *orig= buf; - while ((*dst= *src)) { dst++; src++; i++; } + const char *src = *orig; + char *dst = buf; + size_t i = 0; + *orig = buf; + while ((*dst = *src)) { dst++; src++; i++; } return i + 1; /* include '\0' */ } #endif @@ -922,11 +923,11 @@ static EnumPropertyItem *enum_items_from_py(PyObject *seq_fast, PyObject *def, i { EnumPropertyItem *items; PyObject *item; - const Py_ssize_t seq_len= PySequence_Fast_GET_SIZE(seq_fast); - Py_ssize_t totbuf= 0; + const Py_ssize_t seq_len = PySequence_Fast_GET_SIZE(seq_fast); + Py_ssize_t totbuf = 0; int i; - short def_used= 0; - const char *def_cmp= NULL; + short def_used = 0; + const char *def_cmp = NULL; if (is_enum_flag) { if (seq_len > RNA_ENUM_BITFLAG_SIZE) { @@ -946,8 +947,8 @@ static EnumPropertyItem *enum_items_from_py(PyObject *seq_fast, PyObject *def, i } else { if (def) { - def_cmp= _PyUnicode_AsString(def); - if (def_cmp==NULL) { + def_cmp = _PyUnicode_AsString(def); + if (def_cmp == NULL) { PyErr_Format(PyExc_TypeError, "EnumProperty(...): default option must be a 'str' " "type when ENUM_FLAG is disabled, not a '%.200s'", @@ -958,30 +959,30 @@ static EnumPropertyItem *enum_items_from_py(PyObject *seq_fast, PyObject *def, i } /* blank value */ - *defvalue= 0; + *defvalue = 0; - items= MEM_callocN(sizeof(EnumPropertyItem) * (seq_len + 1), "enum_items_from_py1"); + items = MEM_callocN(sizeof(EnumPropertyItem) * (seq_len + 1), "enum_items_from_py1"); - for (i=0; i<seq_len; i++) { - EnumPropertyItem tmp= {0, "", 0, "", ""}; + for (i = 0; i < seq_len; i++) { + EnumPropertyItem tmp = {0, "", 0, "", ""}; Py_ssize_t item_size; Py_ssize_t id_str_size; Py_ssize_t name_str_size; Py_ssize_t desc_str_size; - item= PySequence_Fast_GET_ITEM(seq_fast, i); + item = PySequence_Fast_GET_ITEM(seq_fast, i); if ( (PyTuple_CheckExact(item)) && - (item_size= PyTuple_GET_SIZE(item)) && + (item_size = PyTuple_GET_SIZE(item)) && (item_size == 3 || item_size == 4) && - (tmp.identifier= _PyUnicode_AsStringAndSize(PyTuple_GET_ITEM(item, 0), &id_str_size)) && - (tmp.name= _PyUnicode_AsStringAndSize(PyTuple_GET_ITEM(item, 1), &name_str_size)) && - (tmp.description= _PyUnicode_AsStringAndSize(PyTuple_GET_ITEM(item, 2), &desc_str_size)) && + (tmp.identifier = _PyUnicode_AsStringAndSize(PyTuple_GET_ITEM(item, 0), &id_str_size)) && + (tmp.name = _PyUnicode_AsStringAndSize(PyTuple_GET_ITEM(item, 1), &name_str_size)) && + (tmp.description = _PyUnicode_AsStringAndSize(PyTuple_GET_ITEM(item, 2), &desc_str_size)) && (item_size < 4 || py_long_as_int(PyTuple_GET_ITEM(item, 3), &tmp.value) != -1)) /* TODO, number isnt ensured to be unique from the script author */ { if (is_enum_flag) { if (item_size < 4) { - tmp.value= 1<<i; + tmp.value = 1 << i; } if (def && PySet_Contains(def, PyTuple_GET_ITEM(item, 0))) { @@ -991,16 +992,16 @@ static EnumPropertyItem *enum_items_from_py(PyObject *seq_fast, PyObject *def, i } else { if (item_size < 4) { - tmp.value= i; + tmp.value = i; } - if (def && def_used == 0 && strcmp(def_cmp, tmp.identifier)==0) { - *defvalue= tmp.value; + if (def && def_used == 0 && strcmp(def_cmp, tmp.identifier) == 0) { + *defvalue = tmp.value; def_used++; /* only ever 1 */ } } - items[i]= tmp; + items[i] = tmp; /* calculate combine string length */ totbuf += id_str_size + name_str_size + desc_str_size + 3; /* 3 is for '\0's */ @@ -1046,18 +1047,18 @@ static EnumPropertyItem *enum_items_from_py(PyObject *seq_fast, PyObject *def, i * immediately after use, so we need to duplicate them, ugh. * annoying because it works most of the time without this. */ { - EnumPropertyItem *items_dup= MEM_mallocN((sizeof(EnumPropertyItem) * (seq_len + 1)) + (sizeof(char) * totbuf), + EnumPropertyItem *items_dup = MEM_mallocN((sizeof(EnumPropertyItem) * (seq_len + 1)) + (sizeof(char) * totbuf), "enum_items_from_py2"); - EnumPropertyItem *items_ptr= items_dup; - char *buf= ((char *)items_dup) + (sizeof(EnumPropertyItem) * (seq_len + 1)); + EnumPropertyItem *items_ptr = items_dup; + char *buf = ((char *)items_dup) + (sizeof(EnumPropertyItem) * (seq_len + 1)); memcpy(items_dup, items, sizeof(EnumPropertyItem) * (seq_len + 1)); - for (i=0; i<seq_len; i++, items_ptr++) { + for (i = 0; i < seq_len; i++, items_ptr++) { buf += strswapbufcpy(buf, &items_ptr->identifier); buf += strswapbufcpy(buf, &items_ptr->name); buf += strswapbufcpy(buf, &items_ptr->description); } MEM_freeN(items); - items=items_dup; + items = items_dup; } /* end string duplication */ #endif @@ -1069,47 +1070,47 @@ static EnumPropertyItem *bpy_props_enum_itemf(struct bContext *C, PointerRNA *pt { PyGILState_STATE gilstate; - PyObject *py_func= RNA_property_enum_py_data_get(prop); - PyObject *self= NULL; + PyObject *py_func = RNA_property_enum_py_data_get(prop); + PyObject *self = NULL; PyObject *args; PyObject *items; /* returned from the function call */ - EnumPropertyItem *eitems= NULL; - int err= 0; + EnumPropertyItem *eitems = NULL; + int err = 0; bpy_context_set(C, &gilstate); - args= PyTuple_New(2); - self= pyrna_struct_as_instance(ptr); + args = PyTuple_New(2); + self = pyrna_struct_as_instance(ptr); PyTuple_SET_ITEM(args, 0, self); /* now get the context */ PyTuple_SET_ITEM(args, 1, (PyObject *)bpy_context_module); Py_INCREF(bpy_context_module); - items= PyObject_CallObject(py_func, args); + items = PyObject_CallObject(py_func, args); Py_DECREF(args); - if (items==NULL) { - err= -1; + if (items == NULL) { + err = -1; } else { PyObject *items_fast; - int defvalue_dummy=0; + int defvalue_dummy = 0; - if (!(items_fast= PySequence_Fast(items, "EnumProperty(...): " + if (!(items_fast = PySequence_Fast(items, "EnumProperty(...): " "return value from the callback was not a sequence"))) { - err= -1; + err = -1; } else { - eitems= enum_items_from_py(items_fast, NULL, &defvalue_dummy, (RNA_property_flag(prop) & PROP_ENUM_FLAG)!=0); + eitems = enum_items_from_py(items_fast, NULL, &defvalue_dummy, (RNA_property_flag(prop) & PROP_ENUM_FLAG) != 0); Py_DECREF(items_fast); if (!eitems) { - err= -1; + err = -1; } } @@ -1117,12 +1118,12 @@ static EnumPropertyItem *bpy_props_enum_itemf(struct bContext *C, PointerRNA *pt } if (err != -1) { /* worked */ - *free= 1; + *free = 1; } else { printf_func_error(py_func); - eitems= DummyRNA_NULL_items; + eitems = DummyRNA_NULL_items; } @@ -1160,19 +1161,19 @@ static PyObject *BPy_EnumProperty(PyObject *self, PyObject *args, PyObject *kw) BPY_PROPDEF_HEAD(EnumProperty) if (srna) { - static const char *kwlist[]= {"attr", "items", "name", "description", "default", + static const char *kwlist[] = {"attr", "items", "name", "description", "default", "options", "update", NULL}; - const char *id=NULL, *name="", *description=""; - PyObject *def= NULL; + const char *id = NULL, *name = "", *description = ""; + PyObject *def = NULL; int id_len; - int defvalue=0; + int defvalue = 0; PyObject *items, *items_fast; EnumPropertyItem *eitems; PropertyRNA *prop; - PyObject *pyopts= NULL; - int opts=0; - short is_itemf= FALSE; - PyObject *update_cb= NULL; + PyObject *pyopts = NULL; + int opts = 0; + short is_itemf = FALSE; + PyObject *update_cb = NULL; if (!PyArg_ParseTupleAndKeywords(args, kw, "s#O|ssOO!O:EnumProperty", @@ -1192,7 +1193,7 @@ static PyObject *BPy_EnumProperty(PyObject *self, PyObject *args, PyObject *kw) /* items can be a list or a callable */ if (PyFunction_Check(items)) { /* dont use PyCallable_Check because we need the function code for errors */ - PyCodeObject *f_code= (PyCodeObject *)PyFunction_GET_CODE(items); + PyCodeObject *f_code = (PyCodeObject *)PyFunction_GET_CODE(items); if (f_code->co_argcount != 2) { PyErr_Format(PyExc_ValueError, "EnumProperty(...): expected 'items' function to take 2 arguments, not %d", @@ -1207,17 +1208,17 @@ static PyObject *BPy_EnumProperty(PyObject *self, PyObject *args, PyObject *kw) return NULL; } - is_itemf= TRUE; - eitems= DummyRNA_NULL_items; + is_itemf = TRUE; + eitems = DummyRNA_NULL_items; } else { - if (!(items_fast= PySequence_Fast(items, "EnumProperty(...): " + if (!(items_fast = PySequence_Fast(items, "EnumProperty(...): " "expected a sequence of tuples for the enum items or a function"))) { return NULL; } - eitems= enum_items_from_py(items_fast, def, &defvalue, (opts & PROP_ENUM_FLAG)!=0); + eitems = enum_items_from_py(items_fast, def, &defvalue, (opts & PROP_ENUM_FLAG) != 0); Py_DECREF(items_fast); @@ -1226,8 +1227,8 @@ static PyObject *BPy_EnumProperty(PyObject *self, PyObject *args, PyObject *kw) } } - if (opts & PROP_ENUM_FLAG) prop= RNA_def_enum_flag(srna, id, eitems, defvalue, name, description); - else prop= RNA_def_enum(srna, id, eitems, defvalue, name, description); + if (opts & PROP_ENUM_FLAG) prop = RNA_def_enum_flag(srna, id, eitems, defvalue, name, description); + else prop = RNA_def_enum(srna, id, eitems, defvalue, name, description); if (is_itemf) { RNA_def_enum_funcs(prop, bpy_props_enum_itemf); @@ -1240,7 +1241,7 @@ static PyObject *BPy_EnumProperty(PyObject *self, PyObject *args, PyObject *kw) if (pyopts) { if (opts & PROP_HIDDEN) RNA_def_property_flag(prop, PROP_HIDDEN); - if ((opts & PROP_ANIMATABLE)==0) RNA_def_property_clear_flag(prop, PROP_ANIMATABLE); + if ((opts & PROP_ANIMATABLE) == 0) RNA_def_property_clear_flag(prop, PROP_ANIMATABLE); if (opts & PROP_SKIP_SAVE) RNA_def_property_flag(prop, PROP_SKIP_SAVE); } bpy_prop_callback_assign(prop, update_cb); @@ -1257,11 +1258,11 @@ static StructRNA *pointer_type_from_py(PyObject *value, const char *error_prefix { StructRNA *srna; - srna= srna_from_self(value, ""); + srna = srna_from_self(value, ""); if (!srna) { if (PyErr_Occurred()) { - PyObject *msg= PyC_ExceptionBuffer(); - const char *msg_char= _PyUnicode_AsString(msg); + PyObject *msg = PyC_ExceptionBuffer(); + const char *msg_char = _PyUnicode_AsString(msg); PyErr_Format(PyExc_TypeError, "%.200s expected an RNA type derived from PropertyGroup, failed with: %s", error_prefix, msg_char); @@ -1305,15 +1306,15 @@ static PyObject *BPy_PointerProperty(PyObject *self, PyObject *args, PyObject *k BPY_PROPDEF_HEAD(PointerProperty) if (srna) { - static const char *kwlist[]= {"attr", "type", "name", "description", "options", "update", NULL}; - const char *id=NULL, *name="", *description=""; + static const char *kwlist[] = {"attr", "type", "name", "description", "options", "update", NULL}; + const char *id = NULL, *name = "", *description = ""; int id_len; PropertyRNA *prop; StructRNA *ptype; - PyObject *type= Py_None; - PyObject *pyopts= NULL; - int opts=0; - PyObject *update_cb= NULL; + PyObject *type = Py_None; + PyObject *pyopts = NULL; + int opts = 0; + PyObject *update_cb = NULL; if (!PyArg_ParseTupleAndKeywords(args, kw, "s#O|ssO!O:PointerProperty", @@ -1327,7 +1328,7 @@ static PyObject *BPy_PointerProperty(PyObject *self, PyObject *args, PyObject *k BPY_PROPDEF_CHECK(PointerProperty, property_flag_items) - ptype= pointer_type_from_py(type, "PointerProperty(...):"); + ptype = pointer_type_from_py(type, "PointerProperty(...):"); if (!ptype) return NULL; @@ -1335,10 +1336,10 @@ static PyObject *BPy_PointerProperty(PyObject *self, PyObject *args, PyObject *k return NULL; } - prop= RNA_def_pointer_runtime(srna, id, ptype, name, description); + prop = RNA_def_pointer_runtime(srna, id, ptype, name, description); if (pyopts) { if (opts & PROP_HIDDEN) RNA_def_property_flag(prop, PROP_HIDDEN); - if ((opts & PROP_ANIMATABLE)==0) RNA_def_property_clear_flag(prop, PROP_ANIMATABLE); + if ((opts & PROP_ANIMATABLE) == 0) RNA_def_property_clear_flag(prop, PROP_ANIMATABLE); if (opts & PROP_SKIP_SAVE) RNA_def_property_flag(prop, PROP_SKIP_SAVE); } bpy_prop_callback_assign(prop, update_cb); @@ -1366,14 +1367,14 @@ static PyObject *BPy_CollectionProperty(PyObject *self, PyObject *args, PyObject BPY_PROPDEF_HEAD(CollectionProperty) if (srna) { - static const char *kwlist[]= {"attr", "type", "name", "description", "options", NULL}; - const char *id=NULL, *name="", *description=""; + static const char *kwlist[] = {"attr", "type", "name", "description", "options", NULL}; + const char *id = NULL, *name = "", *description = ""; int id_len; PropertyRNA *prop; StructRNA *ptype; - PyObject *type= Py_None; - PyObject *pyopts= NULL; - int opts=0; + PyObject *type = Py_None; + PyObject *pyopts = NULL; + int opts = 0; if (!PyArg_ParseTupleAndKeywords(args, kw, "s#O|ssO!:CollectionProperty", @@ -1386,14 +1387,14 @@ static PyObject *BPy_CollectionProperty(PyObject *self, PyObject *args, PyObject BPY_PROPDEF_CHECK(CollectionProperty, property_flag_items) - ptype= pointer_type_from_py(type, "CollectionProperty(...):"); + ptype = pointer_type_from_py(type, "CollectionProperty(...):"); if (!ptype) return NULL; - prop= RNA_def_collection_runtime(srna, id, ptype, name, description); + prop = RNA_def_collection_runtime(srna, id, ptype, name, description); if (pyopts) { if (opts & PROP_HIDDEN) RNA_def_property_flag(prop, PROP_HIDDEN); - if ((opts & PROP_ANIMATABLE)==0) RNA_def_property_clear_flag(prop, PROP_ANIMATABLE); + if ((opts & PROP_ANIMATABLE) == 0) RNA_def_property_clear_flag(prop, PROP_ANIMATABLE); if (opts & PROP_SKIP_SAVE) RNA_def_property_flag(prop, PROP_SKIP_SAVE); } RNA_def_property_duplicate_pointers(srna, prop); @@ -1415,9 +1416,9 @@ static PyObject *BPy_RemoveProperty(PyObject *self, PyObject *args, PyObject *kw if (PyTuple_GET_SIZE(args) == 1) { PyObject *ret; - self= PyTuple_GET_ITEM(args, 0); - args= PyTuple_New(0); - ret= BPy_RemoveProperty(self, args, kw); + self = PyTuple_GET_ITEM(args, 0); + args = PyTuple_New(0); + ret = BPy_RemoveProperty(self, args, kw); Py_DECREF(args); return ret; } @@ -1426,18 +1427,18 @@ static PyObject *BPy_RemoveProperty(PyObject *self, PyObject *args, PyObject *kw return NULL; } - srna= srna_from_self(self, "RemoveProperty(...):"); - if (srna==NULL && PyErr_Occurred()) { + srna = srna_from_self(self, "RemoveProperty(...):"); + if (srna == NULL && PyErr_Occurred()) { return NULL; /* self's type was compatible but error getting the srna */ } - else if (srna==NULL) { + else if (srna == NULL) { PyErr_SetString(PyExc_TypeError, "RemoveProperty(): struct rna not available for this type"); return NULL; } else { - static const char *kwlist[]= {"attr", NULL}; + static const char *kwlist[] = {"attr", NULL}; - char *id=NULL; + char *id = NULL; if (!PyArg_ParseTupleAndKeywords(args, kw, "s:RemoveProperty", @@ -1454,7 +1455,7 @@ static PyObject *BPy_RemoveProperty(PyObject *self, PyObject *args, PyObject *kw Py_RETURN_NONE; } -static struct PyMethodDef props_methods[]= { +static struct PyMethodDef props_methods[] = { {"BoolProperty", (PyCFunction)BPy_BoolProperty, METH_VARARGS|METH_KEYWORDS, BPy_BoolProperty_doc}, {"BoolVectorProperty", (PyCFunction)BPy_BoolVectorProperty, METH_VARARGS|METH_KEYWORDS, BPy_BoolVectorProperty_doc}, {"IntProperty", (PyCFunction)BPy_IntProperty, METH_VARARGS|METH_KEYWORDS, BPy_IntProperty_doc}, @@ -1470,7 +1471,7 @@ static struct PyMethodDef props_methods[]= { {NULL, NULL, 0, NULL} }; -static struct PyModuleDef props_module= { +static struct PyModuleDef props_module = { PyModuleDef_HEAD_INIT, "bpy.props", "This module defines properties to extend blenders internal data, the result of these functions" @@ -1485,7 +1486,7 @@ PyObject *BPY_rna_props(void) PyObject *submodule; PyObject *submodule_dict; - submodule= PyModule_Create(&props_module); + submodule = PyModule_Create(&props_module); PyDict_SetItemString(PyImport_GetModuleDict(), props_module.m_name, submodule); /* INCREF since its its assumed that all these functions return the @@ -1494,9 +1495,9 @@ PyObject *BPY_rna_props(void) Py_INCREF(submodule); /* api needs the PyObjects internally */ - submodule_dict= PyModule_GetDict(submodule); + submodule_dict = PyModule_GetDict(submodule); -#define ASSIGN_STATIC(_name) pymeth_##_name= PyDict_GetItemString(submodule_dict, #_name) +#define ASSIGN_STATIC(_name) pymeth_##_name = PyDict_GetItemString(submodule_dict, #_name) ASSIGN_STATIC(BoolProperty); ASSIGN_STATIC(BoolVectorProperty); diff --git a/source/blender/python/intern/bpy_rna.c b/source/blender/python/intern/bpy_rna.c index ded0f2f768c..b23db759603 100644 --- a/source/blender/python/intern/bpy_rna.c +++ b/source/blender/python/intern/bpy_rna.c @@ -120,13 +120,13 @@ int pyrna_prop_validity_check(BPy_PropertyRNA *self) #if defined(USE_PYRNA_INVALIDATE_GC) || defined(USE_PYRNA_INVALIDATE_WEAKREF) static void pyrna_invalidate(BPy_DummyPointerRNA *self) { - self->ptr.type= NULL; /* this is checked for validity */ - self->ptr.id.data= NULL; /* should not be needed but prevent bad pointer access, just incase */ + self->ptr.type = NULL; /* this is checked for validity */ + self->ptr.id.data = NULL; /* should not be needed but prevent bad pointer access, just incase */ } #endif #ifdef USE_PYRNA_INVALIDATE_GC -#define FROM_GC(g) ((PyObject *)(((PyGC_Head *)g)+1)) +#define FROM_GC(g) ((PyObject *)(((PyGC_Head *)g) + 1)) /* only for sizeof() */ struct gc_generation { @@ -138,15 +138,15 @@ struct gc_generation { static void id_release_gc(struct ID *id) { unsigned int j; - // unsigned int i= 0; - for (j=0; j<3; j++) { + // unsigned int i = 0; + for (j = 0; j < 3; j++) { /* hack below to get the 2 other lists from _PyGC_generation0 that are normally not exposed */ - PyGC_Head *gen= (PyGC_Head *)(((char *)_PyGC_generation0) + (sizeof(gc_generation) * j)); - PyGC_Head *g= gen->gc.gc_next; - while ((g= g->gc.gc_next) != gen) { - PyObject *ob= FROM_GC(g); + PyGC_Head *gen = (PyGC_Head *)(((char *)_PyGC_generation0) + (sizeof(gc_generation) * j)); + PyGC_Head *g = gen->gc.gc_next; + while ((g = g->gc.gc_next) != gen) { + PyObject *ob = FROM_GC(g); if (PyType_IsSubtype(Py_TYPE(ob), &pyrna_struct_Type) || PyType_IsSubtype(Py_TYPE(ob), &pyrna_prop_Type)) { - BPy_DummyPointerRNA *ob_ptr= (BPy_DummyPointerRNA *)ob; + BPy_DummyPointerRNA *ob_ptr = (BPy_DummyPointerRNA *)ob; if (ob_ptr->ptr.id.data == id) { pyrna_invalidate(ob_ptr); // printf("freeing: %p %s, %.200s\n", (void *)ob, id->name, Py_TYPE(ob)->tp_name); @@ -162,27 +162,27 @@ static void id_release_gc(struct ID *id) #ifdef USE_PYRNA_INVALIDATE_WEAKREF //#define DEBUG_RNA_WEAKREF -struct GHash *id_weakref_pool= NULL; +struct GHash *id_weakref_pool = NULL; static PyObject *id_free_weakref_cb(PyObject *weakinfo_pair, PyObject *weakref); -static PyMethodDef id_free_weakref_cb_def= {"id_free_weakref_cb", (PyCFunction)id_free_weakref_cb, METH_O, NULL}; +static PyMethodDef id_free_weakref_cb_def = {"id_free_weakref_cb", (PyCFunction)id_free_weakref_cb, METH_O, NULL}; /* adds a reference to the list, remember to decref */ static GHash *id_weakref_pool_get(ID *id) { - GHash *weakinfo_hash= NULL; + GHash *weakinfo_hash = NULL; if (id_weakref_pool) { - weakinfo_hash= BLI_ghash_lookup(id_weakref_pool, (void *)id); + weakinfo_hash = BLI_ghash_lookup(id_weakref_pool, (void *)id); } else { /* first time, allocate pool */ - id_weakref_pool= BLI_ghash_new(BLI_ghashutil_ptrhash, BLI_ghashutil_ptrcmp, "rna_global_pool"); - weakinfo_hash= NULL; + id_weakref_pool = BLI_ghash_new(BLI_ghashutil_ptrhash, BLI_ghashutil_ptrcmp, "rna_global_pool"); + weakinfo_hash = NULL; } - if (weakinfo_hash==NULL) { + if (weakinfo_hash == NULL) { /* we're using a ghash as a set, could use libHX's HXMAP_SINGULAR but would be an extra dep. */ - weakinfo_hash= BLI_ghash_new(BLI_ghashutil_ptrhash, BLI_ghashutil_ptrcmp, "rna_id"); + weakinfo_hash = BLI_ghash_new(BLI_ghashutil_ptrhash, BLI_ghashutil_ptrcmp, "rna_id"); BLI_ghash_insert(id_weakref_pool, (void *)id, weakinfo_hash); } @@ -197,14 +197,14 @@ void id_weakref_pool_add(ID *id, BPy_DummyPointerRNA *pyrna) PyObject *weakref_cb_py; /* create a new function instance and insert the list as 'self' so we can remove ourself from it */ - GHash *weakinfo_hash= id_weakref_pool_get(id); /* new or existing */ + GHash *weakinfo_hash = id_weakref_pool_get(id); /* new or existing */ - weakref_capsule= PyCapsule_New(weakinfo_hash, NULL, NULL); - weakref_cb_py= PyCFunction_New(&id_free_weakref_cb_def, weakref_capsule); + weakref_capsule = PyCapsule_New(weakinfo_hash, NULL, NULL); + weakref_cb_py = PyCFunction_New(&id_free_weakref_cb_def, weakref_capsule); Py_DECREF(weakref_capsule); /* add weakref to weakinfo_hash list */ - weakref= PyWeakref_NewRef((PyObject *)pyrna, weakref_cb_py); + weakref = PyWeakref_NewRef((PyObject *)pyrna, weakref_cb_py); Py_DECREF(weakref_cb_py); /* function owned by the weakref now */ @@ -218,14 +218,14 @@ void id_weakref_pool_add(ID *id, BPy_DummyPointerRNA *pyrna) static ID *_id_tmp_ptr; static void value_id_set(void *id) { - _id_tmp_ptr= (ID *)id; + _id_tmp_ptr = (ID *)id; } static void id_release_weakref_list(struct ID *id, GHash *weakinfo_hash); static PyObject *id_free_weakref_cb(PyObject *weakinfo_capsule, PyObject *weakref) { /* important to search backwards */ - GHash *weakinfo_hash= PyCapsule_GetPointer(weakinfo_capsule, NULL); + GHash *weakinfo_hash = PyCapsule_GetPointer(weakinfo_capsule, NULL); if (BLI_ghash_size(weakinfo_hash) > 1) { @@ -252,8 +252,8 @@ static void id_release_weakref_list(struct ID *id, GHash *weakinfo_hash) #endif while (!BLI_ghashIterator_isDone(&weakinfo_hash_iter)) { - PyObject *weakref= (PyObject *)BLI_ghashIterator_getKey(&weakinfo_hash_iter); - PyObject *item= PyWeakref_GET_OBJECT(weakref); + PyObject *weakref = (PyObject *)BLI_ghashIterator_getKey(&weakinfo_hash_iter); + PyObject *item = PyWeakref_GET_OBJECT(weakref); if (item != Py_None) { #ifdef DEBUG_RNA_WEAKREF @@ -273,7 +273,7 @@ static void id_release_weakref_list(struct ID *id, GHash *weakinfo_hash) if (BLI_ghash_size(id_weakref_pool) == 0) { BLI_ghash_free(id_weakref_pool, NULL, NULL); - id_weakref_pool= NULL; + id_weakref_pool = NULL; #ifdef DEBUG_RNA_WEAKREF printf("id_release_weakref freeing pool\n"); #endif @@ -282,7 +282,7 @@ static void id_release_weakref_list(struct ID *id, GHash *weakinfo_hash) static void id_release_weakref(struct ID *id) { - GHash *weakinfo_hash= BLI_ghash_lookup(id_weakref_pool, (void *)id); + GHash *weakinfo_hash = BLI_ghash_lookup(id_weakref_pool, (void *)id); if (weakinfo_hash) { id_release_weakref_list(id, weakinfo_hash); } @@ -298,7 +298,7 @@ void BPY_id_release(struct ID *id) #ifdef USE_PYRNA_INVALIDATE_WEAKREF if (id_weakref_pool) { - PyGILState_STATE gilstate= PyGILState_Ensure(); + PyGILState_STATE gilstate = PyGILState_Ensure(); id_release_weakref(id); @@ -310,25 +310,25 @@ void BPY_id_release(struct ID *id) } #ifdef USE_PEDANTIC_WRITE -static short rna_disallow_writes= FALSE; +static short rna_disallow_writes = FALSE; static int rna_id_write_error(PointerRNA *ptr, PyObject *key) { - ID *id= ptr->id.data; + ID *id = ptr->id.data; if (id) { - const short idcode= GS(id->name); + const short idcode = GS(id->name); if (!ELEM(idcode, ID_WM, ID_SCR)) { /* may need more added here */ - const char *idtype= BKE_idcode_to_name(idcode); + const char *idtype = BKE_idcode_to_name(idcode); const char *pyname; - if (key && PyUnicode_Check(key)) pyname= _PyUnicode_AsString(key); - else pyname= "<UNKNOWN>"; + if (key && PyUnicode_Check(key)) pyname = _PyUnicode_AsString(key); + else pyname = "<UNKNOWN>"; /* make a nice string error */ BLI_assert(idtype != NULL); PyErr_Format(PyExc_AttributeError, "Writing to ID classes in this context is not allowed: " "%.200s, %.200s datablock, error setting %.200s.%.200s", - id->name+2, idtype, RNA_struct_identifier(ptr->type), pyname); + id->name + 2, idtype, RNA_struct_identifier(ptr->type), pyname); return TRUE; } @@ -346,7 +346,7 @@ int pyrna_write_check(void) void pyrna_write_set(int val) { - rna_disallow_writes= !val; + rna_disallow_writes = !val; } #else // USE_PEDANTIC_WRITE int pyrna_write_check(void) @@ -372,7 +372,7 @@ static PyObject *pyrna_prop_array_subscript_slice(BPy_PropertyArrayRNA *self, Po static short pyrna_rotation_euler_order_get(PointerRNA *ptr, PropertyRNA **prop_eul_order, short order_fallback); /* bpyrna vector/euler/quat callbacks */ -static int mathutils_rna_array_cb_index= -1; /* index for our callbacks */ +static int mathutils_rna_array_cb_index = -1; /* index for our callbacks */ /* subtype not used much yet */ #define MATHUTILS_CB_SUBTYPE_EUL 0 @@ -382,7 +382,7 @@ static int mathutils_rna_array_cb_index= -1; /* index for our callbacks */ static int mathutils_rna_generic_check(BaseMathObject *bmo) { - BPy_PropertyRNA *self= (BPy_PropertyRNA *)bmo->cb_user; + BPy_PropertyRNA *self = (BPy_PropertyRNA *)bmo->cb_user; PYRNA_PROP_CHECK_INT(self); @@ -391,20 +391,20 @@ static int mathutils_rna_generic_check(BaseMathObject *bmo) static int mathutils_rna_vector_get(BaseMathObject *bmo, int subtype) { - BPy_PropertyRNA *self= (BPy_PropertyRNA *)bmo->cb_user; + BPy_PropertyRNA *self = (BPy_PropertyRNA *)bmo->cb_user; PYRNA_PROP_CHECK_INT(self); - if (self->prop==NULL) + if (self->prop == NULL) return -1; RNA_property_float_get_array(&self->ptr, self->prop, bmo->data); /* Euler order exception */ - if (subtype==MATHUTILS_CB_SUBTYPE_EUL) { - EulerObject *eul= (EulerObject *)bmo; - PropertyRNA *prop_eul_order= NULL; - eul->order= pyrna_rotation_euler_order_get(&self->ptr, &prop_eul_order, eul->order); + if (subtype == MATHUTILS_CB_SUBTYPE_EUL) { + EulerObject *eul = (EulerObject *)bmo; + PropertyRNA *prop_eul_order = NULL; + eul->order = pyrna_rotation_euler_order_get(&self->ptr, &prop_eul_order, eul->order); } return 0; @@ -412,12 +412,12 @@ static int mathutils_rna_vector_get(BaseMathObject *bmo, int subtype) static int mathutils_rna_vector_set(BaseMathObject *bmo, int subtype) { - BPy_PropertyRNA *self= (BPy_PropertyRNA *)bmo->cb_user; + BPy_PropertyRNA *self = (BPy_PropertyRNA *)bmo->cb_user; float min, max; PYRNA_PROP_CHECK_INT(self); - if (self->prop==NULL) + if (self->prop == NULL) return -1; #ifdef USE_PEDANTIC_WRITE @@ -436,8 +436,8 @@ static int mathutils_rna_vector_set(BaseMathObject *bmo, int subtype) RNA_property_float_range(&self->ptr, self->prop, &min, &max); if (min != FLT_MIN || max != FLT_MAX) { - int i, len= RNA_property_array_length(&self->ptr, self->prop); - for (i=0; i<len; i++) { + int i, len = RNA_property_array_length(&self->ptr, self->prop); + for (i = 0; i < len; i++) { CLAMP(bmo->data[i], min, max); } } @@ -448,10 +448,10 @@ static int mathutils_rna_vector_set(BaseMathObject *bmo, int subtype) } /* Euler order exception */ - if (subtype==MATHUTILS_CB_SUBTYPE_EUL) { - EulerObject *eul= (EulerObject *)bmo; - PropertyRNA *prop_eul_order= NULL; - short order= pyrna_rotation_euler_order_get(&self->ptr, &prop_eul_order, eul->order); + if (subtype == MATHUTILS_CB_SUBTYPE_EUL) { + EulerObject *eul = (EulerObject *)bmo; + PropertyRNA *prop_eul_order = NULL; + short order = pyrna_rotation_euler_order_get(&self->ptr, &prop_eul_order, eul->order); if (order != eul->order) { RNA_property_enum_set(&self->ptr, prop_eul_order, eul->order); if (RNA_property_update_check(prop_eul_order)) { @@ -464,24 +464,24 @@ static int mathutils_rna_vector_set(BaseMathObject *bmo, int subtype) static int mathutils_rna_vector_get_index(BaseMathObject *bmo, int UNUSED(subtype), int index) { - BPy_PropertyRNA *self= (BPy_PropertyRNA *)bmo->cb_user; + BPy_PropertyRNA *self = (BPy_PropertyRNA *)bmo->cb_user; PYRNA_PROP_CHECK_INT(self); - if (self->prop==NULL) + if (self->prop == NULL) return -1; - bmo->data[index]= RNA_property_float_get_index(&self->ptr, self->prop, index); + bmo->data[index] = RNA_property_float_get_index(&self->ptr, self->prop, index); return 0; } static int mathutils_rna_vector_set_index(BaseMathObject *bmo, int UNUSED(subtype), int index) { - BPy_PropertyRNA *self= (BPy_PropertyRNA *)bmo->cb_user; + BPy_PropertyRNA *self = (BPy_PropertyRNA *)bmo->cb_user; PYRNA_PROP_CHECK_INT(self); - if (self->prop==NULL) + if (self->prop == NULL) return -1; #ifdef USE_PEDANTIC_WRITE @@ -507,7 +507,7 @@ static int mathutils_rna_vector_set_index(BaseMathObject *bmo, int UNUSED(subtyp return 0; } -static Mathutils_Callback mathutils_rna_array_cb= { +static Mathutils_Callback mathutils_rna_array_cb = { (BaseMathCheckFunc) mathutils_rna_generic_check, (BaseMathGetFunc) mathutils_rna_vector_get, (BaseMathSetFunc) mathutils_rna_vector_set, @@ -517,15 +517,15 @@ static Mathutils_Callback mathutils_rna_array_cb= { /* bpyrna matrix callbacks */ -static int mathutils_rna_matrix_cb_index= -1; /* index for our callbacks */ +static int mathutils_rna_matrix_cb_index = -1; /* index for our callbacks */ static int mathutils_rna_matrix_get(BaseMathObject *bmo, int UNUSED(subtype)) { - BPy_PropertyRNA *self= (BPy_PropertyRNA *)bmo->cb_user; + BPy_PropertyRNA *self = (BPy_PropertyRNA *)bmo->cb_user; PYRNA_PROP_CHECK_INT(self); - if (self->prop==NULL) + if (self->prop == NULL) return -1; RNA_property_float_get_array(&self->ptr, self->prop, bmo->data); @@ -534,11 +534,11 @@ static int mathutils_rna_matrix_get(BaseMathObject *bmo, int UNUSED(subtype)) static int mathutils_rna_matrix_set(BaseMathObject *bmo, int UNUSED(subtype)) { - BPy_PropertyRNA *self= (BPy_PropertyRNA *)bmo->cb_user; + BPy_PropertyRNA *self = (BPy_PropertyRNA *)bmo->cb_user; PYRNA_PROP_CHECK_INT(self); - if (self->prop==NULL) + if (self->prop == NULL) return -1; #ifdef USE_PEDANTIC_WRITE @@ -563,7 +563,7 @@ static int mathutils_rna_matrix_set(BaseMathObject *bmo, int UNUSED(subtype)) return 0; } -static Mathutils_Callback mathutils_rna_matrix_cb= { +static Mathutils_Callback mathutils_rna_matrix_cb = { mathutils_rna_generic_check, mathutils_rna_matrix_get, mathutils_rna_matrix_set, @@ -574,11 +574,11 @@ static Mathutils_Callback mathutils_rna_matrix_cb= { static short pyrna_rotation_euler_order_get(PointerRNA *ptr, PropertyRNA **prop_eul_order, short order_fallback) { /* attempt to get order */ - if (*prop_eul_order==NULL) - *prop_eul_order= RNA_struct_find_property(ptr, "rotation_mode"); + if (*prop_eul_order == NULL) + *prop_eul_order = RNA_struct_find_property(ptr, "rotation_mode"); if (*prop_eul_order) { - short order= RNA_property_enum_get(ptr, *prop_eul_order); + short order = RNA_property_enum_get(ptr, *prop_eul_order); if (order >= EULER_ORDER_XYZ && order <= EULER_ORDER_ZYX) /* could be quat or axisangle */ return order; } @@ -602,107 +602,107 @@ static short pyrna_rotation_euler_order_get(PointerRNA *ptr, PropertyRNA **prop_ PyObject *pyrna_math_object_from_array(PointerRNA *ptr, PropertyRNA *prop) { - PyObject *ret= NULL; + PyObject *ret = NULL; #ifdef USE_MATHUTILS int subtype, totdim; int len; int is_thick; - const int flag= RNA_property_flag(prop); + const int flag = RNA_property_flag(prop); /* disallow dynamic sized arrays to be wrapped since the size could change * to a size mathutils does not support */ if ((RNA_property_type(prop) != PROP_FLOAT) || (flag & PROP_DYNAMIC)) return NULL; - len= RNA_property_array_length(ptr, prop); - subtype= RNA_property_subtype(prop); - totdim= RNA_property_array_dimension(ptr, prop, NULL); - is_thick= (flag & PROP_THICK_WRAP); + len = RNA_property_array_length(ptr, prop); + subtype = RNA_property_subtype(prop); + totdim = RNA_property_array_dimension(ptr, prop, NULL); + is_thick = (flag & PROP_THICK_WRAP); if (totdim == 1 || (totdim == 2 && subtype == PROP_MATRIX)) { if (!is_thick) - ret= pyrna_prop_CreatePyObject(ptr, prop); /* owned by the mathutils PyObject */ + ret = pyrna_prop_CreatePyObject(ptr, prop); /* owned by the mathutils PyObject */ switch (subtype) { case PROP_ALL_VECTOR_SUBTYPES: - if (len>=2 && len <= 4) { + if (len >= 2 && len <= 4) { if (is_thick) { - ret= Vector_CreatePyObject(NULL, len, Py_NEW, NULL); + ret = Vector_CreatePyObject(NULL, len, Py_NEW, NULL); RNA_property_float_get_array(ptr, prop, ((VectorObject *)ret)->vec); } else { - PyObject *vec_cb= Vector_CreatePyObject_cb(ret, len, mathutils_rna_array_cb_index, MATHUTILS_CB_SUBTYPE_VEC); + PyObject *vec_cb = Vector_CreatePyObject_cb(ret, len, mathutils_rna_array_cb_index, MATHUTILS_CB_SUBTYPE_VEC); Py_DECREF(ret); /* the vector owns now */ - ret= vec_cb; /* return the vector instead */ + ret = vec_cb; /* return the vector instead */ } } break; case PROP_MATRIX: - if (len==16) { + if (len == 16) { if (is_thick) { - ret= Matrix_CreatePyObject(NULL, 4, 4, Py_NEW, NULL); + ret = Matrix_CreatePyObject(NULL, 4, 4, Py_NEW, NULL); RNA_property_float_get_array(ptr, prop, ((MatrixObject *)ret)->matrix); } else { - PyObject *mat_cb= Matrix_CreatePyObject_cb(ret, 4,4, mathutils_rna_matrix_cb_index, FALSE); + PyObject *mat_cb = Matrix_CreatePyObject_cb(ret, 4,4, mathutils_rna_matrix_cb_index, FALSE); Py_DECREF(ret); /* the matrix owns now */ - ret= mat_cb; /* return the matrix instead */ + ret = mat_cb; /* return the matrix instead */ } } - else if (len==9) { + else if (len == 9) { if (is_thick) { - ret= Matrix_CreatePyObject(NULL, 3, 3, Py_NEW, NULL); + ret = Matrix_CreatePyObject(NULL, 3, 3, Py_NEW, NULL); RNA_property_float_get_array(ptr, prop, ((MatrixObject *)ret)->matrix); } else { - PyObject *mat_cb= Matrix_CreatePyObject_cb(ret, 3,3, mathutils_rna_matrix_cb_index, FALSE); + PyObject *mat_cb = Matrix_CreatePyObject_cb(ret, 3,3, mathutils_rna_matrix_cb_index, FALSE); Py_DECREF(ret); /* the matrix owns now */ - ret= mat_cb; /* return the matrix instead */ + ret = mat_cb; /* return the matrix instead */ } } break; case PROP_EULER: case PROP_QUATERNION: - if (len==3) { /* euler */ + if (len == 3) { /* euler */ if (is_thick) { /* attempt to get order, only needed for thick types since wrapped with update via callbacks */ - PropertyRNA *prop_eul_order= NULL; - short order= pyrna_rotation_euler_order_get(ptr, &prop_eul_order, EULER_ORDER_XYZ); + PropertyRNA *prop_eul_order = NULL; + short order = pyrna_rotation_euler_order_get(ptr, &prop_eul_order, EULER_ORDER_XYZ); - ret= Euler_CreatePyObject(NULL, order, Py_NEW, NULL); // TODO, get order from RNA + ret = Euler_CreatePyObject(NULL, order, Py_NEW, NULL); // TODO, get order from RNA RNA_property_float_get_array(ptr, prop, ((EulerObject *)ret)->eul); } else { /* order will be updated from callback on use */ - PyObject *eul_cb= Euler_CreatePyObject_cb(ret, EULER_ORDER_XYZ, mathutils_rna_array_cb_index, MATHUTILS_CB_SUBTYPE_EUL); // TODO, get order from RNA + PyObject *eul_cb = Euler_CreatePyObject_cb(ret, EULER_ORDER_XYZ, mathutils_rna_array_cb_index, MATHUTILS_CB_SUBTYPE_EUL); // TODO, get order from RNA Py_DECREF(ret); /* the euler owns now */ - ret= eul_cb; /* return the euler instead */ + ret = eul_cb; /* return the euler instead */ } } - else if (len==4) { + else if (len == 4) { if (is_thick) { - ret= Quaternion_CreatePyObject(NULL, Py_NEW, NULL); + ret = Quaternion_CreatePyObject(NULL, Py_NEW, NULL); RNA_property_float_get_array(ptr, prop, ((QuaternionObject *)ret)->quat); } else { - PyObject *quat_cb= Quaternion_CreatePyObject_cb(ret, mathutils_rna_array_cb_index, MATHUTILS_CB_SUBTYPE_QUAT); + PyObject *quat_cb = Quaternion_CreatePyObject_cb(ret, mathutils_rna_array_cb_index, MATHUTILS_CB_SUBTYPE_QUAT); Py_DECREF(ret); /* the quat owns now */ - ret= quat_cb; /* return the quat instead */ + ret = quat_cb; /* return the quat instead */ } } break; case PROP_COLOR: case PROP_COLOR_GAMMA: - if (len==3) { /* color */ + if (len == 3) { /* color */ if (is_thick) { - ret= Color_CreatePyObject(NULL, Py_NEW, NULL); // TODO, get order from RNA + ret = Color_CreatePyObject(NULL, Py_NEW, NULL); // TODO, get order from RNA RNA_property_float_get_array(ptr, prop, ((ColorObject *)ret)->col); } else { - PyObject *col_cb= Color_CreatePyObject_cb(ret, mathutils_rna_array_cb_index, MATHUTILS_CB_SUBTYPE_COLOR); + PyObject *col_cb = Color_CreatePyObject_cb(ret, mathutils_rna_array_cb_index, MATHUTILS_CB_SUBTYPE_COLOR); Py_DECREF(ret); /* the color owns now */ - ret= col_cb; /* return the color instead */ + ret = col_cb; /* return the color instead */ } } default: @@ -710,14 +710,14 @@ PyObject *pyrna_math_object_from_array(PointerRNA *ptr, PropertyRNA *prop) } } - if (ret==NULL) { + if (ret == NULL) { if (is_thick) { /* this is an array we cant reference (since its not thin wrappable) * and cannot be coerced into a mathutils type, so return as a list */ - ret= pyrna_prop_array_subscript_slice(NULL, ptr, prop, 0, len, len); + ret = pyrna_prop_array_subscript_slice(NULL, ptr, prop, 0, len, len); } else { - ret= pyrna_prop_CreatePyObject(ptr, prop); /* owned by the mathutils PyObject */ + ret = pyrna_prop_CreatePyObject(ptr, prop); /* owned by the mathutils PyObject */ } } #else // USE_MATHUTILS @@ -732,7 +732,7 @@ PyObject *pyrna_math_object_from_array(PointerRNA *ptr, PropertyRNA *prop) int pyrna_enum_value_from_id(EnumPropertyItem *item, const char *identifier, int *value, const char *error_prefix) { if (RNA_enum_value_from_id(item, identifier, value) == 0) { - const char *enum_str= BPy_enum_as_string(item); + const char *enum_str = BPy_enum_as_string(item); PyErr_Format(PyExc_TypeError, "%s: '%.200s' not found in (%s)", error_prefix, identifier, enum_str); @@ -745,34 +745,34 @@ int pyrna_enum_value_from_id(EnumPropertyItem *item, const char *identifier, int static int pyrna_struct_compare(BPy_StructRNA *a, BPy_StructRNA *b) { - return (a->ptr.data==b->ptr.data) ? 0 : -1; + return (a->ptr.data == b->ptr.data) ? 0 : -1; } static int pyrna_prop_compare(BPy_PropertyRNA *a, BPy_PropertyRNA *b) { - return (a->prop==b->prop && a->ptr.data==b->ptr.data) ? 0 : -1; + return (a->prop == b->prop && a->ptr.data == b->ptr.data) ? 0 : -1; } static PyObject *pyrna_struct_richcmp(PyObject *a, PyObject *b, int op) { PyObject *res; - int ok= -1; /* zero is true */ + int ok = -1; /* zero is true */ if (BPy_StructRNA_Check(a) && BPy_StructRNA_Check(b)) - ok= pyrna_struct_compare((BPy_StructRNA *)a, (BPy_StructRNA *)b); + ok = pyrna_struct_compare((BPy_StructRNA *)a, (BPy_StructRNA *)b); switch (op) { case Py_NE: - ok= !ok; /* pass through */ + ok = !ok; /* pass through */ case Py_EQ: - res= ok ? Py_False : Py_True; + res = ok ? Py_False : Py_True; break; case Py_LT: case Py_LE: case Py_GT: case Py_GE: - res= Py_NotImplemented; + res = Py_NotImplemented; break; default: PyErr_BadArgument(); @@ -785,23 +785,23 @@ static PyObject *pyrna_struct_richcmp(PyObject *a, PyObject *b, int op) static PyObject *pyrna_prop_richcmp(PyObject *a, PyObject *b, int op) { PyObject *res; - int ok= -1; /* zero is true */ + int ok = -1; /* zero is true */ if (BPy_PropertyRNA_Check(a) && BPy_PropertyRNA_Check(b)) - ok= pyrna_prop_compare((BPy_PropertyRNA *)a, (BPy_PropertyRNA *)b); + ok = pyrna_prop_compare((BPy_PropertyRNA *)a, (BPy_PropertyRNA *)b); switch (op) { case Py_NE: - ok= !ok; /* pass through */ + ok = !ok; /* pass through */ case Py_EQ: - res= ok ? Py_False : Py_True; + res = ok ? Py_False : Py_True; break; case Py_LT: case Py_LE: case Py_GT: case Py_GE: - res= Py_NotImplemented; + res = Py_NotImplemented; break; default: PyErr_BadArgument(); @@ -823,9 +823,9 @@ static PyObject *pyrna_struct_str(BPy_StructRNA *self) } /* print name if available */ - name= RNA_struct_name_get_alloc(&self->ptr, NULL, 0, NULL); + name = RNA_struct_name_get_alloc(&self->ptr, NULL, 0, NULL); if (name) { - ret= PyUnicode_FromFormat("<bpy_struct, %.200s(\"%.200s\")>", + ret = PyUnicode_FromFormat("<bpy_struct, %.200s(\"%.200s\")>", RNA_struct_identifier(self->ptr.type), name); MEM_freeN((void *)name); @@ -839,32 +839,32 @@ static PyObject *pyrna_struct_str(BPy_StructRNA *self) static PyObject *pyrna_struct_repr(BPy_StructRNA *self) { - ID *id= self->ptr.id.data; + ID *id = self->ptr.id.data; PyObject *tmp_str; PyObject *ret; if (id == NULL || !PYRNA_STRUCT_IS_VALID(self)) return pyrna_struct_str(self); /* fallback */ - tmp_str= PyUnicode_FromString(id->name+2); + tmp_str = PyUnicode_FromString(id->name + 2); if (RNA_struct_is_ID(self->ptr.type)) { - ret= PyUnicode_FromFormat("bpy.data.%s[%R]", + ret = PyUnicode_FromFormat("bpy.data.%s[%R]", BKE_idcode_to_name_plural(GS(id->name)), tmp_str); } else { const char *path; - path= RNA_path_from_ID_to_struct(&self->ptr); + path = RNA_path_from_ID_to_struct(&self->ptr); if (path) { - ret= PyUnicode_FromFormat("bpy.data.%s[%R].%s", + ret = PyUnicode_FromFormat("bpy.data.%s[%R].%s", BKE_idcode_to_name_plural(GS(id->name)), tmp_str, path); MEM_freeN((void *)path); } else { /* cant find, print something sane */ - ret= PyUnicode_FromFormat("bpy.data.%s[%R]...%s", + ret = PyUnicode_FromFormat("bpy.data.%s[%R]...%s", BKE_idcode_to_name_plural(GS(id->name)), tmp_str, RNA_struct_identifier(self->ptr.type)); @@ -881,30 +881,30 @@ static PyObject *pyrna_prop_str(BPy_PropertyRNA *self) PyObject *ret; PointerRNA ptr; const char *name; - const char *type_id= NULL; - char type_fmt[64]= ""; + const char *type_id = NULL; + char type_fmt[64] = ""; int type; PYRNA_PROP_CHECK_OBJ(self); - type= RNA_property_type(self->prop); + type = RNA_property_type(self->prop); - if (RNA_enum_id_from_value(property_type_items, type, &type_id)==0) { + if (RNA_enum_id_from_value(property_type_items, type, &type_id) == 0) { PyErr_SetString(PyExc_RuntimeError, "could not use property type, internal error"); /* should never happen */ return NULL; } else { /* this should never fail */ - int len= -1; - char *c= type_fmt; + int len = -1; + char *c = type_fmt; while ((*c++= tolower(*type_id++))) {} ; - if (type==PROP_COLLECTION) { - len= pyrna_prop_collection_length(self); + if (type == PROP_COLLECTION) { + len = pyrna_prop_collection_length(self); } else if (RNA_property_array_check(self->prop)) { - len= pyrna_prop_array_length((BPy_PropertyArrayRNA *)self); + len = pyrna_prop_array_length((BPy_PropertyArrayRNA *)self); } if (len != -1) @@ -913,11 +913,11 @@ static PyObject *pyrna_prop_str(BPy_PropertyRNA *self) /* if a pointer, try to print name of pointer target too */ if (type == PROP_POINTER) { - ptr= RNA_property_pointer_get(&self->ptr, self->prop); - name= RNA_struct_name_get_alloc(&ptr, NULL, 0, NULL); + ptr = RNA_property_pointer_get(&self->ptr, self->prop); + name = RNA_struct_name_get_alloc(&ptr, NULL, 0, NULL); if (name) { - ret= PyUnicode_FromFormat("<bpy_%.200s, %.200s.%.200s(\"%.200s\")>", + ret = PyUnicode_FromFormat("<bpy_%.200s, %.200s.%.200s(\"%.200s\")>", type_fmt, RNA_struct_identifier(self->ptr.type), RNA_property_identifier(self->prop), @@ -943,7 +943,7 @@ static PyObject *pyrna_prop_str(BPy_PropertyRNA *self) static PyObject *pyrna_prop_repr(BPy_PropertyRNA *self) { - ID *id= self->ptr.id.data; + ID *id = self->ptr.id.data; PyObject *tmp_str; PyObject *ret; const char *path; @@ -953,18 +953,18 @@ static PyObject *pyrna_prop_repr(BPy_PropertyRNA *self) if (id == NULL) return pyrna_prop_str(self); /* fallback */ - tmp_str= PyUnicode_FromString(id->name+2); + tmp_str = PyUnicode_FromString(id->name + 2); - path= RNA_path_from_ID_to_property(&self->ptr, self->prop); + path = RNA_path_from_ID_to_property(&self->ptr, self->prop); if (path) { - ret= PyUnicode_FromFormat("bpy.data.%s[%R].%s", + ret = PyUnicode_FromFormat("bpy.data.%s[%R].%s", BKE_idcode_to_name_plural(GS(id->name)), tmp_str, path); MEM_freeN((void *)path); } else { /* cant find, print something sane */ - ret= PyUnicode_FromFormat("bpy.data.%s[%R]...%s", + ret = PyUnicode_FromFormat("bpy.data.%s[%R]...%s", BKE_idcode_to_name_plural(GS(id->name)), tmp_str, RNA_property_identifier(self->prop)); @@ -995,18 +995,18 @@ static long pyrna_prop_hash(BPy_PropertyRNA *self) { long x, y; if (self->ptr.data == NULL) - x= 0; + x = 0; else { - x= _Py_HashPointer(self->ptr.data); + x = _Py_HashPointer(self->ptr.data); if (x == -1) return -1; } - y= _Py_HashPointer((void*)(self->prop)); + y = _Py_HashPointer((void *)(self->prop)); if (y == -1) return -1; x ^= y; if (x == -1) - x= -2; + x = -2; return x; } @@ -1031,7 +1031,7 @@ static void pyrna_struct_dealloc(BPy_StructRNA *self) if (self->freeptr && self->ptr.data) { IDP_FreeProperty(self->ptr.data); MEM_freeN(self->ptr.data); - self->ptr.data= NULL; + self->ptr.data = NULL; } #endif /* PYRNA_FREE_SUPPORT */ @@ -1056,15 +1056,15 @@ static void pyrna_struct_dealloc(BPy_StructRNA *self) static void pyrna_struct_reference_set(BPy_StructRNA *self, PyObject *reference) { if (self->reference) { -// PyObject_GC_UnTrack(self); /* INITIALIZED TRACKED? */ +// PyObject_GC_UnTrack(self); /* INITIALIZED TRACKED ? */ pyrna_struct_clear(self); } /* reference is now NULL */ if (reference) { - self->reference= reference; + self->reference = reference; Py_INCREF(reference); -// PyObject_GC_Track(self); /* INITIALIZED TRACKED? */ +// PyObject_GC_Track(self); /* INITIALIZED TRACKED ? */ } } #endif /* !USE_PYRNA_STRUCT_REFERENCE */ @@ -1096,14 +1096,14 @@ static const char *pyrna_enum_as_string(PointerRNA *ptr, PropertyRNA *prop) { EnumPropertyItem *item; const char *result; - int free= FALSE; + int free = FALSE; RNA_property_enum_items(BPy_GetContext(), ptr, prop, &item, NULL, &free); if (item) { - result= BPy_enum_as_string(item); + result = BPy_enum_as_string(item); } else { - result= ""; + result = ""; } if (free) @@ -1115,10 +1115,10 @@ static const char *pyrna_enum_as_string(PointerRNA *ptr, PropertyRNA *prop) static int pyrna_string_to_enum(PyObject *item, PointerRNA *ptr, PropertyRNA *prop, int *val, const char *error_prefix) { - const char *param= _PyUnicode_AsString(item); + const char *param = _PyUnicode_AsString(item); - if (param==NULL) { - const char *enum_str= pyrna_enum_as_string(ptr, prop); + if (param == NULL) { + const char *enum_str = pyrna_enum_as_string(ptr, prop); PyErr_Format(PyExc_TypeError, "%.200s expected a string enum type in (%.200s)", error_prefix, enum_str); @@ -1131,7 +1131,7 @@ static int pyrna_string_to_enum(PyObject *item, PointerRNA *ptr, PropertyRNA *pr RNA_def_property_clear_flag(prop, PROP_ENUM_NO_CONTEXT); if (!RNA_property_enum_value(BPy_GetContext(), ptr, prop, param, val)) { - const char *enum_str= pyrna_enum_as_string(ptr, prop); + const char *enum_str = pyrna_enum_as_string(ptr, prop); PyErr_Format(PyExc_TypeError, "%.200s enum \"%.200s\" not found in (%.200s)", error_prefix, param, enum_str); @@ -1147,19 +1147,19 @@ static int pyrna_string_to_enum(PyObject *item, PointerRNA *ptr, PropertyRNA *pr int pyrna_set_to_enum_bitfield(EnumPropertyItem *items, PyObject *value, int *r_value, const char *error_prefix) { /* set of enum items, concatenate all values with OR */ - int ret, flag= 0; + int ret, flag = 0; /* set looping */ - Py_ssize_t pos= 0; - Py_ssize_t hash= 0; + Py_ssize_t pos = 0; + Py_ssize_t hash = 0; PyObject *key; - *r_value= 0; + *r_value = 0; while (_PySet_NextEntry(value, &pos, &key, &hash)) { - const char *param= _PyUnicode_AsString(key); + const char *param = _PyUnicode_AsString(key); - if (param==NULL) { + if (param == NULL) { PyErr_Format(PyExc_TypeError, "%.200s expected a string, not %.200s", error_prefix, Py_TYPE(key)->tp_name); @@ -1173,7 +1173,7 @@ int pyrna_set_to_enum_bitfield(EnumPropertyItem *items, PyObject *value, int *r_ flag |= ret; } - *r_value= flag; + *r_value = flag; return 0; } @@ -1181,9 +1181,9 @@ static int pyrna_prop_to_enum_bitfield(PointerRNA *ptr, PropertyRNA *prop, PyObj { EnumPropertyItem *item; int ret; - int free= FALSE; + int free = FALSE; - *r_value= 0; + *r_value = 0; if (!PyAnySet_Check(value)) { PyErr_Format(PyExc_TypeError, @@ -1196,17 +1196,17 @@ static int pyrna_prop_to_enum_bitfield(PointerRNA *ptr, PropertyRNA *prop, PyObj RNA_property_enum_items(BPy_GetContext(), ptr, prop, &item, NULL, &free); if (item) { - ret= pyrna_set_to_enum_bitfield(item, value, r_value, error_prefix); + ret = pyrna_set_to_enum_bitfield(item, value, r_value, error_prefix); } else { if (PySet_GET_SIZE(value)) { PyErr_Format(PyExc_TypeError, "%.200s: empty enum \"%.200s\" could not have any values assigned", error_prefix, RNA_property_identifier(prop)); - ret= -1; + ret = -1; } else { - ret= 0; + ret = 0; } } @@ -1218,14 +1218,14 @@ static int pyrna_prop_to_enum_bitfield(PointerRNA *ptr, PropertyRNA *prop, PyObj PyObject *pyrna_enum_bitfield_to_py(EnumPropertyItem *items, int value) { - PyObject *ret= PySet_New(NULL); + PyObject *ret = PySet_New(NULL); const char *identifier[RNA_ENUM_BITFLAG_SIZE + 1]; if (RNA_enum_bitflag_identifiers(items, value, identifier)) { PyObject *item; int index; - for (index=0; identifier[index]; index++) { - item= PyUnicode_FromString(identifier[index]); + for (index = 0; identifier[index]; index++) { + item = PyUnicode_FromString(identifier[index]); PySet_Add(ret, item); Py_DECREF(item); } @@ -1236,18 +1236,18 @@ PyObject *pyrna_enum_bitfield_to_py(EnumPropertyItem *items, int value) static PyObject *pyrna_enum_to_py(PointerRNA *ptr, PropertyRNA *prop, int val) { - PyObject *item, *ret= NULL; + PyObject *item, *ret = NULL; if (RNA_property_flag(prop) & PROP_ENUM_FLAG) { const char *identifier[RNA_ENUM_BITFLAG_SIZE + 1]; - ret= PySet_New(NULL); + ret = PySet_New(NULL); if (RNA_property_enum_bitflag_identifiers(BPy_GetContext(), ptr, prop, val, identifier)) { int index; - for (index=0; identifier[index]; index++) { - item= PyUnicode_FromString(identifier[index]); + for (index = 0; identifier[index]; index++) { + item = PyUnicode_FromString(identifier[index]); PySet_Add(ret, item); Py_DECREF(item); } @@ -1257,20 +1257,20 @@ static PyObject *pyrna_enum_to_py(PointerRNA *ptr, PropertyRNA *prop, int val) else { const char *identifier; if (RNA_property_enum_identifier(BPy_GetContext(), ptr, prop, val, &identifier)) { - ret= PyUnicode_FromString(identifier); + ret = PyUnicode_FromString(identifier); } else { EnumPropertyItem *enum_item; - int free= FALSE; + int free = FALSE; /* don't throw error here, can't trust blender 100% to give the * right values, python code should not generate error for that */ RNA_property_enum_items(BPy_GetContext(), ptr, prop, &enum_item, NULL, &free); if (enum_item && enum_item->identifier) { - ret= PyUnicode_FromString(enum_item->identifier); + ret = PyUnicode_FromString(enum_item->identifier); } else { - const char *ptr_name= RNA_struct_name_get_alloc(ptr, NULL, 0, NULL); + const char *ptr_name = RNA_struct_name_get_alloc(ptr, NULL, 0, NULL); /* prefer not fail silently incase of api errors, maybe disable it later */ printf("RNA Warning: Current value \"%d\" " @@ -1292,7 +1292,7 @@ static PyObject *pyrna_enum_to_py(PointerRNA *ptr, PropertyRNA *prop, int val) if (ptr_name) MEM_freeN((void *)ptr_name); - ret= PyUnicode_FromString(""); + ret = PyUnicode_FromString(""); } if (free) @@ -1300,7 +1300,7 @@ static PyObject *pyrna_enum_to_py(PointerRNA *ptr, PropertyRNA *prop, int val) /* PyErr_Format(PyExc_AttributeError, "RNA Error: Current value \"%d\" matches no enum", val); - ret= NULL; + ret = NULL; */ } } @@ -1311,7 +1311,7 @@ static PyObject *pyrna_enum_to_py(PointerRNA *ptr, PropertyRNA *prop, int val) PyObject *pyrna_prop_to_py(PointerRNA *ptr, PropertyRNA *prop) { PyObject *ret; - const int type= RNA_property_type(prop); + const int type = RNA_property_type(prop); if (RNA_property_array_check(prop)) { return pyrna_py_from_array(ptr, prop); @@ -1320,39 +1320,39 @@ PyObject *pyrna_prop_to_py(PointerRNA *ptr, PropertyRNA *prop) /* see if we can coorce into a python type - PropertyType */ switch (type) { case PROP_BOOLEAN: - ret= PyBool_FromLong(RNA_property_boolean_get(ptr, prop)); + ret = PyBool_FromLong(RNA_property_boolean_get(ptr, prop)); break; case PROP_INT: - ret= PyLong_FromSsize_t((Py_ssize_t)RNA_property_int_get(ptr, prop)); + ret = PyLong_FromSsize_t((Py_ssize_t)RNA_property_int_get(ptr, prop)); break; case PROP_FLOAT: - ret= PyFloat_FromDouble(RNA_property_float_get(ptr, prop)); + ret = PyFloat_FromDouble(RNA_property_float_get(ptr, prop)); break; case PROP_STRING: { - const int subtype= RNA_property_subtype(prop); + const int subtype = RNA_property_subtype(prop); const char *buf; int buf_len; char buf_fixed[32]; - buf= RNA_property_string_get_alloc(ptr, prop, buf_fixed, sizeof(buf_fixed), &buf_len); + buf = RNA_property_string_get_alloc(ptr, prop, buf_fixed, sizeof(buf_fixed), &buf_len); #ifdef USE_STRING_COERCE /* only file paths get special treatment, they may contain non utf-8 chars */ if (subtype == PROP_BYTESTRING) { - ret= PyBytes_FromStringAndSize(buf, buf_len); + ret = PyBytes_FromStringAndSize(buf, buf_len); } else if (ELEM3(subtype, PROP_FILEPATH, PROP_DIRPATH, PROP_FILENAME)) { - ret= PyC_UnicodeFromByteAndSize(buf, buf_len); + ret = PyC_UnicodeFromByteAndSize(buf, buf_len); } else { - ret= PyUnicode_FromStringAndSize(buf, buf_len); + ret = PyUnicode_FromStringAndSize(buf, buf_len); } #else // USE_STRING_COERCE if (subtype == PROP_BYTESTRING) { - ret= PyBytes_FromStringAndSize(buf, buf_len); + ret = PyBytes_FromStringAndSize(buf, buf_len); } else { - ret= PyUnicode_FromStringAndSize(buf, buf_len); + ret = PyUnicode_FromStringAndSize(buf, buf_len); } #endif // USE_STRING_COERCE if (buf_fixed != buf) { @@ -1362,29 +1362,29 @@ PyObject *pyrna_prop_to_py(PointerRNA *ptr, PropertyRNA *prop) } case PROP_ENUM: { - ret= pyrna_enum_to_py(ptr, prop, RNA_property_enum_get(ptr, prop)); + ret = pyrna_enum_to_py(ptr, prop, RNA_property_enum_get(ptr, prop)); break; } case PROP_POINTER: { PointerRNA newptr; - newptr= RNA_property_pointer_get(ptr, prop); + newptr = RNA_property_pointer_get(ptr, prop); if (newptr.data) { - ret= pyrna_struct_CreatePyObject(&newptr); + ret = pyrna_struct_CreatePyObject(&newptr); } else { - ret= Py_None; + ret = Py_None; Py_INCREF(ret); } break; } case PROP_COLLECTION: - ret= pyrna_prop_CreatePyObject(ptr, prop); + ret = pyrna_prop_CreatePyObject(ptr, prop); break; default: PyErr_Format(PyExc_TypeError, "bpy_struct internal error: unknown type '%d' (pyrna_prop_to_py)", type); - ret= NULL; + ret = NULL; break; } @@ -1395,40 +1395,40 @@ PyObject *pyrna_prop_to_py(PointerRNA *ptr, PropertyRNA *prop) * Its takes keyword args and fills them with property values */ int pyrna_pydict_to_props(PointerRNA *ptr, PyObject *kw, int all_args, const char *error_prefix) { - int error_val= 0; + int error_val = 0; int totkw; - const char *arg_name= NULL; + const char *arg_name = NULL; PyObject *item; - totkw= kw ? PyDict_Size(kw):0; + totkw = kw ? PyDict_Size(kw):0; RNA_STRUCT_BEGIN(ptr, prop) { - arg_name= RNA_property_identifier(prop); + arg_name = RNA_property_identifier(prop); - if (strcmp(arg_name, "rna_type")==0) continue; + if (strcmp(arg_name, "rna_type") == 0) continue; - if (kw==NULL) { + if (kw == NULL) { PyErr_Format(PyExc_TypeError, "%.200s: no keywords, expected \"%.200s\"", error_prefix, arg_name ? arg_name : "<UNKNOWN>"); - error_val= -1; + error_val = -1; break; } - item= PyDict_GetItemString(kw, arg_name); /* wont set an error */ + item = PyDict_GetItemString(kw, arg_name); /* wont set an error */ if (item == NULL) { if (all_args) { PyErr_Format(PyExc_TypeError, "%.200s: keyword \"%.200s\" missing", error_prefix, arg_name ? arg_name : "<UNKNOWN>"); - error_val= -1; /* pyrna_py_to_prop sets the error */ + error_val = -1; /* pyrna_py_to_prop sets the error */ break; } } else { if (pyrna_py_to_prop(ptr, prop, NULL, item, error_prefix)) { - error_val= -1; + error_val = -1; break; } totkw--; @@ -1436,20 +1436,20 @@ int pyrna_pydict_to_props(PointerRNA *ptr, PyObject *kw, int all_args, const cha } RNA_STRUCT_END; - if (error_val==0 && totkw > 0) { /* some keywords were given that were not used :/ */ + if (error_val == 0 && totkw > 0) { /* some keywords were given that were not used :/ */ PyObject *key, *value; - Py_ssize_t pos= 0; + Py_ssize_t pos = 0; while (PyDict_Next(kw, &pos, &key, &value)) { - arg_name= _PyUnicode_AsString(key); + arg_name = _PyUnicode_AsString(key); if (RNA_struct_find_property(ptr, arg_name) == NULL) break; - arg_name= NULL; + arg_name = NULL; } PyErr_Format(PyExc_TypeError, "%.200s: keyword \"%.200s\" unrecognized", error_prefix, arg_name ? arg_name : "<UNKNOWN>"); - error_val= -1; + error_val = -1; } return error_val; @@ -1458,9 +1458,9 @@ int pyrna_pydict_to_props(PointerRNA *ptr, PyObject *kw, int all_args, const cha static PyObject *pyrna_func_to_py(PointerRNA *ptr, FunctionRNA *func) { - BPy_FunctionRNA* pyfunc= (BPy_FunctionRNA *) PyObject_NEW(BPy_FunctionRNA, &pyrna_func_Type); - pyfunc->ptr= *ptr; - pyfunc->func= func; + BPy_FunctionRNA* pyfunc = (BPy_FunctionRNA *) PyObject_NEW(BPy_FunctionRNA, &pyrna_func_Type); + pyfunc->ptr = *ptr; + pyfunc->func = func; return (PyObject *)pyfunc; } @@ -1468,7 +1468,7 @@ static PyObject *pyrna_func_to_py(PointerRNA *ptr, FunctionRNA *func) static int pyrna_py_to_prop(PointerRNA *ptr, PropertyRNA *prop, void *data, PyObject *value, const char *error_prefix) { /* XXX hard limits should be checked here */ - const int type= RNA_property_type(prop); + const int type = RNA_property_type(prop); if (RNA_property_array_check(prop)) { @@ -1489,9 +1489,9 @@ static int pyrna_py_to_prop(PointerRNA *ptr, PropertyRNA *prop, void *data, PyOb * however so many poll functions return None or a valid Object. * its a hassle to convert these into a bool before returning, */ if (RNA_property_flag(prop) & PROP_OUTPUT) - param= PyObject_IsTrue(value); + param = PyObject_IsTrue(value); else - param= PyLong_AsLong(value); + param = PyLong_AsLong(value); if (param < 0) { PyErr_Format(PyExc_TypeError, @@ -1501,7 +1501,7 @@ static int pyrna_py_to_prop(PointerRNA *ptr, PropertyRNA *prop, void *data, PyOb return -1; } else { - if (data) *((int*)data)= param; + if (data) *((int *)data)= param; else RNA_property_boolean_set(ptr, prop, param); } break; @@ -1509,7 +1509,7 @@ static int pyrna_py_to_prop(PointerRNA *ptr, PropertyRNA *prop, void *data, PyOb case PROP_INT: { int overflow; - long param= PyLong_AsLongAndOverflow(value, &overflow); + long param = PyLong_AsLongAndOverflow(value, &overflow); if (overflow || (param > INT_MAX) || (param < INT_MIN)) { PyErr_Format(PyExc_ValueError, "%.200s %.200s.%.200s value not in 'int' range " @@ -1518,7 +1518,7 @@ static int pyrna_py_to_prop(PointerRNA *ptr, PropertyRNA *prop, void *data, PyOb RNA_property_identifier(prop)); return -1; } - else if (param==-1 && PyErr_Occurred()) { + else if (param == -1 && PyErr_Occurred()) { PyErr_Format(PyExc_TypeError, "%.200s %.200s.%.200s expected an int type, not %.200s", error_prefix, RNA_struct_identifier(ptr->type), @@ -1526,16 +1526,16 @@ static int pyrna_py_to_prop(PointerRNA *ptr, PropertyRNA *prop, void *data, PyOb return -1; } else { - int param_i= (int)param; + int param_i = (int)param; RNA_property_int_clamp(ptr, prop, ¶m_i); - if (data) *((int*)data)= param_i; + if (data) *((int *)data)= param_i; else RNA_property_int_set(ptr, prop, param_i); } break; } case PROP_FLOAT: { - float param= PyFloat_AsDouble(value); + float param = PyFloat_AsDouble(value); if (PyErr_Occurred()) { PyErr_Format(PyExc_TypeError, "%.200s %.200s.%.200s expected a float type, not %.200s", @@ -1545,23 +1545,23 @@ static int pyrna_py_to_prop(PointerRNA *ptr, PropertyRNA *prop, void *data, PyOb } else { RNA_property_float_clamp(ptr, prop, (float *)¶m); - if (data) *((float*)data)= param; + if (data) *((float *)data)= param; else RNA_property_float_set(ptr, prop, param); } break; } case PROP_STRING: { - const int subtype= RNA_property_subtype(prop); + const int subtype = RNA_property_subtype(prop); const char *param; if (subtype == PROP_BYTESTRING) { /* Byte String */ - param= PyBytes_AsString(value); + param = PyBytes_AsString(value); - if (param==NULL) { + if (param == NULL) { if (PyBytes_Check(value)) { /* there was an error assigning a string type, * rather than setting a new error, prefix the existing one @@ -1582,7 +1582,7 @@ static int pyrna_py_to_prop(PointerRNA *ptr, PropertyRNA *prop, void *data, PyOb } else { /* same as unicode */ - if (data) *((char**)data)= (char *)param; /*XXX, this is suspect but needed for function calls, need to see if theres a better way */ + if (data) *((char **)data)= (char *)param; /*XXX, this is suspect but needed for function calls, need to see if theres a better way */ else RNA_property_string_set(ptr, prop, param); } } @@ -1591,25 +1591,25 @@ static int pyrna_py_to_prop(PointerRNA *ptr, PropertyRNA *prop, void *data, PyOb /* Unicode String */ #ifdef USE_STRING_COERCE - PyObject *value_coerce= NULL; + PyObject *value_coerce = NULL; if (ELEM3(subtype, PROP_FILEPATH, PROP_DIRPATH, PROP_FILENAME)) { /* TODO, get size */ - param= PyC_UnicodeAsByte(value, &value_coerce); + param = PyC_UnicodeAsByte(value, &value_coerce); } else { - param= _PyUnicode_AsString(value); + param = _PyUnicode_AsString(value); #ifdef WITH_INTERNATIONAL if (subtype == PROP_TRANSLATE) { - param= IFACE_(param); + param = IFACE_(param); } #endif // WITH_INTERNATIONAL } #else // USE_STRING_COERCE - param= _PyUnicode_AsString(value); + param = _PyUnicode_AsString(value); #endif // USE_STRING_COERCE - if (param==NULL) { + if (param == NULL) { if (PyUnicode_Check(value)) { /* there was an error assigning a string type, * rather than setting a new error, prefix the existing one @@ -1630,7 +1630,7 @@ static int pyrna_py_to_prop(PointerRNA *ptr, PropertyRNA *prop, void *data, PyOb } else { /* same as bytes */ - if (data) *((char**)data)= (char *)param; /*XXX, this is suspect but needed for function calls, need to see if theres a better way */ + if (data) *((char **)data)= (char *)param; /*XXX, this is suspect but needed for function calls, need to see if theres a better way */ else RNA_property_string_set(ptr, prop, param); } #ifdef USE_STRING_COERCE @@ -1641,7 +1641,7 @@ static int pyrna_py_to_prop(PointerRNA *ptr, PropertyRNA *prop, void *data, PyOb } case PROP_ENUM: { - int val= 0; + int val = 0; /* type checkins is done by each function */ if (RNA_property_flag(prop) & PROP_ENUM_FLAG) { @@ -1657,17 +1657,17 @@ static int pyrna_py_to_prop(PointerRNA *ptr, PropertyRNA *prop, void *data, PyOb } } - if (data) *((int*)data)= val; + if (data) *((int *)data)= val; else RNA_property_enum_set(ptr, prop, val); break; } case PROP_POINTER: { - PyObject *value_new= NULL; + PyObject *value_new = NULL; - StructRNA *ptr_type= RNA_property_pointer_type(ptr, prop); - int flag= RNA_property_flag(prop); + StructRNA *ptr_type = RNA_property_pointer_type(ptr, prop); + int flag = RNA_property_flag(prop); /* this is really nasty!, so we can fake the operator having direct properties eg: * layout.prop(self, "filepath") @@ -1675,7 +1675,8 @@ static int pyrna_py_to_prop(PointerRNA *ptr, PropertyRNA *prop, void *data, PyOb * layout.prop(self.properties, "filepath") * * we need to do this trick. - * if the prop is not an operator type and the pyobject is an operator, use its properties in place of its self. + * if the prop is not an operator type and the pyobject is an operator, + * use its properties in place of its self. * * this is so bad that its almost a good reason to do away with fake 'self.properties -> self' class mixing * if this causes problems in the future it should be removed. @@ -1684,24 +1685,25 @@ static int pyrna_py_to_prop(PointerRNA *ptr, PropertyRNA *prop, void *data, PyOb (BPy_StructRNA_Check(value)) && (RNA_struct_is_a(((BPy_StructRNA *)value)->ptr.type, &RNA_Operator)) ) { - value= PyObject_GetAttrString(value, "properties"); - value_new= value; + value = PyObject_GetAttrString(value, "properties"); + value_new = value; } - /* if property is an OperatorProperties pointer and value is a map, forward back to pyrna_pydict_to_props */ + /* if property is an OperatorProperties pointer and value is a map, + * forward back to pyrna_pydict_to_props */ if (RNA_struct_is_a(ptr_type, &RNA_OperatorProperties) && PyDict_Check(value)) { - PointerRNA opptr= RNA_property_pointer_get(ptr, prop); + PointerRNA opptr = RNA_property_pointer_get(ptr, prop); return pyrna_pydict_to_props(&opptr, value, 0, error_prefix); } /* another exception, allow to pass a collection as an RNA property */ - if (Py_TYPE(value)==&pyrna_prop_collection_Type) { /* ok to ignore idprop collections */ + if (Py_TYPE(value) == &pyrna_prop_collection_Type) { /* ok to ignore idprop collections */ PointerRNA c_ptr; - BPy_PropertyRNA *value_prop= (BPy_PropertyRNA *)value; + BPy_PropertyRNA *value_prop = (BPy_PropertyRNA *)value; if (RNA_property_collection_type_get(&value_prop->ptr, value_prop->prop, &c_ptr)) { - value= pyrna_struct_CreatePyObject(&c_ptr); - value_new= value; + value = pyrna_struct_CreatePyObject(&c_ptr); + value_new = value; } else { PyErr_Format(PyExc_TypeError, @@ -1728,7 +1730,9 @@ static int pyrna_py_to_prop(PointerRNA *ptr, PropertyRNA *prop, void *data, PyOb RNA_property_identifier(prop), RNA_struct_identifier(ptr_type)); Py_XDECREF(value_new); return -1; } - else if (value != Py_None && ((flag & PROP_ID_SELF_CHECK) && ptr->id.data == ((BPy_StructRNA*)value)->ptr.id.data)) { + else if ((value != Py_None) && + ((flag & PROP_ID_SELF_CHECK) && ptr->id.data == ((BPy_StructRNA *)value)->ptr.id.data)) + { PyErr_Format(PyExc_TypeError, "%.200s %.200s.%.200s ID type does not support assignment to its self", error_prefix, RNA_struct_identifier(ptr->type), @@ -1736,30 +1740,30 @@ static int pyrna_py_to_prop(PointerRNA *ptr, PropertyRNA *prop, void *data, PyOb Py_XDECREF(value_new); return -1; } else { - BPy_StructRNA *param= (BPy_StructRNA*)value; - int raise_error= FALSE; + BPy_StructRNA *param = (BPy_StructRNA *)value; + int raise_error = FALSE; if (data) { if (flag & PROP_RNAPTR) { if (value == Py_None) memset(data, 0, sizeof(PointerRNA)); else - *((PointerRNA*)data)= param->ptr; + *((PointerRNA *)data)= param->ptr; } else if (value == Py_None) { - *((void**)data)= NULL; + *((void **)data)= NULL; } else if (RNA_struct_is_a(param->ptr.type, ptr_type)) { - *((void**)data)= param->ptr.data; + *((void **)data)= param->ptr.data; } else { - raise_error= TRUE; + raise_error = TRUE; } } else { - /* data==NULL, assign to RNA */ + /* data == NULL, assign to RNA */ if (value == Py_None) { - PointerRNA valueptr= {{NULL}}; + PointerRNA valueptr = {{NULL}}; RNA_property_pointer_set(ptr, prop, valueptr); } else if (RNA_struct_is_a(param->ptr.type, ptr_type)) { @@ -1801,7 +1805,7 @@ static int pyrna_py_to_prop(PointerRNA *ptr, PropertyRNA *prop, void *data, PyOb ListBase *lb; CollectionPointerLink *link; - lb= (data)? (ListBase*)data: NULL; + lb = (data) ? (ListBase *)data : NULL; /* convert a sequence of dict's into a collection */ if (!PySequence_Check(value)) { @@ -1812,11 +1816,11 @@ static int pyrna_py_to_prop(PointerRNA *ptr, PropertyRNA *prop, void *data, PyOb return -1; } - seq_len= PySequence_Size(value); - for (i=0; i < seq_len; i++) { - item= PySequence_GetItem(value, i); + seq_len = PySequence_Size(value); + for (i = 0; i < seq_len; i++) { + item = PySequence_GetItem(value, i); - if (item==NULL) { + if (item == NULL) { PyErr_Format(PyExc_TypeError, "%.200s %.200s.%.200s failed to get sequence index '%d' for an RNA collection", error_prefix, RNA_struct_identifier(ptr->type), @@ -1825,7 +1829,7 @@ static int pyrna_py_to_prop(PointerRNA *ptr, PropertyRNA *prop, void *data, PyOb return -1; } - if (PyDict_Check(item)==0) { + if (PyDict_Check(item) == 0) { PyErr_Format(PyExc_TypeError, "%.200s %.200s.%.200s expected a each sequence " "member to be a dict for an RNA collection, not %.200s", @@ -1836,16 +1840,16 @@ static int pyrna_py_to_prop(PointerRNA *ptr, PropertyRNA *prop, void *data, PyOb } if (lb) { - link= MEM_callocN(sizeof(CollectionPointerLink), "PyCollectionPointerLink"); - link->ptr= itemptr; + link = MEM_callocN(sizeof(CollectionPointerLink), "PyCollectionPointerLink"); + link->ptr = itemptr; BLI_addtail(lb, link); } else RNA_property_collection_add(ptr, prop, &itemptr); - if (pyrna_pydict_to_props(&itemptr, item, 1, "Converting a python list to an RNA collection")==-1) { - PyObject *msg= PyC_ExceptionBuffer(); - const char *msg_char= _PyUnicode_AsString(msg); + if (pyrna_pydict_to_props(&itemptr, item, 1, "Converting a python list to an RNA collection") == -1) { + PyObject *msg = PyC_ExceptionBuffer(); + const char *msg_char = _PyUnicode_AsString(msg); PyErr_Format(PyExc_TypeError, "%.200s %.200s.%.200s error converting a member of a collection " @@ -1888,17 +1892,17 @@ static PyObject *pyrna_prop_array_to_py_index(BPy_PropertyArrayRNA *self, int in static int pyrna_py_to_prop_array_index(BPy_PropertyArrayRNA *self, int index, PyObject *value) { - int ret= 0; - PointerRNA *ptr= &self->ptr; - PropertyRNA *prop= self->prop; + int ret = 0; + PointerRNA *ptr = &self->ptr; + PropertyRNA *prop = self->prop; - const int totdim= RNA_property_array_dimension(ptr, prop, NULL); + const int totdim = RNA_property_array_dimension(ptr, prop, NULL); if (totdim > 1) { /* char error_str[512]; */ if (pyrna_py_to_array_index(&self->ptr, self->prop, self->arraydim, self->arrayoffset, index, value, "") == -1) { /* error is set */ - ret= -1; + ret = -1; } } else { @@ -1906,11 +1910,11 @@ static int pyrna_py_to_prop_array_index(BPy_PropertyArrayRNA *self, int index, P switch (RNA_property_type(prop)) { case PROP_BOOLEAN: { - int param= PyLong_AsLong(value); + int param = PyLong_AsLong(value); if (param < 0 || param > 1) { PyErr_SetString(PyExc_TypeError, "expected True/False or 0/1"); - ret= -1; + ret = -1; } else { RNA_property_boolean_set_index(ptr, prop, index, param); @@ -1919,10 +1923,10 @@ static int pyrna_py_to_prop_array_index(BPy_PropertyArrayRNA *self, int index, P } case PROP_INT: { - int param= PyLong_AsLong(value); - if (param==-1 && PyErr_Occurred()) { + int param = PyLong_AsLong(value); + if (param == -1 && PyErr_Occurred()) { PyErr_SetString(PyExc_TypeError, "expected an int type"); - ret= -1; + ret = -1; } else { RNA_property_int_clamp(ptr, prop, ¶m); @@ -1932,10 +1936,10 @@ static int pyrna_py_to_prop_array_index(BPy_PropertyArrayRNA *self, int index, P } case PROP_FLOAT: { - float param= PyFloat_AsDouble(value); + float param = PyFloat_AsDouble(value); if (PyErr_Occurred()) { PyErr_SetString(PyExc_TypeError, "expected a float type"); - ret= -1; + ret = -1; } else { RNA_property_float_clamp(ptr, prop, ¶m); @@ -1945,7 +1949,7 @@ static int pyrna_py_to_prop_array_index(BPy_PropertyArrayRNA *self, int index, P } default: PyErr_SetString(PyExc_AttributeError, "not an array type"); - ret= -1; + ret = -1; break; } } @@ -1994,7 +1998,7 @@ static int pyrna_prop_collection_bool(BPy_PropertyRNA *self) PYRNA_PROP_CHECK_INT(self); RNA_property_collection_begin(&self->ptr, self->prop, &iter); - test= iter.valid; + test = iter.valid; RNA_property_collection_end(&iter); return test; } @@ -2018,7 +2022,7 @@ static int pyrna_prop_collection_bool(BPy_PropertyRNA *self) static PyObject *pyrna_prop_collection_subscript_int(BPy_PropertyRNA *self, Py_ssize_t keynum) { PointerRNA newptr; - Py_ssize_t keynum_abs= keynum; + Py_ssize_t keynum_abs = keynum; PYRNA_PROP_CHECK_OBJ(self); @@ -2028,7 +2032,7 @@ static PyObject *pyrna_prop_collection_subscript_int(BPy_PropertyRNA *self, Py_s return pyrna_struct_CreatePyObject(&newptr); } else { - const int len= RNA_property_collection_length(&self->ptr, self->prop); + const int len = RNA_property_collection_length(&self->ptr, self->prop); if (keynum_abs >= len) { PyErr_Format(PyExc_IndexError, "bpy_prop_collection[index]: " @@ -2048,15 +2052,15 @@ static PyObject *pyrna_prop_collection_subscript_int(BPy_PropertyRNA *self, Py_s /* values type must have been already checked */ static int pyrna_prop_collection_ass_subscript_int(BPy_PropertyRNA *self, Py_ssize_t keynum, PyObject *value) { - Py_ssize_t keynum_abs= keynum; - const PointerRNA *ptr= (value == Py_None) ? (&PointerRNA_NULL) : &((BPy_StructRNA *)value)->ptr; + Py_ssize_t keynum_abs = keynum; + const PointerRNA *ptr = (value == Py_None) ? (&PointerRNA_NULL) : &((BPy_StructRNA *)value)->ptr; PYRNA_PROP_CHECK_INT(self); PYRNA_PROP_COLLECTION_ABS_INDEX(-1); if (RNA_property_collection_assign_int(&self->ptr, self->prop, keynum_abs, ptr) == 0) { - const int len= RNA_property_collection_length(&self->ptr, self->prop); + const int len = RNA_property_collection_length(&self->ptr, self->prop); if (keynum_abs >= len) { PyErr_Format(PyExc_IndexError, "bpy_prop_collection[index] = value: " @@ -2080,7 +2084,7 @@ static PyObject *pyrna_prop_array_subscript_int(BPy_PropertyArrayRNA *self, int PYRNA_PROP_CHECK_OBJ((BPy_PropertyRNA *)self); - len= pyrna_prop_array_length(self); + len = pyrna_prop_array_length(self); if (keynum < 0) keynum += len; @@ -2135,24 +2139,24 @@ int pyrna_prop_collection_subscript_str_lib_pair_ptr(BPy_PropertyRNA *self, PyOb err_prefix, RNA_struct_identifier(self->ptr.type)); return -1; } - else if ((keyname= _PyUnicode_AsString(PyTuple_GET_ITEM(key, 0))) == NULL) { + else if ((keyname = _PyUnicode_AsString(PyTuple_GET_ITEM(key, 0))) == NULL) { PyErr_Format(PyExc_KeyError, "%s: id must be a string, not %.200s", err_prefix, Py_TYPE(PyTuple_GET_ITEM(key, 0))->tp_name); return -1; } else { - PyObject *keylib= PyTuple_GET_ITEM(key, 1); + PyObject *keylib = PyTuple_GET_ITEM(key, 1); Library *lib; - int found= FALSE; + int found = FALSE; if (keylib == Py_None) { - lib= NULL; + lib = NULL; } else if (PyUnicode_Check(keylib)) { - Main *bmain= self->ptr.data; - const char *keylib_str= _PyUnicode_AsString(keylib); - lib= BLI_findstring(&bmain->library, keylib_str, offsetof(Library, name)); + Main *bmain = self->ptr.data; + const char *keylib_str = _PyUnicode_AsString(keylib); + lib = BLI_findstring(&bmain->library, keylib_str, offsetof(Library, name)); if (lib == NULL) { if (err_not_found) { PyErr_Format(PyExc_KeyError, @@ -2178,11 +2182,11 @@ int pyrna_prop_collection_subscript_str_lib_pair_ptr(BPy_PropertyRNA *self, PyOb * either way can do direct comparison with id.lib */ RNA_PROP_BEGIN(&self->ptr, itemptr, self->prop) { - ID *id= itemptr.data; /* always an ID */ - if (id->lib == lib && (strncmp(keyname, id->name+2, sizeof(id->name)-2) == 0)) { - found= TRUE; + ID *id = itemptr.data; /* always an ID */ + if (id->lib == lib && (strncmp(keyname, id->name + 2, sizeof(id->name) - 2) == 0)) { + found = TRUE; if (r_ptr) { - *r_ptr= itemptr; + *r_ptr = itemptr; } break; } @@ -2206,7 +2210,7 @@ static PyObject *pyrna_prop_collection_subscript_str_lib_pair(BPy_PropertyRNA *s const char *err_prefix, const short err_not_found) { PointerRNA ptr; - const int contains= pyrna_prop_collection_subscript_str_lib_pair_ptr(self, key, err_prefix, err_not_found, &ptr); + const int contains = pyrna_prop_collection_subscript_str_lib_pair_ptr(self, key, err_prefix, err_not_found, &ptr); if (contains == 1) { return pyrna_struct_CreatePyObject(&ptr); @@ -2220,21 +2224,21 @@ static PyObject *pyrna_prop_collection_subscript_str_lib_pair(BPy_PropertyRNA *s static PyObject *pyrna_prop_collection_subscript_slice(BPy_PropertyRNA *self, Py_ssize_t start, Py_ssize_t stop) { CollectionPropertyIterator rna_macro_iter; - int count= 0; + int count = 0; PyObject *list; PyObject *item; PYRNA_PROP_CHECK_OBJ(self); - list= PyList_New(0); + list = PyList_New(0); /* first loop up-until the start */ for (RNA_property_collection_begin(&self->ptr, self->prop, &rna_macro_iter); rna_macro_iter.valid; RNA_property_collection_next(&rna_macro_iter)) { - /* PointerRNA itemptr= rna_macro_iter.ptr; */ + /* PointerRNA itemptr = rna_macro_iter.ptr; */ if (count == start) { break; } @@ -2245,7 +2249,7 @@ static PyObject *pyrna_prop_collection_subscript_slice(BPy_PropertyRNA *self, Py for (; rna_macro_iter.valid; RNA_property_collection_next(&rna_macro_iter)) { - item= pyrna_struct_CreatePyObject(&rna_macro_iter.ptr); + item = pyrna_struct_CreatePyObject(&rna_macro_iter.ptr); PyList_Append(list, item); Py_DECREF(item); @@ -2272,14 +2276,14 @@ static PyObject *pyrna_prop_array_subscript_slice(BPy_PropertyArrayRNA *self, Po PYRNA_PROP_CHECK_OBJ((BPy_PropertyRNA *)self); - tuple= PyTuple_New(stop - start); + tuple = PyTuple_New(stop - start); /* PYRNA_PROP_CHECK_OBJ(self); isn't needed, internal use only */ - totdim= RNA_property_array_dimension(ptr, prop, NULL); + totdim = RNA_property_array_dimension(ptr, prop, NULL); if (totdim > 1) { - for (count= start; count < stop; count++) + for (count = start; count < stop; count++) PyTuple_SET_ITEM(tuple, count - start, pyrna_prop_array_to_py_index(self, count)); } else { @@ -2288,11 +2292,11 @@ static PyObject *pyrna_prop_array_subscript_slice(BPy_PropertyArrayRNA *self, Po { float values_stack[PYRNA_STACK_ARRAY]; float *values; - if (length > PYRNA_STACK_ARRAY) { values= PyMem_MALLOC(sizeof(float) * length); } - else { values= values_stack; } + if (length > PYRNA_STACK_ARRAY) { values = PyMem_MALLOC(sizeof(float) * length); } + else { values = values_stack; } RNA_property_float_get_array(ptr, prop, values); - for (count=start; count<stop; count++) + for (count = start; count < stop; count++) PyTuple_SET_ITEM(tuple, count-start, PyFloat_FromDouble(values[count])); if (values != values_stack) { @@ -2304,11 +2308,11 @@ static PyObject *pyrna_prop_array_subscript_slice(BPy_PropertyArrayRNA *self, Po { int values_stack[PYRNA_STACK_ARRAY]; int *values; - if (length > PYRNA_STACK_ARRAY) { values= PyMem_MALLOC(sizeof(int) * length); } - else { values= values_stack; } + if (length > PYRNA_STACK_ARRAY) { values = PyMem_MALLOC(sizeof(int) * length); } + else { values = values_stack; } RNA_property_boolean_get_array(ptr, prop, values); - for (count=start; count<stop; count++) + for (count = start; count < stop; count++) PyTuple_SET_ITEM(tuple, count-start, PyBool_FromLong(values[count])); if (values != values_stack) { @@ -2320,11 +2324,11 @@ static PyObject *pyrna_prop_array_subscript_slice(BPy_PropertyArrayRNA *self, Po { int values_stack[PYRNA_STACK_ARRAY]; int *values; - if (length > PYRNA_STACK_ARRAY) { values= PyMem_MALLOC(sizeof(int) * length); } - else { values= values_stack; } + if (length > PYRNA_STACK_ARRAY) { values = PyMem_MALLOC(sizeof(int) * length); } + else { values = values_stack; } RNA_property_int_get_array(ptr, prop, values); - for (count=start; count<stop; count++) + for (count = start; count < stop; count++) PyTuple_SET_ITEM(tuple, count-start, PyLong_FromSsize_t(values[count])); if (values != values_stack) { @@ -2337,7 +2341,7 @@ static PyObject *pyrna_prop_array_subscript_slice(BPy_PropertyArrayRNA *self, Po PyErr_SetString(PyExc_TypeError, "not an array type"); Py_DECREF(tuple); - tuple= NULL; + tuple = NULL; } } return tuple; @@ -2351,15 +2355,15 @@ static PyObject *pyrna_prop_collection_subscript(BPy_PropertyRNA *self, PyObject return pyrna_prop_collection_subscript_str(self, _PyUnicode_AsString(key)); } else if (PyIndex_Check(key)) { - Py_ssize_t i= PyNumber_AsSsize_t(key, PyExc_IndexError); + Py_ssize_t i = PyNumber_AsSsize_t(key, PyExc_IndexError); if (i == -1 && PyErr_Occurred()) return NULL; return pyrna_prop_collection_subscript_int(self, i); } else if (PySlice_Check(key)) { - PySliceObject *key_slice= (PySliceObject *)key; - Py_ssize_t step= 1; + PySliceObject *key_slice = (PySliceObject *)key; + Py_ssize_t step = 1; if (key_slice->step != Py_None && !_PyEval_SliceIndex(key, &step)) { return NULL; @@ -2372,7 +2376,7 @@ static PyObject *pyrna_prop_collection_subscript(BPy_PropertyRNA *self, PyObject return pyrna_prop_collection_subscript_slice(self, 0, PY_SSIZE_T_MAX); } else { - Py_ssize_t start= 0, stop= PY_SSIZE_T_MAX; + Py_ssize_t start = 0, stop = PY_SSIZE_T_MAX; /* avoid PySlice_GetIndicesEx because it needs to know the length ahead of time. */ if (key_slice->start != Py_None && !_PyEval_SliceIndex(key_slice->start, &start)) return NULL; @@ -2380,7 +2384,7 @@ static PyObject *pyrna_prop_collection_subscript(BPy_PropertyRNA *self, PyObject if (start < 0 || stop < 0) { /* only get the length for negative values */ - Py_ssize_t len= (Py_ssize_t)RNA_property_collection_length(&self->ptr, self->prop); + Py_ssize_t len = (Py_ssize_t)RNA_property_collection_length(&self->ptr, self->prop); if (start < 0) start += len; if (stop < 0) start += len; } @@ -2431,8 +2435,8 @@ static int pyrna_prop_collection_type_check(BPy_PropertyRNA *self, PyObject *val Py_TYPE(value)->tp_name); return -1; } - else if ((prop_srna= RNA_property_pointer_type(&self->ptr, self->prop))) { - StructRNA *value_srna= ((BPy_StructRNA *)value)->ptr.type; + else if ((prop_srna = RNA_property_pointer_type(&self->ptr, self->prop))) { + StructRNA *value_srna = ((BPy_StructRNA *)value)->ptr.type; if (RNA_struct_is_a(value_srna, prop_srna) == 0) { PyErr_Format(PyExc_TypeError, "bpy_prop_collection[key] = value: invalid, " @@ -2476,7 +2480,7 @@ static int pyrna_prop_collection_ass_subscript(BPy_PropertyRNA *self, PyObject * else #endif if (PyIndex_Check(key)) { - Py_ssize_t i= PyNumber_AsSsize_t(key, PyExc_IndexError); + Py_ssize_t i = PyNumber_AsSsize_t(key, PyExc_IndexError); if (i == -1 && PyErr_Occurred()) return -1; @@ -2484,8 +2488,8 @@ static int pyrna_prop_collection_ass_subscript(BPy_PropertyRNA *self, PyObject * } #if 0 /* TODO, fake slice assignment */ else if (PySlice_Check(key)) { - PySliceObject *key_slice= (PySliceObject *)key; - Py_ssize_t step= 1; + PySliceObject *key_slice = (PySliceObject *)key; + Py_ssize_t step = 1; if (key_slice->step != Py_None && !_PyEval_SliceIndex(key, &step)) { return NULL; @@ -2498,7 +2502,7 @@ static int pyrna_prop_collection_ass_subscript(BPy_PropertyRNA *self, PyObject * return pyrna_prop_collection_subscript_slice(self, 0, PY_SSIZE_T_MAX); } else { - Py_ssize_t start= 0, stop= PY_SSIZE_T_MAX; + Py_ssize_t start = 0, stop = PY_SSIZE_T_MAX; /* avoid PySlice_GetIndicesEx because it needs to know the length ahead of time. */ if (key_slice->start != Py_None && !_PyEval_SliceIndex(key_slice->start, &start)) return NULL; @@ -2506,7 +2510,7 @@ static int pyrna_prop_collection_ass_subscript(BPy_PropertyRNA *self, PyObject * if (start < 0 || stop < 0) { /* only get the length for negative values */ - Py_ssize_t len= (Py_ssize_t)RNA_property_collection_length(&self->ptr, self->prop); + Py_ssize_t len = (Py_ssize_t)RNA_property_collection_length(&self->ptr, self->prop); if (start < 0) start += len; if (stop < 0) start += len; } @@ -2538,14 +2542,14 @@ static PyObject *pyrna_prop_array_subscript(BPy_PropertyArrayRNA *self, PyObject } else */ if (PyIndex_Check(key)) { - Py_ssize_t i= PyNumber_AsSsize_t(key, PyExc_IndexError); + Py_ssize_t i = PyNumber_AsSsize_t(key, PyExc_IndexError); if (i == -1 && PyErr_Occurred()) return NULL; return pyrna_prop_array_subscript_int(self, PyLong_AsLong(key)); } else if (PySlice_Check(key)) { - Py_ssize_t step= 1; - PySliceObject *key_slice= (PySliceObject *)key; + Py_ssize_t step = 1; + PySliceObject *key_slice = (PySliceObject *)key; if (key_slice->step != Py_None && !_PyEval_SliceIndex(key, &step)) { return NULL; @@ -2556,11 +2560,11 @@ static PyObject *pyrna_prop_array_subscript(BPy_PropertyArrayRNA *self, PyObject } else if (key_slice->start == Py_None && key_slice->stop == Py_None) { /* note, no significant advantage with optimizing [:] slice as with collections but include here for consistency with collection slice func */ - Py_ssize_t len= (Py_ssize_t)pyrna_prop_array_length(self); + Py_ssize_t len = (Py_ssize_t)pyrna_prop_array_length(self); return pyrna_prop_array_subscript_slice(self, &self->ptr, self->prop, 0, len, len); } else { - int len= pyrna_prop_array_length(self); + int len = pyrna_prop_array_length(self); Py_ssize_t start, stop, slicelength; if (PySlice_GetIndicesEx((void *)key, len, &start, &stop, &step, &slicelength) < 0) @@ -2586,23 +2590,23 @@ static int prop_subscript_ass_array_slice(PointerRNA *ptr, PropertyRNA *prop, { PyObject *value; int count; - void *values_alloc= NULL; - int ret= 0; + void *values_alloc = NULL; + int ret = 0; if (value_orig == NULL) { PyErr_SetString(PyExc_TypeError, - "bpy_prop_array[slice]= value: deleting with list types is not supported by bpy_struct"); + "bpy_prop_array[slice] = value: deleting with list types is not supported by bpy_struct"); return -1; } - if (!(value=PySequence_Fast(value_orig, "bpy_prop_array[slice]= value: assignment is not a sequence type"))) { + if (!(value = PySequence_Fast(value_orig, "bpy_prop_array[slice] = value: assignment is not a sequence type"))) { return -1; } if (PySequence_Fast_GET_SIZE(value) != stop-start) { Py_DECREF(value); PyErr_SetString(PyExc_TypeError, - "bpy_prop_array[slice]= value: resizing bpy_struct arrays isn't supported"); + "bpy_prop_array[slice] = value: resizing bpy_struct arrays isn't supported"); return -1; } @@ -2615,18 +2619,18 @@ static int prop_subscript_ass_array_slice(PointerRNA *ptr, PropertyRNA *prop, float min, max; RNA_property_float_range(ptr, prop, &min, &max); - if (length > PYRNA_STACK_ARRAY) { values= values_alloc= PyMem_MALLOC(sizeof(float) * length); } - else { values= values_stack; } + if (length > PYRNA_STACK_ARRAY) { values = values_alloc = PyMem_MALLOC(sizeof(float) * length); } + else { values = values_stack; } if (start != 0 || stop != length) /* partial assignment? - need to get the array */ RNA_property_float_get_array(ptr, prop, values); - for (count=start; count<stop; count++) { - fval= PyFloat_AsDouble(PySequence_Fast_GET_ITEM(value, count-start)); + for (count = start; count < stop; count++) { + fval = PyFloat_AsDouble(PySequence_Fast_GET_ITEM(value, count-start)); CLAMP(fval, min, max); - values[count]= fval; + values[count] = fval; } - if (PyErr_Occurred()) ret= -1; + if (PyErr_Occurred()) ret = -1; else RNA_property_float_set_array(ptr, prop, values); break; } @@ -2634,16 +2638,16 @@ static int prop_subscript_ass_array_slice(PointerRNA *ptr, PropertyRNA *prop, { int values_stack[PYRNA_STACK_ARRAY]; int *values; - if (length > PYRNA_STACK_ARRAY) { values= values_alloc= PyMem_MALLOC(sizeof(int) * length); } - else { values= values_stack; } + if (length > PYRNA_STACK_ARRAY) { values = values_alloc = PyMem_MALLOC(sizeof(int) * length); } + else { values = values_stack; } if (start != 0 || stop != length) /* partial assignment? - need to get the array */ RNA_property_boolean_get_array(ptr, prop, values); - for (count=start; count<stop; count++) - values[count]= PyLong_AsLong(PySequence_Fast_GET_ITEM(value, count-start)); + for (count = start; count < stop; count++) + values[count] = PyLong_AsLong(PySequence_Fast_GET_ITEM(value, count-start)); - if (PyErr_Occurred()) ret= -1; + if (PyErr_Occurred()) ret = -1; else RNA_property_boolean_set_array(ptr, prop, values); break; } @@ -2655,25 +2659,25 @@ static int prop_subscript_ass_array_slice(PointerRNA *ptr, PropertyRNA *prop, int min, max; RNA_property_int_range(ptr, prop, &min, &max); - if (length > PYRNA_STACK_ARRAY) { values= values_alloc= PyMem_MALLOC(sizeof(int) * length); } - else { values= values_stack; } + if (length > PYRNA_STACK_ARRAY) { values = values_alloc = PyMem_MALLOC(sizeof(int) * length); } + else { values = values_stack; } if (start != 0 || stop != length) /* partial assignment? - need to get the array */ RNA_property_int_get_array(ptr, prop, values); - for (count=start; count<stop; count++) { - ival= PyLong_AsLong(PySequence_Fast_GET_ITEM(value, count-start)); + for (count = start; count < stop; count++) { + ival = PyLong_AsLong(PySequence_Fast_GET_ITEM(value, count-start)); CLAMP(ival, min, max); - values[count]= ival; + values[count] = ival; } - if (PyErr_Occurred()) ret= -1; + if (PyErr_Occurred()) ret = -1; else RNA_property_int_set_array(ptr, prop, values); break; } default: PyErr_SetString(PyExc_TypeError, "not an array type"); - ret= -1; + ret = -1; } Py_DECREF(value); @@ -2692,7 +2696,7 @@ static int prop_subscript_ass_array_int(BPy_PropertyArrayRNA *self, Py_ssize_t k PYRNA_PROP_CHECK_INT((BPy_PropertyRNA *)self); - len= pyrna_prop_array_length(self); + len = pyrna_prop_array_length(self); if (keynum < 0) keynum += len; @@ -2706,8 +2710,8 @@ static int prop_subscript_ass_array_int(BPy_PropertyArrayRNA *self, Py_ssize_t k static int pyrna_prop_array_ass_subscript(BPy_PropertyArrayRNA *self, PyObject *key, PyObject *value) { - /* char *keyname= NULL; */ /* not supported yet */ - int ret= -1; + /* char *keyname = NULL; */ /* not supported yet */ + int ret = -1; PYRNA_PROP_CHECK_INT((BPy_PropertyRNA *)self); @@ -2715,39 +2719,39 @@ static int pyrna_prop_array_ass_subscript(BPy_PropertyArrayRNA *self, PyObject * PyErr_Format(PyExc_AttributeError, "bpy_prop_collection: attribute \"%.200s\" from \"%.200s\" is read-only", RNA_property_identifier(self->prop), RNA_struct_identifier(self->ptr.type)); - ret= -1; + ret = -1; } else if (PyIndex_Check(key)) { - Py_ssize_t i= PyNumber_AsSsize_t(key, PyExc_IndexError); + Py_ssize_t i = PyNumber_AsSsize_t(key, PyExc_IndexError); if (i == -1 && PyErr_Occurred()) { - ret= -1; + ret = -1; } else { - ret= prop_subscript_ass_array_int(self, i, value); + ret = prop_subscript_ass_array_int(self, i, value); } } else if (PySlice_Check(key)) { - int len= RNA_property_array_length(&self->ptr, self->prop); + int len = RNA_property_array_length(&self->ptr, self->prop); Py_ssize_t start, stop, step, slicelength; if (PySlice_GetIndicesEx((void *)key, len, &start, &stop, &step, &slicelength) < 0) { - ret= -1; + ret = -1; } else if (slicelength <= 0) { - ret= 0; /* do nothing */ + ret = 0; /* do nothing */ } else if (step == 1) { - ret= prop_subscript_ass_array_slice(&self->ptr, self->prop, start, stop, len, value); + ret = prop_subscript_ass_array_slice(&self->ptr, self->prop, start, stop, len, value); } else { PyErr_SetString(PyExc_TypeError, "slice steps not supported with rna"); - ret= -1; + ret = -1; } } else { PyErr_SetString(PyExc_AttributeError, "invalid key, key must be an int"); - ret= -1; + ret = -1; } if (ret != -1) { @@ -2760,20 +2764,20 @@ static int pyrna_prop_array_ass_subscript(BPy_PropertyArrayRNA *self, PyObject * } /* for slice only */ -static PyMappingMethods pyrna_prop_array_as_mapping= { +static PyMappingMethods pyrna_prop_array_as_mapping = { (lenfunc) pyrna_prop_array_length, /* mp_length */ (binaryfunc) pyrna_prop_array_subscript, /* mp_subscript */ (objobjargproc) pyrna_prop_array_ass_subscript, /* mp_ass_subscript */ }; -static PyMappingMethods pyrna_prop_collection_as_mapping= { +static PyMappingMethods pyrna_prop_collection_as_mapping = { (lenfunc) pyrna_prop_collection_length, /* mp_length */ (binaryfunc) pyrna_prop_collection_subscript, /* mp_subscript */ (objobjargproc) pyrna_prop_collection_ass_subscript, /* mp_ass_subscript */ }; /* only for fast bool's, large structs, assign nb_bool on init */ -static PyNumberMethods pyrna_prop_array_as_number= { +static PyNumberMethods pyrna_prop_array_as_number = { NULL, /* nb_add */ NULL, /* nb_subtract */ NULL, /* nb_multiply */ @@ -2785,7 +2789,7 @@ static PyNumberMethods pyrna_prop_array_as_number= { NULL, /* nb_absolute */ (inquiry) pyrna_prop_array_bool, /* nb_bool */ }; -static PyNumberMethods pyrna_prop_collection_as_number= { +static PyNumberMethods pyrna_prop_collection_as_number = { NULL, /* nb_add */ NULL, /* nb_subtract */ NULL, /* nb_multiply */ @@ -2815,9 +2819,9 @@ static int pyrna_prop_collection_contains(BPy_PropertyRNA *self, PyObject *key) else { /* key in dict style check */ - const char *keyname= _PyUnicode_AsString(key); + const char *keyname = _PyUnicode_AsString(key); - if (keyname==NULL) { + if (keyname == NULL) { PyErr_SetString(PyExc_TypeError, "bpy_prop_collection.__contains__: expected a string or a typle of strings"); return -1; } @@ -2832,7 +2836,7 @@ static int pyrna_prop_collection_contains(BPy_PropertyRNA *self, PyObject *key) static int pyrna_struct_contains(BPy_StructRNA *self, PyObject *value) { IDProperty *group; - const char *name= _PyUnicode_AsString(value); + const char *name = _PyUnicode_AsString(value); PYRNA_STRUCT_CHECK_INT(self); @@ -2841,12 +2845,12 @@ static int pyrna_struct_contains(BPy_StructRNA *self, PyObject *value) return -1; } - if (RNA_struct_idprops_check(self->ptr.type)==0) { + if (RNA_struct_idprops_check(self->ptr.type) == 0) { PyErr_SetString(PyExc_TypeError, "bpy_struct: this type doesn't support IDProperties"); return -1; } - group= RNA_struct_idprops(&self->ptr, 0); + group = RNA_struct_idprops(&self->ptr, 0); if (!group) return 0; @@ -2854,7 +2858,7 @@ static int pyrna_struct_contains(BPy_StructRNA *self, PyObject *value) return IDP_GetPropertyFromGroup(group, name) ? 1:0; } -static PySequenceMethods pyrna_prop_array_as_sequence= { +static PySequenceMethods pyrna_prop_array_as_sequence = { (lenfunc)pyrna_prop_array_length, /* Cant set the len otherwise it can evaluate as false */ NULL, /* sq_concat */ NULL, /* sq_repeat */ @@ -2867,7 +2871,7 @@ static PySequenceMethods pyrna_prop_array_as_sequence= { (ssizeargfunc) NULL, /* sq_inplace_repeat */ }; -static PySequenceMethods pyrna_prop_collection_as_sequence= { +static PySequenceMethods pyrna_prop_collection_as_sequence = { (lenfunc)pyrna_prop_collection_length, /* Cant set the len otherwise it can evaluate as false */ NULL, /* sq_concat */ NULL, /* sq_repeat */ @@ -2880,7 +2884,7 @@ static PySequenceMethods pyrna_prop_collection_as_sequence= { (ssizeargfunc) NULL, /* sq_inplace_repeat */ }; -static PySequenceMethods pyrna_struct_as_sequence= { +static PySequenceMethods pyrna_struct_as_sequence = { NULL, /* Cant set the len otherwise it can evaluate as false */ NULL, /* sq_concat */ NULL, /* sq_repeat */ @@ -2897,30 +2901,30 @@ static PyObject *pyrna_struct_subscript(BPy_StructRNA *self, PyObject *key) { /* mostly copied from BPy_IDGroup_Map_GetItem */ IDProperty *group, *idprop; - const char *name= _PyUnicode_AsString(key); + const char *name = _PyUnicode_AsString(key); PYRNA_STRUCT_CHECK_OBJ(self); - if (RNA_struct_idprops_check(self->ptr.type)==0) { + if (RNA_struct_idprops_check(self->ptr.type) == 0) { PyErr_SetString(PyExc_TypeError, "this type doesn't support IDProperties"); return NULL; } - if (name==NULL) { + if (name == NULL) { PyErr_SetString(PyExc_TypeError, "bpy_struct[key]: only strings are allowed as keys of ID properties"); return NULL; } - group= RNA_struct_idprops(&self->ptr, 0); + group = RNA_struct_idprops(&self->ptr, 0); - if (group==NULL) { + if (group == NULL) { PyErr_Format(PyExc_KeyError, "bpy_struct[key]: key \"%s\" not found", name); return NULL; } - idprop= IDP_GetPropertyFromGroup(group, name); + idprop = IDP_GetPropertyFromGroup(group, name); - if (idprop==NULL) { + if (idprop == NULL) { PyErr_Format(PyExc_KeyError, "bpy_struct[key]: key \"%s\" not found", name); return NULL; } @@ -2934,7 +2938,7 @@ static int pyrna_struct_ass_subscript(BPy_StructRNA *self, PyObject *key, PyObje PYRNA_STRUCT_CHECK_INT(self); - group= RNA_struct_idprops(&self->ptr, 1); + group = RNA_struct_idprops(&self->ptr, 1); #ifdef USE_PEDANTIC_WRITE if (rna_disallow_writes && rna_id_write_error(&self->ptr, key)) { @@ -2942,15 +2946,15 @@ static int pyrna_struct_ass_subscript(BPy_StructRNA *self, PyObject *key, PyObje } #endif // USE_PEDANTIC_WRITE - if (group==NULL) { - PyErr_SetString(PyExc_TypeError, "bpy_struct[key]= val: id properties not supported for this type"); + if (group == NULL) { + PyErr_SetString(PyExc_TypeError, "bpy_struct[key] = val: id properties not supported for this type"); return -1; } return BPy_Wrap_SetMapItem(group, key, value); } -static PyMappingMethods pyrna_struct_as_mapping= { +static PyMappingMethods pyrna_struct_as_mapping = { (lenfunc) NULL, /* mp_length */ (binaryfunc) pyrna_struct_subscript, /* mp_subscript */ (objobjargproc) pyrna_struct_ass_subscript, /* mp_ass_subscript */ @@ -2971,14 +2975,14 @@ static PyObject *pyrna_struct_keys(BPy_PropertyRNA *self) { IDProperty *group; - if (RNA_struct_idprops_check(self->ptr.type)==0) { + if (RNA_struct_idprops_check(self->ptr.type) == 0) { PyErr_SetString(PyExc_TypeError, "bpy_struct.keys(): this type doesn't support IDProperties"); return NULL; } - group= RNA_struct_idprops(&self->ptr, 0); + group = RNA_struct_idprops(&self->ptr, 0); - if (group==NULL) + if (group == NULL) return PyList_New(0); return BPy_Wrap_GetKeys(group); @@ -2999,14 +3003,14 @@ static PyObject *pyrna_struct_items(BPy_PropertyRNA *self) { IDProperty *group; - if (RNA_struct_idprops_check(self->ptr.type)==0) { + if (RNA_struct_idprops_check(self->ptr.type) == 0) { PyErr_SetString(PyExc_TypeError, "bpy_struct.items(): this type doesn't support IDProperties"); return NULL; } - group= RNA_struct_idprops(&self->ptr, 0); + group = RNA_struct_idprops(&self->ptr, 0); - if (group==NULL) + if (group == NULL) return PyList_New(0); return BPy_Wrap_GetItems(self->ptr.id.data, group); @@ -3027,14 +3031,14 @@ static PyObject *pyrna_struct_values(BPy_PropertyRNA *self) { IDProperty *group; - if (RNA_struct_idprops_check(self->ptr.type)==0) { + if (RNA_struct_idprops_check(self->ptr.type) == 0) { PyErr_SetString(PyExc_TypeError, "bpy_struct.values(): this type doesn't support IDProperties"); return NULL; } - group= RNA_struct_idprops(&self->ptr, 0); + group = RNA_struct_idprops(&self->ptr, 0); - if (group==NULL) + if (group == NULL) return PyList_New(0); return BPy_Wrap_GetValues(self->ptr.id.data, group); @@ -3060,7 +3064,7 @@ static PyObject *pyrna_struct_is_property_set(BPy_StructRNA *self, PyObject *arg if (!PyArg_ParseTuple(args, "s:is_property_set", &name)) return NULL; - if ((prop= RNA_struct_find_property(&self->ptr, name)) == NULL) { + if ((prop = RNA_struct_find_property(&self->ptr, name)) == NULL) { PyErr_Format(PyExc_TypeError, "%.200s.is_property_set(\"%.200s\") not found", RNA_struct_identifier(self->ptr.type), name); @@ -3070,16 +3074,16 @@ static PyObject *pyrna_struct_is_property_set(BPy_StructRNA *self, PyObject *arg /* double property lookup, could speed up */ /* return PyBool_FromLong(RNA_property_is_set(&self->ptr, name)); */ if (RNA_property_flag(prop) & PROP_IDPROPERTY) { - IDProperty *group= RNA_struct_idprops(&self->ptr, 0); + IDProperty *group = RNA_struct_idprops(&self->ptr, 0); if (group) { - ret= IDP_GetPropertyFromGroup(group, name) ? 1:0; + ret = IDP_GetPropertyFromGroup(group, name) ? 1:0; } else { - ret= 0; + ret = 0; } } else { - ret= 1; + ret = 1; } return PyBool_FromLong(ret); @@ -3103,7 +3107,7 @@ static PyObject *pyrna_struct_is_property_hidden(BPy_StructRNA *self, PyObject * if (!PyArg_ParseTuple(args, "s:is_property_hidden", &name)) return NULL; - if ((prop= RNA_struct_find_property(&self->ptr, name)) == NULL) { + if ((prop = RNA_struct_find_property(&self->ptr, name)) == NULL) { PyErr_Format(PyExc_TypeError, "%.200s.is_property_hidden(\"%.200s\") not found", RNA_struct_identifier(self->ptr.type), name); @@ -3127,10 +3131,10 @@ PyDoc_STRVAR(pyrna_struct_path_resolve_doc, static PyObject *pyrna_struct_path_resolve(BPy_StructRNA *self, PyObject *args) { const char *path; - PyObject *coerce= Py_True; + PyObject *coerce = Py_True; PointerRNA r_ptr; PropertyRNA *r_prop; - int index= -1; + int index = -1; PYRNA_STRUCT_CHECK_OBJ(self); @@ -3185,7 +3189,7 @@ PyDoc_STRVAR(pyrna_struct_path_from_id_doc, ); static PyObject *pyrna_struct_path_from_id(BPy_StructRNA *self, PyObject *args) { - const char *name= NULL; + const char *name = NULL; const char *path; PropertyRNA *prop; PyObject *ret; @@ -3196,21 +3200,21 @@ static PyObject *pyrna_struct_path_from_id(BPy_StructRNA *self, PyObject *args) return NULL; if (name) { - prop= RNA_struct_find_property(&self->ptr, name); - if (prop==NULL) { + prop = RNA_struct_find_property(&self->ptr, name); + if (prop == NULL) { PyErr_Format(PyExc_AttributeError, "%.200s.path_from_id(\"%.200s\") not found", RNA_struct_identifier(self->ptr.type), name); return NULL; } - path= RNA_path_from_ID_to_property(&self->ptr, prop); + path = RNA_path_from_ID_to_property(&self->ptr, prop); } else { - path= RNA_path_from_ID_to_struct(&self->ptr); + path = RNA_path_from_ID_to_struct(&self->ptr); } - if (path==NULL) { + if (path == NULL) { if (name) { PyErr_Format(PyExc_ValueError, "%.200s.path_from_id(\"%s\") found but does not support path creation", @@ -3224,7 +3228,7 @@ static PyObject *pyrna_struct_path_from_id(BPy_StructRNA *self, PyObject *args) return NULL; } - ret= PyUnicode_FromString(path); + ret = PyUnicode_FromString(path); MEM_freeN((void *)path); return ret; @@ -3241,19 +3245,19 @@ PyDoc_STRVAR(pyrna_prop_path_from_id_doc, static PyObject *pyrna_prop_path_from_id(BPy_PropertyRNA *self) { const char *path; - PropertyRNA *prop= self->prop; + PropertyRNA *prop = self->prop; PyObject *ret; - path= RNA_path_from_ID_to_property(&self->ptr, self->prop); + path = RNA_path_from_ID_to_property(&self->ptr, self->prop); - if (path==NULL) { + if (path == NULL) { PyErr_Format(PyExc_ValueError, "%.200s.%.200s.path_from_id() does not support path creation for this type", RNA_struct_identifier(self->ptr.type), RNA_property_identifier(prop)); return NULL; } - ret= PyUnicode_FromString(path); + ret = PyUnicode_FromString(path); MEM_freeN((void *)path); return ret; @@ -3284,17 +3288,17 @@ static void pyrna_dir_members_py(PyObject *list, PyObject *self) PyObject **dict_ptr; PyObject *list_tmp; - dict_ptr= _PyObject_GetDictPtr((PyObject *)self); + dict_ptr = _PyObject_GetDictPtr((PyObject *)self); - if (dict_ptr && (dict=*dict_ptr)) { - list_tmp= PyDict_Keys(dict); + if (dict_ptr && (dict = *dict_ptr)) { + list_tmp = PyDict_Keys(dict); PyList_SetSlice(list, INT_MAX, INT_MAX, list_tmp); Py_DECREF(list_tmp); } - dict= ((PyTypeObject *)Py_TYPE(self))->tp_dict; + dict = ((PyTypeObject *)Py_TYPE(self))->tp_dict; if (dict) { - list_tmp= PyDict_Keys(dict); + list_tmp = PyDict_Keys(dict); PyList_SetSlice(list, INT_MAX, INT_MAX, list_tmp); Py_DECREF(list_tmp); } @@ -3311,12 +3315,12 @@ static void pyrna_dir_members_rna(PyObject *list, PointerRNA *ptr) { RNA_pointer_create(NULL, &RNA_Struct, ptr->type, &tptr); - iterprop= RNA_struct_find_property(&tptr, "functions"); + iterprop = RNA_struct_find_property(&tptr, "functions"); RNA_PROP_BEGIN(&tptr, itemptr, iterprop) { - idname= RNA_function_identifier(itemptr.data); + idname = RNA_function_identifier(itemptr.data); - pystring= PyUnicode_FromString(idname); + pystring = PyUnicode_FromString(idname); PyList_Append(list, pystring); Py_DECREF(pystring); } @@ -3330,13 +3334,13 @@ static void pyrna_dir_members_rna(PyObject *list, PointerRNA *ptr) char name[256], *nameptr; int namelen; - iterprop= RNA_struct_iterator_property(ptr->type); + iterprop = RNA_struct_iterator_property(ptr->type); RNA_PROP_BEGIN(ptr, itemptr, iterprop) { - nameptr= RNA_struct_name_get_alloc(&itemptr, name, sizeof(name), &namelen); + nameptr = RNA_struct_name_get_alloc(&itemptr, name, sizeof(name), &namelen); if (nameptr) { - pystring= PyUnicode_FromStringAndSize(nameptr, namelen); + pystring = PyUnicode_FromStringAndSize(nameptr, namelen); PyList_Append(list, pystring); Py_DECREF(pystring); @@ -3360,7 +3364,7 @@ static PyObject *pyrna_struct_dir(BPy_StructRNA *self) /* Include this incase this instance is a subtype of a python class * In these instances we may want to return a function or variable provided by the subtype * */ - ret= PyList_New(0); + ret = PyList_New(0); if (!BPy_StructRNA_CheckExact(self)) pyrna_dir_members_py(ret, (PyObject *)self); @@ -3368,11 +3372,11 @@ static PyObject *pyrna_struct_dir(BPy_StructRNA *self) pyrna_dir_members_rna(ret, &self->ptr); if (self->ptr.type == &RNA_Context) { - ListBase lb= CTX_data_dir_get(self->ptr.data); + ListBase lb = CTX_data_dir_get(self->ptr.data); LinkData *link; - for (link=lb.first; link; link=link->next) { - pystring= PyUnicode_FromString(link->data); + for (link = lb.first; link; link = link->next) { + pystring = PyUnicode_FromString(link->data); PyList_Append(ret, pystring); Py_DECREF(pystring); } @@ -3384,10 +3388,10 @@ static PyObject *pyrna_struct_dir(BPy_StructRNA *self) /* set(), this is needed to remove-doubles because the deferred * register-props will be in both the python __dict__ and accessed as RNA */ - PyObject *set= PySet_New(ret); + PyObject *set = PySet_New(ret); Py_DECREF(ret); - ret= PySequence_List(set); + ret = PySequence_List(set); Py_DECREF(set); } @@ -3397,7 +3401,7 @@ static PyObject *pyrna_struct_dir(BPy_StructRNA *self) //---------------getattr-------------------------------------------- static PyObject *pyrna_struct_getattro(BPy_StructRNA *self, PyObject *pyname) { - const char *name= _PyUnicode_AsString(pyname); + const char *name = _PyUnicode_AsString(pyname); PyObject *ret; PropertyRNA *prop; FunctionRNA *func; @@ -3406,49 +3410,49 @@ static PyObject *pyrna_struct_getattro(BPy_StructRNA *self, PyObject *pyname) if (name == NULL) { PyErr_SetString(PyExc_AttributeError, "bpy_struct: __getattr__ must be a string"); - ret= NULL; + ret = NULL; } - else if (name[0]=='_') { // rna can't start with a "_", so for __dict__ and similar we can skip using rna lookups + else if (name[0] == '_') { // rna can't start with a "_", so for __dict__ and similar we can skip using rna lookups /* annoying exception, maybe we need to have different types for this... */ - if ((strcmp(name, "__getitem__")==0 || strcmp(name, "__setitem__")==0) && !RNA_struct_idprops_check(self->ptr.type)) { + if ((strcmp(name, "__getitem__") == 0 || strcmp(name, "__setitem__") == 0) && !RNA_struct_idprops_check(self->ptr.type)) { PyErr_SetString(PyExc_AttributeError, "bpy_struct: no __getitem__ support for this type"); - ret= NULL; + ret = NULL; } else { - ret= PyObject_GenericGetAttr((PyObject *)self, pyname); + ret = PyObject_GenericGetAttr((PyObject *)self, pyname); } } - else if ((prop= RNA_struct_find_property(&self->ptr, name))) { - ret= pyrna_prop_to_py(&self->ptr, prop); + else if ((prop = RNA_struct_find_property(&self->ptr, name))) { + ret = pyrna_prop_to_py(&self->ptr, prop); } /* RNA function only if callback is declared (no optional functions) */ - else if ((func= RNA_struct_find_function(&self->ptr, name)) && RNA_function_defined(func)) { - ret= pyrna_func_to_py(&self->ptr, func); + else if ((func = RNA_struct_find_function(&self->ptr, name)) && RNA_function_defined(func)) { + ret = pyrna_func_to_py(&self->ptr, func); } else if (self->ptr.type == &RNA_Context) { - bContext *C= self->ptr.data; - if (C==NULL) { + bContext *C = self->ptr.data; + if (C == NULL) { PyErr_Format(PyExc_AttributeError, "bpy_struct: Context is 'NULL', can't get \"%.200s\" from context", name); - ret= NULL; + ret = NULL; } else { PointerRNA newptr; ListBase newlb; short newtype; - int done= CTX_data_get(C, name, &newptr, &newlb, &newtype); + int done = CTX_data_get(C, name, &newptr, &newlb, &newtype); - if (done==1) { /* found */ + if (done == 1) { /* found */ switch (newtype) { case CTX_DATA_TYPE_POINTER: if (newptr.data == NULL) { - ret= Py_None; + ret = Py_None; Py_INCREF(ret); } else { - ret= pyrna_struct_CreatePyObject(&newptr); + ret = pyrna_struct_CreatePyObject(&newptr); } break; case CTX_DATA_TYPE_COLLECTION: @@ -3456,10 +3460,10 @@ static PyObject *pyrna_struct_getattro(BPy_StructRNA *self, PyObject *pyname) CollectionPointerLink *link; PyObject *linkptr; - ret= PyList_New(0); + ret = PyList_New(0); - for (link=newlb.first; link; link=link->next) { - linkptr= pyrna_struct_CreatePyObject(&link->ptr); + for (link = newlb.first; link; link = link->next) { + linkptr = pyrna_struct_CreatePyObject(&link->ptr); PyList_Append(ret, linkptr); Py_DECREF(linkptr); } @@ -3472,16 +3476,16 @@ static PyObject *pyrna_struct_getattro(BPy_StructRNA *self, PyObject *pyname) PyErr_Format(PyExc_AttributeError, "bpy_struct: Context type invalid %d, can't get \"%.200s\" from context", newtype, name); - ret= NULL; + ret = NULL; } } - else if (done==-1) { /* found but not set */ - ret= Py_None; + else if (done == -1) { /* found but not set */ + ret = Py_None; Py_INCREF(ret); } else { /* not found in the context */ /* lookup the subclass. raise an error if its not found */ - ret= PyObject_GenericGetAttr((PyObject *)self, pyname); + ret = PyObject_GenericGetAttr((PyObject *)self, pyname); } BLI_freelistN(&newlb); @@ -3492,7 +3496,7 @@ static PyObject *pyrna_struct_getattro(BPy_StructRNA *self, PyObject *pyname) PyErr_Format(PyExc_AttributeError, "bpy_struct: attribute \"%.200s\" not found", name); - ret= NULL; + ret = NULL; #endif /* Include this incase this instance is a subtype of a python class * In these instances we may want to return a function or variable provided by the subtype @@ -3501,7 +3505,7 @@ static PyObject *pyrna_struct_getattro(BPy_StructRNA *self, PyObject *pyname) * */ /* The error raised here will be displayed */ - ret= PyObject_GenericGetAttr((PyObject *)self, pyname); + ret = PyObject_GenericGetAttr((PyObject *)self, pyname); } return ret; @@ -3510,8 +3514,8 @@ static PyObject *pyrna_struct_getattro(BPy_StructRNA *self, PyObject *pyname) #if 0 static int pyrna_struct_pydict_contains(PyObject *self, PyObject *pyname) { - PyObject *dict= *(_PyObject_GetDictPtr((PyObject *)self)); - if (dict==NULL) /* unlikely */ + PyObject *dict = *(_PyObject_GetDictPtr((PyObject *)self)); + if (dict == NULL) /* unlikely */ return 0; return PyDict_Contains(dict, pyname); @@ -3530,10 +3534,10 @@ static int pyrna_is_deferred_prop(const PyObject *value) #if 0 static PyObject *pyrna_struct_meta_idprop_getattro(PyObject *cls, PyObject *attr) { - PyObject *ret= PyType_Type.tp_getattro(cls, attr); + PyObject *ret = PyType_Type.tp_getattro(cls, attr); /* Allows: - * >>> bpy.types.Scene.foo= BoolProperty() + * >>> bpy.types.Scene.foo = BoolProperty() * >>> bpy.types.Scene.foo * <bpy_struct, BoolProperty("foo")> * ...rather than returning the deferred class register tuple as checked by pyrna_is_deferred_prop() @@ -3541,14 +3545,14 @@ static PyObject *pyrna_struct_meta_idprop_getattro(PyObject *cls, PyObject *attr * Disable for now, this is faking internal behavior in a way thats too tricky to maintain well. */ #if 0 if (ret == NULL) { // || pyrna_is_deferred_prop(ret) - StructRNA *srna= srna_from_self(cls, "StructRNA.__getattr__"); + StructRNA *srna = srna_from_self(cls, "StructRNA.__getattr__"); if (srna) { - PropertyRNA *prop= RNA_struct_type_find_property(srna, _PyUnicode_AsString(attr)); + PropertyRNA *prop = RNA_struct_type_find_property(srna, _PyUnicode_AsString(attr)); if (prop) { PointerRNA tptr; PyErr_Clear(); /* clear error from tp_getattro */ RNA_pointer_create(NULL, &RNA_Property, prop, &tptr); - ret= pyrna_struct_CreatePyObject(&tptr); + ret = pyrna_struct_CreatePyObject(&tptr); } } } @@ -3560,9 +3564,9 @@ static PyObject *pyrna_struct_meta_idprop_getattro(PyObject *cls, PyObject *attr static int pyrna_struct_meta_idprop_setattro(PyObject *cls, PyObject *attr, PyObject *value) { - StructRNA *srna= srna_from_self(cls, "StructRNA.__setattr__"); - const int is_deferred_prop= (value && pyrna_is_deferred_prop(value)); - const char *attr_str= _PyUnicode_AsString(attr); + StructRNA *srna = srna_from_self(cls, "StructRNA.__setattr__"); + const int is_deferred_prop = (value && pyrna_is_deferred_prop(value)); + const char *attr_str = _PyUnicode_AsString(attr); if (srna && !pyrna_write_check() && (is_deferred_prop || RNA_struct_type_find_property(srna, attr_str))) { PyErr_Format(PyExc_AttributeError, @@ -3590,7 +3594,7 @@ static int pyrna_struct_meta_idprop_setattro(PyObject *cls, PyObject *attr, PyOb if (value) { /* check if the value is a property */ if (is_deferred_prop) { - int ret= deferred_register_prop(srna, attr, value); + int ret = deferred_register_prop(srna, attr, value); if (ret == -1) { /* error set */ return ret; @@ -3607,7 +3611,7 @@ static int pyrna_struct_meta_idprop_setattro(PyObject *cls, PyObject *attr, PyOb } else { /* __delattr__ */ /* first find if this is a registered property */ - const int ret= RNA_def_property_free_identifier(srna, attr_str); + const int ret = RNA_def_property_free_identifier(srna, attr_str); if (ret == -1) { PyErr_Format(PyExc_TypeError, "struct_meta_idprop.detattr(): '%s' not a dynamic property", @@ -3622,8 +3626,8 @@ static int pyrna_struct_meta_idprop_setattro(PyObject *cls, PyObject *attr, PyOb static int pyrna_struct_setattro(BPy_StructRNA *self, PyObject *pyname, PyObject *value) { - const char *name= _PyUnicode_AsString(pyname); - PropertyRNA *prop= NULL; + const char *name = _PyUnicode_AsString(pyname); + PropertyRNA *prop = NULL; PYRNA_STRUCT_CHECK_INT(self); @@ -3637,7 +3641,7 @@ static int pyrna_struct_setattro(BPy_StructRNA *self, PyObject *pyname, PyObject PyErr_SetString(PyExc_AttributeError, "bpy_struct: __setattr__ must be a string"); return -1; } - else if (name[0] != '_' && (prop= RNA_struct_find_property(&self->ptr, name))) { + else if (name[0] != '_' && (prop = RNA_struct_find_property(&self->ptr, name))) { if (!RNA_property_editable_flag(&self->ptr, prop)) { PyErr_Format(PyExc_AttributeError, "bpy_struct: attribute \"%.200s\" from \"%.200s\" is read-only", @@ -3647,8 +3651,8 @@ static int pyrna_struct_setattro(BPy_StructRNA *self, PyObject *pyname, PyObject } else if (self->ptr.type == &RNA_Context) { /* code just raises correct error, context prop's cant be set, unless its apart of the py class */ - bContext *C= self->ptr.data; - if (C==NULL) { + bContext *C = self->ptr.data; + if (C == NULL) { PyErr_Format(PyExc_AttributeError, "bpy_struct: Context is 'NULL', can't set \"%.200s\" from context", name); @@ -3659,9 +3663,9 @@ static int pyrna_struct_setattro(BPy_StructRNA *self, PyObject *pyname, PyObject ListBase newlb; short newtype; - int done= CTX_data_get(C, name, &newptr, &newlb, &newtype); + int done = CTX_data_get(C, name, &newptr, &newlb, &newtype); - if (done==1) { + if (done == 1) { PyErr_Format(PyExc_AttributeError, "bpy_struct: Context property \"%.200s\" is read-only", name); @@ -3679,7 +3683,7 @@ static int pyrna_struct_setattro(BPy_StructRNA *self, PyObject *pyname, PyObject PyErr_SetString(PyExc_AttributeError, "bpy_struct: del not supported"); return -1; } - return pyrna_py_to_prop(&self->ptr, prop, NULL, value, "bpy_struct: item.attr= val:"); + return pyrna_py_to_prop(&self->ptr, prop, NULL, value, "bpy_struct: item.attr = val:"); } else { return PyObject_GenericSetAttr((PyObject *)self, pyname, value); @@ -3694,7 +3698,7 @@ static PyObject *pyrna_prop_dir(BPy_PropertyRNA *self) /* Include this incase this instance is a subtype of a python class * In these instances we may want to return a function or variable provided by the subtype * */ - ret= PyList_New(0); + ret = PyList_New(0); if (!BPy_PropertyRNA_CheckExact(self)) { pyrna_dir_members_py(ret, (PyObject *)self); @@ -3717,7 +3721,7 @@ static PyObject *pyrna_prop_array_getattro(BPy_PropertyRNA *self, PyObject *pyna static PyObject *pyrna_prop_collection_getattro(BPy_PropertyRNA *self, PyObject *pyname) { - const char *name= _PyUnicode_AsString(pyname); + const char *name = _PyUnicode_AsString(pyname); if (name == NULL) { PyErr_SetString(PyExc_AttributeError, "bpy_prop_collection: __getattr__ must be a string"); @@ -3730,14 +3734,14 @@ static PyObject *pyrna_prop_collection_getattro(BPy_PropertyRNA *self, PyObject PointerRNA r_ptr; if (RNA_property_collection_type_get(&self->ptr, self->prop, &r_ptr)) { - if ((prop= RNA_struct_find_property(&r_ptr, name))) { - ret= pyrna_prop_to_py(&r_ptr, prop); + if ((prop = RNA_struct_find_property(&r_ptr, name))) { + ret = pyrna_prop_to_py(&r_ptr, prop); return ret; } - else if ((func= RNA_struct_find_function(&r_ptr, name))) { - PyObject *self_collection= pyrna_struct_CreatePyObject(&r_ptr); - ret= pyrna_func_to_py(&((BPy_DummyPointerRNA *)self_collection)->ptr, func); + else if ((func = RNA_struct_find_function(&r_ptr, name))) { + PyObject *self_collection = pyrna_struct_CreatePyObject(&r_ptr); + ret = pyrna_func_to_py(&((BPy_DummyPointerRNA *)self_collection)->ptr, func); Py_DECREF(self_collection); return ret; @@ -3754,7 +3758,7 @@ static PyObject *pyrna_prop_collection_getattro(BPy_PropertyRNA *self, PyObject * so as to support 'bpy.data.library.load()' * note, this _only_ supports static methods */ - PyObject *ret= PyObject_GenericGetAttr((PyObject *)self, pyname); + PyObject *ret = PyObject_GenericGetAttr((PyObject *)self, pyname); if (ret == NULL && name[0] != '_') { /* avoid inheriting __call__ and similar */ /* since this is least common case, handle it last */ @@ -3766,8 +3770,8 @@ static PyObject *pyrna_prop_collection_getattro(BPy_PropertyRNA *self, PyObject PyErr_Fetch(&error_type, &error_value, &error_traceback); PyErr_Clear(); - cls= pyrna_struct_Subtype(&r_ptr); /* borrows */ - ret= PyObject_GenericGetAttr(cls, pyname); + cls = pyrna_struct_Subtype(&r_ptr); /* borrows */ + ret = PyObject_GenericGetAttr(cls, pyname); /* restore the original error */ if (ret == NULL) { PyErr_Restore(error_type, error_value, error_traceback); @@ -3783,7 +3787,7 @@ static PyObject *pyrna_prop_collection_getattro(BPy_PropertyRNA *self, PyObject //--------------- setattr------------------------------------------- static int pyrna_prop_collection_setattro(BPy_PropertyRNA *self, PyObject *pyname, PyObject *value) { - const char *name= _PyUnicode_AsString(pyname); + const char *name = _PyUnicode_AsString(pyname); PropertyRNA *prop; PointerRNA r_ptr; @@ -3802,7 +3806,7 @@ static int pyrna_prop_collection_setattro(BPy_PropertyRNA *self, PyObject *pynam return -1; } else if (RNA_property_collection_type_get(&self->ptr, self->prop, &r_ptr)) { - if ((prop= RNA_struct_find_property(&r_ptr, name))) { + if ((prop = RNA_struct_find_property(&r_ptr, name))) { /* pyrna_py_to_prop sets its own exceptions */ return pyrna_py_to_prop(&r_ptr, prop, NULL, value, "BPy_PropertyRNA - Attribute (setattr):"); } @@ -3831,9 +3835,9 @@ static PyObject *pyrna_prop_collection_idprop_add(BPy_PropertyRNA *self) static PyObject *pyrna_prop_collection_idprop_remove(BPy_PropertyRNA *self, PyObject *value) { - int key= PyLong_AsLong(value); + int key = PyLong_AsLong(value); - if (key==-1 && PyErr_Occurred()) { + if (key == -1 && PyErr_Occurred()) { PyErr_SetString(PyExc_TypeError, "bpy_prop_collection.remove(): expected one int argument"); return NULL; } @@ -3848,7 +3852,7 @@ static PyObject *pyrna_prop_collection_idprop_remove(BPy_PropertyRNA *self, PyOb static PyObject *pyrna_prop_collection_idprop_move(BPy_PropertyRNA *self, PyObject *args) { - int key=0, pos=0; + int key = 0, pos = 0; if (!PyArg_ParseTuple(args, "ii", &key, &pos)) { PyErr_SetString(PyExc_TypeError, "bpy_prop_collection.move(): expected two ints as arguments"); @@ -3903,14 +3907,14 @@ static PyObject *pyrna_struct_get_rna_type(BPy_PropertyRNA *self) /* Python attributes get/set structure: */ /*****************************************************************************/ -static PyGetSetDef pyrna_prop_getseters[]= { +static PyGetSetDef pyrna_prop_getseters[] = { {(char *)"id_data", (getter)pyrna_struct_get_id_data, (setter)NULL, (char *)pyrna_struct_get_id_data_doc, NULL}, {(char *)"data", (getter)pyrna_struct_get_data, (setter)NULL, (char *)pyrna_struct_get_data_doc, NULL}, {(char *)"rna_type", (getter)pyrna_struct_get_rna_type, (setter)NULL, (char *)pyrna_struct_get_rna_type_doc, NULL}, {NULL, NULL, NULL, NULL, NULL} /* Sentinel */ }; -static PyGetSetDef pyrna_struct_getseters[]= { +static PyGetSetDef pyrna_struct_getseters[] = { {(char *)"id_data", (getter)pyrna_struct_get_id_data, (setter)NULL, (char *)pyrna_struct_get_id_data_doc, NULL}, {NULL, NULL, NULL, NULL, NULL} /* Sentinel */ }; @@ -3927,17 +3931,17 @@ PyDoc_STRVAR(pyrna_prop_collection_keys_doc, ); static PyObject *pyrna_prop_collection_keys(BPy_PropertyRNA *self) { - PyObject *ret= PyList_New(0); + PyObject *ret = PyList_New(0); PyObject *item; char name[256], *nameptr; int namelen; RNA_PROP_BEGIN(&self->ptr, itemptr, self->prop) { - nameptr= RNA_struct_name_get_alloc(&itemptr, name, sizeof(name), &namelen); + nameptr = RNA_struct_name_get_alloc(&itemptr, name, sizeof(name), &namelen); if (nameptr) { /* add to python list */ - item= PyUnicode_FromStringAndSize(nameptr, namelen); + item = PyUnicode_FromStringAndSize(nameptr, namelen); PyList_Append(ret, item); Py_DECREF(item); /* done */ @@ -3963,17 +3967,17 @@ PyDoc_STRVAR(pyrna_prop_collection_items_doc, ); static PyObject *pyrna_prop_collection_items(BPy_PropertyRNA *self) { - PyObject *ret= PyList_New(0); + PyObject *ret = PyList_New(0); PyObject *item; char name[256], *nameptr; int namelen; - int i= 0; + int i = 0; RNA_PROP_BEGIN(&self->ptr, itemptr, self->prop) { if (itemptr.data) { /* add to python list */ - item= PyTuple_New(2); - nameptr= RNA_struct_name_get_alloc(&itemptr, name, sizeof(name), &namelen); + item = PyTuple_New(2); + nameptr = RNA_struct_name_get_alloc(&itemptr, name, sizeof(name), &namelen); if (nameptr) { PyTuple_SET_ITEM(item, 0, PyUnicode_FromStringAndSize(nameptr, namelen)); if (name != nameptr) @@ -4030,7 +4034,7 @@ static PyObject *pyrna_struct_get(BPy_StructRNA *self, PyObject *args) IDProperty *group, *idprop; const char *key; - PyObject* def= Py_None; + PyObject* def = Py_None; PYRNA_STRUCT_CHECK_OBJ(self); @@ -4038,14 +4042,14 @@ static PyObject *pyrna_struct_get(BPy_StructRNA *self, PyObject *args) return NULL; /* mostly copied from BPy_IDGroup_Map_GetItem */ - if (RNA_struct_idprops_check(self->ptr.type)==0) { + if (RNA_struct_idprops_check(self->ptr.type) == 0) { PyErr_SetString(PyExc_TypeError, "this type doesn't support IDProperties"); return NULL; } - group= RNA_struct_idprops(&self->ptr, 0); + group = RNA_struct_idprops(&self->ptr, 0); if (group) { - idprop= IDP_GetPropertyFromGroup(group, key); + idprop = IDP_GetPropertyFromGroup(group, key); if (idprop) { return BPy_IDGroup_WrapData(self->ptr.id.data, idprop, group); @@ -4089,7 +4093,7 @@ static PyObject *pyrna_prop_collection_get(BPy_PropertyRNA *self, PyObject *args PointerRNA newptr; PyObject *key_ob; - PyObject* def= Py_None; + PyObject* def = Py_None; PYRNA_PROP_CHECK_OBJ(self); @@ -4097,13 +4101,13 @@ static PyObject *pyrna_prop_collection_get(BPy_PropertyRNA *self, PyObject *args return NULL; if (PyUnicode_Check(key_ob)) { - const char *key= _PyUnicode_AsString(key_ob); + const char *key = _PyUnicode_AsString(key_ob); if (RNA_property_collection_lookup_string(&self->ptr, self->prop, key, &newptr)) return pyrna_struct_CreatePyObject(&newptr); } else if (PyTuple_Check(key_ob)) { - PyObject *ret= pyrna_prop_collection_subscript_str_lib_pair(self, key_ob, + PyObject *ret = pyrna_prop_collection_subscript_str_lib_pair(self, key_ob, "bpy_prop_collection.get((id, lib))", FALSE); if (ret) { return ret; @@ -4123,16 +4127,16 @@ static void foreach_attr_type( BPy_PropertyRNA *self, const char *attr, RawPropertyType *raw_type, int *attr_tot, int *attr_signed) { PropertyRNA *prop; - *raw_type= PROP_RAW_UNSET; - *attr_tot= 0; - *attr_signed= FALSE; + *raw_type = PROP_RAW_UNSET; + *attr_tot = 0; + *attr_signed = FALSE; /* note: this is fail with zero length lists, so dont let this get caled in that case */ RNA_PROP_BEGIN(&self->ptr, itemptr, self->prop) { - prop= RNA_struct_find_property(&itemptr, attr); - *raw_type= RNA_property_raw_type(prop); - *attr_tot= RNA_property_array_length(&itemptr, prop); - *attr_signed= (RNA_property_subtype(prop)==PROP_UNSIGNED) ? FALSE:TRUE; + prop = RNA_struct_find_property(&itemptr, attr); + *raw_type = RNA_property_raw_type(prop); + *attr_tot = RNA_property_array_length(&itemptr, prop); + *attr_signed = (RNA_property_subtype(prop) == PROP_UNSIGNED) ? FALSE:TRUE; break; } RNA_PROP_END; @@ -4152,31 +4156,31 @@ static int foreach_parse_args( int target_tot; #endif - *size= *attr_tot= *attr_signed= FALSE; - *raw_type= PROP_RAW_UNSET; + *size = *attr_tot = *attr_signed = FALSE; + *raw_type = PROP_RAW_UNSET; if (!PyArg_ParseTuple(args, "sO", attr, seq) || (!PySequence_Check(*seq) && PyObject_CheckBuffer(*seq))) { PyErr_SetString(PyExc_TypeError, "foreach_get(attr, sequence) expects a string and a sequence"); return -1; } - *tot= PySequence_Size(*seq); // TODO - buffer may not be a sequence! array.array() is tho. + *tot = PySequence_Size(*seq); // TODO - buffer may not be a sequence! array.array() is tho. - if (*tot>0) { + if (*tot > 0) { foreach_attr_type(self, *attr, raw_type, attr_tot, attr_signed); - *size= RNA_raw_type_sizeof(*raw_type); + *size = RNA_raw_type_sizeof(*raw_type); #if 0 // works fine but not strictly needed, we could allow RNA_property_collection_raw_* to do the checks if ((*attr_tot) < 1) - *attr_tot= 1; + *attr_tot = 1; if (RNA_property_type(self->prop) == PROP_COLLECTION) - array_tot= RNA_property_collection_length(&self->ptr, self->prop); + array_tot = RNA_property_collection_length(&self->ptr, self->prop); else - array_tot= RNA_property_array_length(&self->ptr, self->prop); + array_tot = RNA_property_array_length(&self->ptr, self->prop); - target_tot= array_tot * (*attr_tot); + target_tot = array_tot * (*attr_tot); /* rna_access.c - rna_raw_access(...) uses this same method */ if (target_tot != (*tot)) { @@ -4199,22 +4203,22 @@ static int foreach_parse_args( static int foreach_compat_buffer(RawPropertyType raw_type, int attr_signed, const char *format) { - char f= format ? *format:'B'; /* B is assumed when not set */ + char f = format ? *format:'B'; /* B is assumed when not set */ switch (raw_type) { case PROP_RAW_CHAR: - if (attr_signed) return (f=='b') ? 1:0; - else return (f=='B') ? 1:0; + if (attr_signed) return (f == 'b') ? 1:0; + else return (f == 'B') ? 1:0; case PROP_RAW_SHORT: - if (attr_signed) return (f=='h') ? 1:0; - else return (f=='H') ? 1:0; + if (attr_signed) return (f == 'h') ? 1:0; + else return (f == 'H') ? 1:0; case PROP_RAW_INT: - if (attr_signed) return (f=='i') ? 1:0; - else return (f=='I') ? 1:0; + if (attr_signed) return (f == 'i') ? 1:0; + else return (f == 'I') ? 1:0; case PROP_RAW_FLOAT: - return (f=='f') ? 1:0; + return (f == 'f') ? 1:0; case PROP_RAW_DOUBLE: - return (f=='d') ? 1:0; + return (f == 'd') ? 1:0; case PROP_RAW_UNSET: return 0; } @@ -4224,9 +4228,9 @@ static int foreach_compat_buffer(RawPropertyType raw_type, int attr_signed, cons static PyObject *foreach_getset(BPy_PropertyRNA *self, PyObject *args, int set) { - PyObject *item= NULL; - int i=0, ok=0, buffer_is_compat; - void *array= NULL; + PyObject *item = NULL; + int i = 0, ok = 0, buffer_is_compat; + void *array = NULL; /* get/set both take the same args currently */ const char *attr; @@ -4237,23 +4241,23 @@ static PyObject *foreach_getset(BPy_PropertyRNA *self, PyObject *args, int set) if (foreach_parse_args(self, args, &attr, &seq, &tot, &size, &raw_type, &attr_tot, &attr_signed) < 0) return NULL; - if (tot==0) + if (tot == 0) Py_RETURN_NONE; if (set) { /* get the array from python */ - buffer_is_compat= FALSE; + buffer_is_compat = FALSE; if (PyObject_CheckBuffer(seq)) { Py_buffer buf; PyObject_GetBuffer(seq, &buf, PyBUF_SIMPLE | PyBUF_FORMAT); /* check if the buffer matches */ - buffer_is_compat= foreach_compat_buffer(raw_type, attr_signed, buf.format); + buffer_is_compat = foreach_compat_buffer(raw_type, attr_signed, buf.format); if (buffer_is_compat) { - ok= RNA_property_collection_raw_set(NULL, &self->ptr, self->prop, attr, buf.buf, raw_type, tot); + ok = RNA_property_collection_raw_set(NULL, &self->ptr, self->prop, attr, buf.buf, raw_type, tot); } PyBuffer_Release(&buf); @@ -4261,25 +4265,25 @@ static PyObject *foreach_getset(BPy_PropertyRNA *self, PyObject *args, int set) /* could not use the buffer, fallback to sequence */ if (!buffer_is_compat) { - array= PyMem_Malloc(size * tot); + array = PyMem_Malloc(size * tot); - for ( ; i<tot; i++) { - item= PySequence_GetItem(seq, i); + for ( ; i < tot; i++) { + item = PySequence_GetItem(seq, i); switch (raw_type) { case PROP_RAW_CHAR: - ((char *)array)[i]= (char)PyLong_AsLong(item); + ((char *)array)[i] = (char)PyLong_AsLong(item); break; case PROP_RAW_SHORT: - ((short *)array)[i]= (short)PyLong_AsLong(item); + ((short *)array)[i] = (short)PyLong_AsLong(item); break; case PROP_RAW_INT: - ((int *)array)[i]= (int)PyLong_AsLong(item); + ((int *)array)[i] = (int)PyLong_AsLong(item); break; case PROP_RAW_FLOAT: - ((float *)array)[i]= (float)PyFloat_AsDouble(item); + ((float *)array)[i] = (float)PyFloat_AsDouble(item); break; case PROP_RAW_DOUBLE: - ((double *)array)[i]= (double)PyFloat_AsDouble(item); + ((double *)array)[i] = (double)PyFloat_AsDouble(item); break; case PROP_RAW_UNSET: /* should never happen */ @@ -4290,21 +4294,21 @@ static PyObject *foreach_getset(BPy_PropertyRNA *self, PyObject *args, int set) Py_DECREF(item); } - ok= RNA_property_collection_raw_set(NULL, &self->ptr, self->prop, attr, array, raw_type, tot); + ok = RNA_property_collection_raw_set(NULL, &self->ptr, self->prop, attr, array, raw_type, tot); } } else { - buffer_is_compat= FALSE; + buffer_is_compat = FALSE; if (PyObject_CheckBuffer(seq)) { Py_buffer buf; PyObject_GetBuffer(seq, &buf, PyBUF_SIMPLE | PyBUF_FORMAT); /* check if the buffer matches, TODO - signed/unsigned types */ - buffer_is_compat= foreach_compat_buffer(raw_type, attr_signed, buf.format); + buffer_is_compat = foreach_compat_buffer(raw_type, attr_signed, buf.format); if (buffer_is_compat) { - ok= RNA_property_collection_raw_get(NULL, &self->ptr, self->prop, attr, buf.buf, raw_type, tot); + ok = RNA_property_collection_raw_get(NULL, &self->ptr, self->prop, attr, buf.buf, raw_type, tot); } PyBuffer_Release(&buf); @@ -4312,34 +4316,34 @@ static PyObject *foreach_getset(BPy_PropertyRNA *self, PyObject *args, int set) /* could not use the buffer, fallback to sequence */ if (!buffer_is_compat) { - array= PyMem_Malloc(size * tot); + array = PyMem_Malloc(size * tot); - ok= RNA_property_collection_raw_get(NULL, &self->ptr, self->prop, attr, array, raw_type, tot); + ok = RNA_property_collection_raw_get(NULL, &self->ptr, self->prop, attr, array, raw_type, tot); - if (!ok) i= tot; /* skip the loop */ + if (!ok) i = tot; /* skip the loop */ - for ( ; i<tot; i++) { + for ( ; i < tot; i++) { switch (raw_type) { case PROP_RAW_CHAR: - item= PyLong_FromSsize_t((Py_ssize_t) ((char *)array)[i]); + item = PyLong_FromSsize_t((Py_ssize_t) ((char *)array)[i]); break; case PROP_RAW_SHORT: - item= PyLong_FromSsize_t((Py_ssize_t) ((short *)array)[i]); + item = PyLong_FromSsize_t((Py_ssize_t) ((short *)array)[i]); break; case PROP_RAW_INT: - item= PyLong_FromSsize_t((Py_ssize_t) ((int *)array)[i]); + item = PyLong_FromSsize_t((Py_ssize_t) ((int *)array)[i]); break; case PROP_RAW_FLOAT: - item= PyFloat_FromDouble((double) ((float *)array)[i]); + item = PyFloat_FromDouble((double) ((float *)array)[i]); break; case PROP_RAW_DOUBLE: - item= PyFloat_FromDouble((double) ((double *)array)[i]); + item = PyFloat_FromDouble((double) ((double *)array)[i]); break; default: /* PROP_RAW_UNSET */ /* should never happen */ BLI_assert(!"Invalid array type - get"); - item= Py_None; + item = Py_None; Py_INCREF(item); break; } @@ -4377,7 +4381,7 @@ PyDoc_STRVAR(pyrna_prop_collection_foreach_get_doc, " collection.foreach_get(someseq, attr)\n" "\n" " # Python equivalent\n" -" for i in range(len(seq)): someseq[i]= getattr(collection, attr)\n" +" for i in range(len(seq)): someseq[i] = getattr(collection, attr)\n" "\n" ); static PyObject *pyrna_prop_collection_foreach_get(BPy_PropertyRNA *self, PyObject *args) @@ -4413,18 +4417,18 @@ static PyObject *pyrna_prop_array_iter(BPy_PropertyArrayRNA *self) { /* Try get values from a collection */ PyObject *ret; - PyObject *iter= NULL; + PyObject *iter = NULL; int len; PYRNA_PROP_CHECK_OBJ((BPy_PropertyRNA *)self); - len= pyrna_prop_array_length(self); - ret= pyrna_prop_array_subscript_slice(self, &self->ptr, self->prop, 0, len, len); + len = pyrna_prop_array_length(self); + ret = pyrna_prop_array_subscript_slice(self, &self->ptr, self->prop, 0, len, len); /* we know this is a list so no need to PyIter_Check * otherwise it could be NULL (unlikely) if conversion failed */ if (ret) { - iter= PyObject_GetIter(ret); + iter = PyObject_GetIter(ret); Py_DECREF(ret); } @@ -4438,13 +4442,13 @@ static PyObject *pyrna_prop_collection_iter(BPy_PropertyRNA *self) { /* Try get values from a collection */ PyObject *ret; - PyObject *iter= NULL; - ret= pyrna_prop_collection_values(self); + PyObject *iter = NULL; + ret = pyrna_prop_collection_values(self); /* we know this is a list so no need to PyIter_Check * otherwise it could be NULL (unlikely) if conversion failed */ if (ret) { - iter= PyObject_GetIter(ret); + iter = PyObject_GetIter(ret); Py_DECREF(ret); } @@ -4452,7 +4456,7 @@ static PyObject *pyrna_prop_collection_iter(BPy_PropertyRNA *self) } #endif /* # !USE_PYRNA_ITER */ -static struct PyMethodDef pyrna_struct_methods[]= { +static struct PyMethodDef pyrna_struct_methods[] = { /* only for PointerRNA's with ID'props */ {"keys", (PyCFunction)pyrna_struct_keys, METH_NOARGS, pyrna_struct_keys_doc}, @@ -4482,17 +4486,17 @@ static struct PyMethodDef pyrna_struct_methods[]= { {NULL, NULL, 0, NULL} }; -static struct PyMethodDef pyrna_prop_methods[]= { +static struct PyMethodDef pyrna_prop_methods[] = { {"path_from_id", (PyCFunction)pyrna_prop_path_from_id, METH_NOARGS, pyrna_prop_path_from_id_doc}, {"__dir__", (PyCFunction)pyrna_prop_dir, METH_NOARGS, NULL}, {NULL, NULL, 0, NULL} }; -static struct PyMethodDef pyrna_prop_array_methods[]= { +static struct PyMethodDef pyrna_prop_array_methods[] = { {NULL, NULL, 0, NULL} }; -static struct PyMethodDef pyrna_prop_collection_methods[]= { +static struct PyMethodDef pyrna_prop_collection_methods[] = { {"foreach_get", (PyCFunction)pyrna_prop_collection_foreach_get, METH_VARARGS, pyrna_prop_collection_foreach_get_doc}, {"foreach_set", (PyCFunction)pyrna_prop_collection_foreach_set, METH_VARARGS, pyrna_prop_collection_foreach_set_doc}, @@ -4504,7 +4508,7 @@ static struct PyMethodDef pyrna_prop_collection_methods[]= { {NULL, NULL, 0, NULL} }; -static struct PyMethodDef pyrna_prop_collection_idprop_methods[]= { +static struct PyMethodDef pyrna_prop_collection_idprop_methods[] = { {"add", (PyCFunction)pyrna_prop_collection_idprop_add, METH_NOARGS, NULL}, {"remove", (PyCFunction)pyrna_prop_collection_idprop_remove, METH_O, NULL}, {"move", (PyCFunction)pyrna_prop_collection_idprop_move, METH_VARARGS, NULL}, @@ -4516,7 +4520,7 @@ static struct PyMethodDef pyrna_prop_collection_idprop_methods[]= { static PyObject *pyrna_struct_new(PyTypeObject *type, PyObject *args, PyObject *UNUSED(kwds)) { if (PyTuple_GET_SIZE(args) == 1) { - BPy_StructRNA *base= (BPy_StructRNA *)PyTuple_GET_ITEM(args, 0); + BPy_StructRNA *base = (BPy_StructRNA *)PyTuple_GET_ITEM(args, 0); if (Py_TYPE(base) == type) { Py_INCREF(base); return (PyObject *)base; @@ -4529,15 +4533,15 @@ static PyObject *pyrna_struct_new(PyTypeObject *type, PyObject *args, PyObject * ... def test_func(self): ... print(100) ... - >>> myob= MyObSubclass(bpy.context.object) + >>> myob = MyObSubclass(bpy.context.object) >>> myob.test_func() 100 * * Keep this since it could be useful. */ BPy_StructRNA *ret; - if ((ret= (BPy_StructRNA *)type->tp_alloc(type, 0))) { - ret->ptr= base->ptr; + if ((ret = (BPy_StructRNA *)type->tp_alloc(type, 0))) { + ret->ptr = base->ptr; } /* pass on exception & NULL if tp_alloc fails */ return (PyObject *)ret; @@ -4570,9 +4574,9 @@ static PyObject *pyrna_prop_new(PyTypeObject *type, PyObject *args, PyObject *UN return (PyObject *)base; } else if (PyType_IsSubtype(type, &pyrna_prop_Type)) { - BPy_PropertyRNA *ret= (BPy_PropertyRNA *) type->tp_alloc(type, 0); - ret->ptr= base->ptr; - ret->prop= base->prop; + BPy_PropertyRNA *ret = (BPy_PropertyRNA *) type->tp_alloc(type, 0); + ret->ptr = base->ptr; + ret->prop = base->prop; return (PyObject *)ret; } else { @@ -4586,19 +4590,19 @@ static PyObject *pyrna_prop_new(PyTypeObject *type, PyObject *args, PyObject *UN static PyObject *pyrna_param_to_py(PointerRNA *ptr, PropertyRNA *prop, void *data) { PyObject *ret; - const int type= RNA_property_type(prop); - const int flag= RNA_property_flag(prop); + const int type = RNA_property_type(prop); + const int flag = RNA_property_flag(prop); if (RNA_property_array_check(prop)) { int a, len; if (flag & PROP_DYNAMIC) { - ParameterDynAlloc *data_alloc= data; - len= data_alloc->array_tot; - data= data_alloc->array; + ParameterDynAlloc *data_alloc = data; + len = data_alloc->array_tot; + data = data_alloc->array; } else - len= RNA_property_array_length(ptr, prop); + len = RNA_property_array_length(ptr, prop); /* resolve the array from a new pytype */ @@ -4606,36 +4610,36 @@ static PyObject *pyrna_param_to_py(PointerRNA *ptr, PropertyRNA *prop, void *dat switch (type) { case PROP_BOOLEAN: - ret= PyTuple_New(len); - for (a=0; a<len; a++) - PyTuple_SET_ITEM(ret, a, PyBool_FromLong(((int*)data)[a])); + ret = PyTuple_New(len); + for (a = 0; a < len; a++) + PyTuple_SET_ITEM(ret, a, PyBool_FromLong(((int *)data)[a])); break; case PROP_INT: - ret= PyTuple_New(len); - for (a=0; a<len; a++) - PyTuple_SET_ITEM(ret, a, PyLong_FromSsize_t((Py_ssize_t)((int*)data)[a])); + ret = PyTuple_New(len); + for (a = 0; a < len; a++) + PyTuple_SET_ITEM(ret, a, PyLong_FromSsize_t((Py_ssize_t)((int *)data)[a])); break; case PROP_FLOAT: switch (RNA_property_subtype(prop)) { #ifdef USE_MATHUTILS case PROP_ALL_VECTOR_SUBTYPES: - ret= Vector_CreatePyObject(data, len, Py_NEW, NULL); + ret = Vector_CreatePyObject(data, len, Py_NEW, NULL); break; case PROP_MATRIX: - if (len==16) { - ret= Matrix_CreatePyObject(data, 4, 4, Py_NEW, NULL); + if (len == 16) { + ret = Matrix_CreatePyObject(data, 4, 4, Py_NEW, NULL); break; } - else if (len==9) { - ret= Matrix_CreatePyObject(data, 3, 3, Py_NEW, NULL); + else if (len == 9) { + ret = Matrix_CreatePyObject(data, 3, 3, Py_NEW, NULL); break; } /* pass through */ #endif default: - ret= PyTuple_New(len); - for (a=0; a<len; a++) - PyTuple_SET_ITEM(ret, a, PyFloat_FromDouble(((float*)data)[a])); + ret = PyTuple_New(len); + for (a = 0; a < len; a++) + PyTuple_SET_ITEM(ret, a, PyFloat_FromDouble(((float *)data)[a])); } break; @@ -4643,7 +4647,7 @@ static PyObject *pyrna_param_to_py(PointerRNA *ptr, PropertyRNA *prop, void *dat PyErr_Format(PyExc_TypeError, "RNA Error: unknown array type \"%d\" (pyrna_param_to_py)", type); - ret= NULL; + ret = NULL; break; } } @@ -4651,41 +4655,41 @@ static PyObject *pyrna_param_to_py(PointerRNA *ptr, PropertyRNA *prop, void *dat /* see if we can coorce into a python type - PropertyType */ switch (type) { case PROP_BOOLEAN: - ret= PyBool_FromLong(*(int*)data); + ret = PyBool_FromLong(*(int *)data); break; case PROP_INT: - ret= PyLong_FromSsize_t((Py_ssize_t)*(int*)data); + ret = PyLong_FromSsize_t((Py_ssize_t)*(int *)data); break; case PROP_FLOAT: - ret= PyFloat_FromDouble(*(float*)data); + ret = PyFloat_FromDouble(*(float *)data); break; case PROP_STRING: { char *data_ch; - PyObject *value_coerce= NULL; - const int subtype= RNA_property_subtype(prop); + PyObject *value_coerce = NULL; + const int subtype = RNA_property_subtype(prop); if (flag & PROP_THICK_WRAP) - data_ch= (char *)data; + data_ch = (char *)data; else - data_ch= *(char **)data; + data_ch = *(char **)data; #ifdef USE_STRING_COERCE if (subtype == PROP_BYTESTRING) { - ret= PyBytes_FromString(data_ch); + ret = PyBytes_FromString(data_ch); } else if (ELEM3(subtype, PROP_FILEPATH, PROP_DIRPATH, PROP_FILENAME)) { - ret= PyC_UnicodeFromByte(data_ch); + ret = PyC_UnicodeFromByte(data_ch); } else { - ret= PyUnicode_FromString(data_ch); + ret = PyUnicode_FromString(data_ch); } #else if (subtype == PROP_BYTESTRING) { - ret= PyBytes_FromString(buf); + ret = PyBytes_FromString(buf); } else { - ret= PyUnicode_FromString(data_ch); + ret = PyUnicode_FromString(data_ch); } #endif @@ -4697,50 +4701,50 @@ static PyObject *pyrna_param_to_py(PointerRNA *ptr, PropertyRNA *prop, void *dat } case PROP_ENUM: { - ret= pyrna_enum_to_py(ptr, prop, *(int*)data); + ret = pyrna_enum_to_py(ptr, prop, *(int *)data); break; } case PROP_POINTER: { PointerRNA newptr; - StructRNA *ptype= RNA_property_pointer_type(ptr, prop); + StructRNA *ptype = RNA_property_pointer_type(ptr, prop); if (flag & PROP_RNAPTR) { /* in this case we get the full ptr */ - newptr= *(PointerRNA*)data; + newptr = *(PointerRNA *)data; } else { if (RNA_struct_is_ID(ptype)) { - RNA_id_pointer_create(*(void**)data, &newptr); + RNA_id_pointer_create(*(void **)data, &newptr); } else { /* note: this is taken from the function's ID pointer * and will break if a function returns a pointer from * another ID block, watch this! - it should at least be * easy to debug since they are all ID's */ - RNA_pointer_create(ptr->id.data, ptype, *(void**)data, &newptr); + RNA_pointer_create(ptr->id.data, ptype, *(void **)data, &newptr); } } if (newptr.data) { - ret= pyrna_struct_CreatePyObject(&newptr); + ret = pyrna_struct_CreatePyObject(&newptr); } else { - ret= Py_None; + ret = Py_None; Py_INCREF(ret); } break; } case PROP_COLLECTION: { - ListBase *lb= (ListBase*)data; + ListBase *lb = (ListBase *)data; CollectionPointerLink *link; PyObject *linkptr; - ret= PyList_New(0); + ret = PyList_New(0); - for (link=lb->first; link; link=link->next) { - linkptr= pyrna_struct_CreatePyObject(&link->ptr); + for (link = lb->first; link; link = link->next) { + linkptr = pyrna_struct_CreatePyObject(&link->ptr); PyList_Append(ret, linkptr); Py_DECREF(linkptr); } @@ -4751,7 +4755,7 @@ static PyObject *pyrna_param_to_py(PointerRNA *ptr, PropertyRNA *prop, void *dat PyErr_Format(PyExc_TypeError, "RNA Error: unknown type \"%d\" (pyrna_param_to_py)", type); - ret= NULL; + ret = NULL; break; } } @@ -4764,13 +4768,13 @@ static PyObject *pyrna_param_to_py(PointerRNA *ptr, PropertyRNA *prop, void *dat * works on small dict's such as keyword args. */ static PyObject *small_dict_get_item_string(PyObject *dict, const char *key_lookup) { - PyObject *key= NULL; + PyObject *key = NULL; Py_ssize_t pos = 0; PyObject *value = NULL; while (PyDict_Next(dict, &pos, &key, &value)) { if (PyUnicode_Check(key)) { - if (strcmp(key_lookup, _PyUnicode_AsString(key))==0) { + if (strcmp(key_lookup, _PyUnicode_AsString(key)) == 0) { return value; } } @@ -4782,36 +4786,36 @@ static PyObject *small_dict_get_item_string(PyObject *dict, const char *key_look static PyObject *pyrna_func_call(BPy_FunctionRNA *self, PyObject *args, PyObject *kw) { /* Note, both BPy_StructRNA and BPy_PropertyRNA can be used here */ - PointerRNA *self_ptr= &self->ptr; - FunctionRNA *self_func= self->func; + PointerRNA *self_ptr = &self->ptr; + FunctionRNA *self_func = self->func; PointerRNA funcptr; ParameterList parms; ParameterIterator iter; PropertyRNA *parm; PyObject *ret, *item; - int i, pyargs_len, pykw_len, parms_len, ret_len, flag, err= 0, kw_tot= 0, kw_arg; + int i, pyargs_len, pykw_len, parms_len, ret_len, flag, err = 0, kw_tot = 0, kw_arg; - PropertyRNA *pret_single= NULL; - void *retdata_single= NULL; + PropertyRNA *pret_single = NULL; + void *retdata_single = NULL; /* enable this so all strings are copied and freed after calling. * this exposes bugs where the pointer to the string is held and re-used */ // #define DEBUG_STRING_FREE #ifdef DEBUG_STRING_FREE - PyObject *string_free_ls= PyList_New(0); + PyObject *string_free_ls = PyList_New(0); #endif /* Should never happen but it does in rare cases */ BLI_assert(self_ptr != NULL); - if (self_ptr==NULL) { + if (self_ptr == NULL) { PyErr_SetString(PyExc_RuntimeError, "rna functions internal rna pointer is NULL, this is a bug. aborting"); return NULL; } - if (self_func==NULL) { + if (self_func == NULL) { PyErr_Format(PyExc_RuntimeError, "%.200s.<unknown>(): rna function internal function is NULL, this is a bug. aborting", RNA_struct_identifier(self_ptr->type)); @@ -4834,13 +4838,13 @@ static PyObject *pyrna_func_call(BPy_FunctionRNA *self, PyObject *args, PyObject * the same ID as the functions. */ RNA_pointer_create(self_ptr->id.data, &RNA_Function, self_func, &funcptr); - pyargs_len= PyTuple_GET_SIZE(args); - pykw_len= kw ? PyDict_Size(kw) : 0; + pyargs_len = PyTuple_GET_SIZE(args); + pykw_len = kw ? PyDict_Size(kw) : 0; RNA_parameter_list_create(&parms, self_ptr, self_func); RNA_parameter_list_begin(&parms, &iter); - parms_len= RNA_parameter_list_arg_count(&parms); - ret_len= 0; + parms_len = RNA_parameter_list_arg_count(&parms); + ret_len = 0; if (pyargs_len + pykw_len > parms_len) { RNA_parameter_list_end(&iter); @@ -4848,53 +4852,53 @@ static PyObject *pyrna_func_call(BPy_FunctionRNA *self, PyObject *args, PyObject "%.200s.%.200s(): takes at most %d arguments, got %d", RNA_struct_identifier(self_ptr->type), RNA_function_identifier(self_func), parms_len, pyargs_len + pykw_len); - err= -1; + err = -1; } /* parse function parameters */ - for (i= 0; iter.valid && err==0; RNA_parameter_list_next(&iter)) { - parm= iter.parm; - flag= RNA_property_flag(parm); + for (i = 0; iter.valid && err == 0; RNA_parameter_list_next(&iter)) { + parm = iter.parm; + flag = RNA_property_flag(parm); /* only useful for single argument returns, we'll need another list loop for multiple */ if (flag & PROP_OUTPUT) { ret_len++; - if (pret_single==NULL) { - pret_single= parm; - retdata_single= iter.data; + if (pret_single == NULL) { + pret_single = parm; + retdata_single = iter.data; } continue; } - item= NULL; + item = NULL; if (i < pyargs_len) { - item= PyTuple_GET_ITEM(args, i); - kw_arg= FALSE; + item = PyTuple_GET_ITEM(args, i); + kw_arg = FALSE; } else if (kw != NULL) { #if 0 - item= PyDict_GetItemString(kw, RNA_property_identifier(parm)); /* borrow ref */ + item = PyDict_GetItemString(kw, RNA_property_identifier(parm)); /* borrow ref */ #else - item= small_dict_get_item_string(kw, RNA_property_identifier(parm)); /* borrow ref */ + item = small_dict_get_item_string(kw, RNA_property_identifier(parm)); /* borrow ref */ #endif if (item) kw_tot++; /* make sure invalid keywords are not given */ - kw_arg= TRUE; + kw_arg = TRUE; } i++; /* current argument */ - if (item==NULL) { + if (item == NULL) { if (flag & PROP_REQUIRED) { PyErr_Format(PyExc_TypeError, "%.200s.%.200s(): required parameter \"%.200s\" not specified", RNA_struct_identifier(self_ptr->type), RNA_function_identifier(self_func), RNA_property_identifier(parm)); - err= -1; + err = -1; break; } else { /* PyDict_GetItemString wont raise an error */ @@ -4905,21 +4909,21 @@ static PyObject *pyrna_func_call(BPy_FunctionRNA *self, PyObject *args, PyObject #ifdef DEBUG_STRING_FREE if (item) { if (PyUnicode_Check(item)) { - item= PyUnicode_FromString(_PyUnicode_AsString(item)); + item = PyUnicode_FromString(_PyUnicode_AsString(item)); PyList_Append(string_free_ls, item); Py_DECREF(item); } } #endif - err= pyrna_py_to_prop(&funcptr, parm, iter.data, item, ""); + err = pyrna_py_to_prop(&funcptr, parm, iter.data, item, ""); - if (err!=0) { + if (err != 0) { /* the error generated isn't that useful, so generate it again with a useful prefix * could also write a function to prepend to error messages */ char error_prefix[512]; PyErr_Clear(); /* re-raise */ - if (kw_arg==TRUE) + if (kw_arg == TRUE) BLI_snprintf(error_prefix, sizeof(error_prefix), "%.200s.%.200s(): error with keyword argument \"%.200s\" - ", RNA_struct_identifier(self_ptr->type), @@ -4948,59 +4952,59 @@ static PyObject *pyrna_func_call(BPy_FunctionRNA *self, PyObject *args, PyObject */ if (err == 0 && kw && (pykw_len > kw_tot)) { PyObject *key, *value; - Py_ssize_t pos= 0; + Py_ssize_t pos = 0; - DynStr *bad_args= BLI_dynstr_new(); - DynStr *good_args= BLI_dynstr_new(); + DynStr *bad_args = BLI_dynstr_new(); + DynStr *good_args = BLI_dynstr_new(); const char *arg_name, *bad_args_str, *good_args_str; - int found= FALSE, first= TRUE; + int found = FALSE, first = TRUE; while (PyDict_Next(kw, &pos, &key, &value)) { - arg_name= _PyUnicode_AsString(key); - found= FALSE; + arg_name = _PyUnicode_AsString(key); + found = FALSE; - if (arg_name==NULL) { /* unlikely the argname is not a string but ignore if it is*/ + if (arg_name == NULL) { /* unlikely the argname is not a string but ignore if it is*/ PyErr_Clear(); } else { /* Search for arg_name */ RNA_parameter_list_begin(&parms, &iter); for (; iter.valid; RNA_parameter_list_next(&iter)) { - parm= iter.parm; - if (strcmp(arg_name, RNA_property_identifier(parm))==0) { - found= TRUE; + parm = iter.parm; + if (strcmp(arg_name, RNA_property_identifier(parm)) == 0) { + found = TRUE; break; } } RNA_parameter_list_end(&iter); - if (found==FALSE) { + if (found == FALSE) { BLI_dynstr_appendf(bad_args, first ? "%s" : ", %s", arg_name); - first= FALSE; + first = FALSE; } } } /* list good args */ - first= TRUE; + first = TRUE; RNA_parameter_list_begin(&parms, &iter); for (; iter.valid; RNA_parameter_list_next(&iter)) { - parm= iter.parm; + parm = iter.parm; if (RNA_property_flag(parm) & PROP_OUTPUT) continue; BLI_dynstr_appendf(good_args, first ? "%s" : ", %s", RNA_property_identifier(parm)); - first= FALSE; + first = FALSE; } RNA_parameter_list_end(&iter); - bad_args_str= BLI_dynstr_get_cstring(bad_args); - good_args_str= BLI_dynstr_get_cstring(good_args); + bad_args_str = BLI_dynstr_get_cstring(bad_args); + good_args_str = BLI_dynstr_get_cstring(good_args); PyErr_Format(PyExc_TypeError, "%.200s.%.200s(): was called with invalid keyword arguments(s) (%s), expected (%s)", @@ -5012,32 +5016,32 @@ static PyObject *pyrna_func_call(BPy_FunctionRNA *self, PyObject *args, PyObject MEM_freeN((void *)bad_args_str); MEM_freeN((void *)good_args_str); - err= -1; + err = -1; } - ret= NULL; - if (err==0) { + ret = NULL; + if (err == 0) { /* call function */ ReportList reports; - bContext *C= BPy_GetContext(); + bContext *C = BPy_GetContext(); BKE_reports_init(&reports, RPT_STORE); RNA_function_call(C, &reports, self_ptr, self_func, &parms); - err= (BPy_reports_to_error(&reports, PyExc_RuntimeError, TRUE)); + err = (BPy_reports_to_error(&reports, PyExc_RuntimeError, TRUE)); /* return value */ if (err != -1) { if (ret_len > 0) { if (ret_len > 1) { - ret= PyTuple_New(ret_len); - i= 0; /* arg index */ + ret = PyTuple_New(ret_len); + i = 0; /* arg index */ RNA_parameter_list_begin(&parms, &iter); for (; iter.valid; RNA_parameter_list_next(&iter)) { - parm= iter.parm; - flag= RNA_property_flag(parm); + parm = iter.parm; + flag = RNA_property_flag(parm); if (flag & PROP_OUTPUT) PyTuple_SET_ITEM(ret, i++, pyrna_param_to_py(&funcptr, parm, iter.data)); @@ -5046,11 +5050,11 @@ static PyObject *pyrna_func_call(BPy_FunctionRNA *self, PyObject *args, PyObject RNA_parameter_list_end(&iter); } else - ret= pyrna_param_to_py(&funcptr, pret_single, retdata_single); + ret = pyrna_param_to_py(&funcptr, pret_single, retdata_single); /* possible there is an error in conversion */ - if (ret==NULL) - err= -1; + if (ret == NULL) + err = -1; } } } @@ -5069,7 +5073,7 @@ static PyObject *pyrna_func_call(BPy_FunctionRNA *self, PyObject *args, PyObject if (ret) return ret; - if (err==-1) + if (err == -1) return NULL; Py_RETURN_NONE; @@ -5078,7 +5082,7 @@ static PyObject *pyrna_func_call(BPy_FunctionRNA *self, PyObject *args, PyObject /* subclasses of pyrna_struct_Type which support idprop definitions use this as a metaclass */ /* note: tp_base member is set to &PyType_Type on init */ -PyTypeObject pyrna_struct_meta_idprop_Type= { +PyTypeObject pyrna_struct_meta_idprop_Type = { PyVarObject_HEAD_INIT(NULL, 0) "bpy_struct_meta_idprop", /* tp_name */ sizeof(PyHeapTypeObject), /* tp_basicsize */ // XXX, would be PyTypeObject, but subtypes of Type must be PyHeapTypeObject's @@ -5160,7 +5164,7 @@ PyTypeObject pyrna_struct_meta_idprop_Type= { /*-----------------------BPy_StructRNA method def------------------------------*/ -PyTypeObject pyrna_struct_Type= { +PyTypeObject pyrna_struct_Type = { PyVarObject_HEAD_INIT(NULL, 0) "bpy_struct", /* tp_name */ sizeof(BPy_StructRNA), /* tp_basicsize */ @@ -5249,7 +5253,7 @@ PyTypeObject pyrna_struct_Type= { }; /*-----------------------BPy_PropertyRNA method def------------------------------*/ -PyTypeObject pyrna_prop_Type= { +PyTypeObject pyrna_prop_Type = { PyVarObject_HEAD_INIT(NULL, 0) "bpy_prop", /* tp_name */ sizeof(BPy_PropertyRNA), /* tp_basicsize */ @@ -5333,7 +5337,7 @@ PyTypeObject pyrna_prop_Type= { NULL }; -PyTypeObject pyrna_prop_array_Type= { +PyTypeObject pyrna_prop_array_Type = { PyVarObject_HEAD_INIT(NULL, 0) "bpy_prop_array", /* tp_name */ sizeof(BPy_PropertyArrayRNA), /* tp_basicsize */ @@ -5416,7 +5420,7 @@ PyTypeObject pyrna_prop_array_Type= { NULL }; -PyTypeObject pyrna_prop_collection_Type= { +PyTypeObject pyrna_prop_collection_Type = { PyVarObject_HEAD_INIT(NULL, 0) "bpy_prop_collection", /* tp_name */ sizeof(BPy_PropertyRNA), /* tp_basicsize */ @@ -5501,7 +5505,7 @@ PyTypeObject pyrna_prop_collection_Type= { }; /* only for add/remove/move methods */ -static PyTypeObject pyrna_prop_collection_idprop_Type= { +static PyTypeObject pyrna_prop_collection_idprop_Type = { PyVarObject_HEAD_INIT(NULL, 0) "bpy_prop_collection_idprop", /* tp_name */ sizeof(BPy_PropertyRNA), /* tp_basicsize */ @@ -5586,7 +5590,7 @@ static PyTypeObject pyrna_prop_collection_idprop_Type= { }; /*-----------------------BPy_PropertyRNA method def------------------------------*/ -PyTypeObject pyrna_func_Type= { +PyTypeObject pyrna_func_Type = { PyVarObject_HEAD_INIT(NULL, 0) "bpy_func", /* tp_name */ sizeof(BPy_FunctionRNA), /* tp_basicsize */ @@ -5682,7 +5686,7 @@ PyTypeObject pyrna_func_Type= { static void pyrna_prop_collection_iter_dealloc(BPy_PropertyCollectionIterRNA *self); static PyObject *pyrna_prop_collection_iter_next(BPy_PropertyCollectionIterRNA *self); -PyTypeObject pyrna_prop_collection_iter_Type= { +PyTypeObject pyrna_prop_collection_iter_Type = { PyVarObject_HEAD_INIT(NULL, 0) "bpy_prop_collection_iter", /* tp_name */ sizeof(BPy_PropertyCollectionIterRNA), /* tp_basicsize */ @@ -5775,10 +5779,10 @@ PyTypeObject pyrna_prop_collection_iter_Type= { PyObject *pyrna_prop_collection_iter_CreatePyObject(PointerRNA *ptr, PropertyRNA *prop) { - BPy_PropertyCollectionIterRNA *self= PyObject_New(BPy_PropertyCollectionIterRNA, &pyrna_prop_collection_iter_Type); + BPy_PropertyCollectionIterRNA *self = PyObject_New(BPy_PropertyCollectionIterRNA, &pyrna_prop_collection_iter_Type); #ifdef USE_WEAKREFS - self->in_weakreflist= NULL; + self->in_weakreflist = NULL; #endif RNA_property_collection_begin(ptr, prop, &self->iter); @@ -5798,7 +5802,7 @@ static PyObject *pyrna_prop_collection_iter_next(BPy_PropertyCollectionIterRNA * return NULL; } else { - BPy_StructRNA *pyrna= (BPy_StructRNA *)pyrna_struct_CreatePyObject(&self->iter.ptr); + BPy_StructRNA *pyrna = (BPy_StructRNA *)pyrna_struct_CreatePyObject(&self->iter.ptr); #ifdef USE_PYRNA_STRUCT_REFERENCE if (pyrna) { /* unlikely but may fail */ @@ -5854,7 +5858,7 @@ static void pyrna_subtype_set_rna(PyObject *newclass, StructRNA *srna) /* python deals with the circular ref */ RNA_pointer_create(NULL, &RNA_Struct, srna, &ptr); - item= pyrna_struct_CreatePyObject(&ptr); + item = pyrna_struct_CreatePyObject(&ptr); /* note, must set the class not the __dict__ else the internal slots are not updated correctly */ PyObject_SetAttr(newclass, bpy_intern_str_bl_rna, item); @@ -5871,19 +5875,19 @@ static PyObject* pyrna_srna_PyBase(StructRNA *srna) //, PyObject *bpy_types_dict /* Assume RNA_struct_py_type_get(srna) was already checked */ StructRNA *base; - PyObject *py_base= NULL; + PyObject *py_base = NULL; /* get the base type */ - base= RNA_struct_base(srna); + base = RNA_struct_base(srna); if (base && base != srna) { /*/printf("debug subtype %s %p\n", RNA_struct_identifier(srna), srna); */ - py_base= pyrna_srna_Subtype(base); //, bpy_types_dict); + py_base = pyrna_srna_Subtype(base); //, bpy_types_dict); Py_DECREF(py_base); /* srna owns, this is only to pass as an arg */ } - if (py_base==NULL) { - py_base= (PyObject *)&pyrna_struct_Type; + if (py_base == NULL) { + py_base = (PyObject *)&pyrna_struct_Type; } return py_base; @@ -5891,47 +5895,47 @@ static PyObject* pyrna_srna_PyBase(StructRNA *srna) //, PyObject *bpy_types_dict /* check if we have a native python subclass, use it when it exists * return a borrowed reference */ -static PyObject *bpy_types_dict= NULL; +static PyObject *bpy_types_dict = NULL; static PyObject* pyrna_srna_ExternalType(StructRNA *srna) { - const char *idname= RNA_struct_identifier(srna); + const char *idname = RNA_struct_identifier(srna); PyObject *newclass; - if (bpy_types_dict==NULL) { - PyObject *bpy_types= PyImport_ImportModuleLevel((char *)"bpy_types", NULL, NULL, NULL, 0); + if (bpy_types_dict == NULL) { + PyObject *bpy_types = PyImport_ImportModuleLevel((char *)"bpy_types", NULL, NULL, NULL, 0); - if (bpy_types==NULL) { + if (bpy_types == NULL) { PyErr_Print(); PyErr_Clear(); fprintf(stderr, "%s: failed to find 'bpy_types' module\n", __func__); return NULL; } - bpy_types_dict= PyModule_GetDict(bpy_types); // borrow + bpy_types_dict = PyModule_GetDict(bpy_types); // borrow Py_DECREF(bpy_types); // fairly safe to assume the dict is kept } - newclass= PyDict_GetItemString(bpy_types_dict, idname); + newclass = PyDict_GetItemString(bpy_types_dict, idname); /* sanity check, could skip this unless in debug mode */ if (newclass) { - PyObject *base_compare= pyrna_srna_PyBase(srna); - //PyObject *slots= PyObject_GetAttrString(newclass, "__slots__"); // cant do this because it gets superclasses values! - //PyObject *bases= PyObject_GetAttrString(newclass, "__bases__"); // can do this but faster not to. - PyObject *tp_bases= ((PyTypeObject *)newclass)->tp_bases; - PyObject *tp_slots= PyDict_GetItem(((PyTypeObject *)newclass)->tp_dict, bpy_intern_str___slots__); + PyObject *base_compare = pyrna_srna_PyBase(srna); + //PyObject *slots = PyObject_GetAttrString(newclass, "__slots__"); // cant do this because it gets superclasses values! + //PyObject *bases = PyObject_GetAttrString(newclass, "__bases__"); // can do this but faster not to. + PyObject *tp_bases = ((PyTypeObject *)newclass)->tp_bases; + PyObject *tp_slots = PyDict_GetItem(((PyTypeObject *)newclass)->tp_dict, bpy_intern_str___slots__); - if (tp_slots==NULL) { + if (tp_slots == NULL) { fprintf(stderr, "%s: expected class '%s' to have __slots__ defined\n\nSee bpy_types.py\n", __func__, idname); - newclass= NULL; + newclass = NULL; } else if (PyTuple_GET_SIZE(tp_bases)) { - PyObject *base= PyTuple_GET_ITEM(tp_bases, 0); + PyObject *base = PyTuple_GET_ITEM(tp_bases, 0); if (base_compare != base) { fprintf(stderr, "%s: incorrect subclassing of SRNA '%s'\nSee bpy_types.py\n", __func__, idname); PyC_ObSpit("Expected! ", base_compare); - newclass= NULL; + newclass = NULL; } else { if (G.f & G_DEBUG) @@ -5945,16 +5949,16 @@ static PyObject* pyrna_srna_ExternalType(StructRNA *srna) static PyObject* pyrna_srna_Subtype(StructRNA *srna) { - PyObject *newclass= NULL; + PyObject *newclass = NULL; /* stupid/simple case */ if (srna == NULL) { - newclass= NULL; /* Nothing to do */ + newclass = NULL; /* Nothing to do */ } /* the class may have already been declared & allocated */ - else if ((newclass= RNA_struct_py_type_get(srna))) { + else if ((newclass = RNA_struct_py_type_get(srna))) { Py_INCREF(newclass); } /* check if bpy_types.py module has the class defined in it */ - else if ((newclass= pyrna_srna_ExternalType(srna))) { + else if ((newclass = pyrna_srna_ExternalType(srna))) { pyrna_subtype_set_rna(newclass, srna); Py_INCREF(newclass); } /* create a new class instance with the C api @@ -5962,32 +5966,32 @@ static PyObject* pyrna_srna_Subtype(StructRNA *srna) else { /* subclass equivalents - class myClass(myBase): - some='value' # or ... - - myClass= type(name='myClass', bases=(myBase,), dict={'__module__':'bpy.types'}) + some = 'value' # or ... + - myClass = type(name='myClass', bases=(myBase,), dict={'__module__':'bpy.types'}) */ /* Assume RNA_struct_py_type_get(srna) was already checked */ - PyObject *py_base= pyrna_srna_PyBase(srna); + PyObject *py_base = pyrna_srna_PyBase(srna); PyObject *metaclass; - const char *idname= RNA_struct_identifier(srna); + const char *idname = RNA_struct_identifier(srna); /* remove __doc__ for now */ - // const char *descr= RNA_struct_ui_description(srna); - // if (!descr) descr= "(no docs)"; + // const char *descr = RNA_struct_ui_description(srna); + // if (!descr) descr = "(no docs)"; // "__doc__", descr if ( RNA_struct_idprops_check(srna) && !PyObject_IsSubclass(py_base, (PyObject *)&pyrna_struct_meta_idprop_Type)) { - metaclass= (PyObject *)&pyrna_struct_meta_idprop_Type; + metaclass = (PyObject *)&pyrna_struct_meta_idprop_Type; } else { - metaclass= (PyObject *)&PyType_Type; + metaclass = (PyObject *)&PyType_Type; } /* always use O not N when calling, N causes refcount errors */ - newclass= PyObject_CallFunction(metaclass, (char *)"s(O){sss()}", - idname, py_base, "__module__","bpy.types", "__slots__"); + newclass = PyObject_CallFunction(metaclass, (char *)"s(O){sss()}", + idname, py_base, "__module__","bpy.types", "__slots__"); /* newclass will now have 2 ref's, ???, probably 1 is internal since decrefing here segfaults */ @@ -6031,24 +6035,24 @@ static PyObject* pyrna_struct_Subtype(PointerRNA *ptr) /*-----------------------CreatePyObject---------------------------------*/ PyObject *pyrna_struct_CreatePyObject(PointerRNA *ptr) { - BPy_StructRNA *pyrna= NULL; + BPy_StructRNA *pyrna = NULL; /* note: don't rely on this to return None since NULL data with a valid type can often crash */ - if (ptr->data==NULL && ptr->type==NULL) { /* Operator RNA has NULL data */ + if (ptr->data == NULL && ptr->type == NULL) { /* Operator RNA has NULL data */ Py_RETURN_NONE; } else { - PyTypeObject *tp= (PyTypeObject *)pyrna_struct_Subtype(ptr); + PyTypeObject *tp = (PyTypeObject *)pyrna_struct_Subtype(ptr); if (tp) { - pyrna= (BPy_StructRNA *) tp->tp_alloc(tp, 0); + pyrna = (BPy_StructRNA *) tp->tp_alloc(tp, 0); Py_DECREF(tp); /* srna owns, cant hold a ref */ } else { fprintf(stderr, "%s: could not make type\n", __func__); - pyrna= (BPy_StructRNA *) PyObject_GC_New(BPy_StructRNA, &pyrna_struct_Type); + pyrna = (BPy_StructRNA *) PyObject_GC_New(BPy_StructRNA, &pyrna_struct_Type); #ifdef USE_WEAKREFS - pyrna->in_weakreflist= NULL; + pyrna->in_weakreflist = NULL; #endif } } @@ -6058,13 +6062,13 @@ PyObject *pyrna_struct_CreatePyObject(PointerRNA *ptr) return NULL; } - pyrna->ptr= *ptr; + pyrna->ptr = *ptr; #ifdef PYRNA_FREE_SUPPORT - pyrna->freeptr= FALSE; + pyrna->freeptr = FALSE; #endif #ifdef USE_PYRNA_STRUCT_REFERENCE - pyrna->reference= NULL; + pyrna->reference = NULL; #endif // PyC_ObSpit("NewStructRNA: ", (PyObject *)pyrna); @@ -6085,28 +6089,28 @@ PyObject *pyrna_prop_CreatePyObject(PointerRNA *ptr, PropertyRNA *prop) PyTypeObject *type; if (RNA_property_type(prop) != PROP_COLLECTION) { - type= &pyrna_prop_Type; + type = &pyrna_prop_Type; } else { if ((RNA_property_flag(prop) & PROP_IDPROPERTY) == 0) { - type= &pyrna_prop_collection_Type; + type = &pyrna_prop_collection_Type; } else { - type= &pyrna_prop_collection_idprop_Type; + type = &pyrna_prop_collection_idprop_Type; } } - pyrna= (BPy_PropertyRNA *) PyObject_NEW(BPy_PropertyRNA, type); + pyrna = (BPy_PropertyRNA *) PyObject_NEW(BPy_PropertyRNA, type); #ifdef USE_WEAKREFS - pyrna->in_weakreflist= NULL; + pyrna->in_weakreflist = NULL; #endif } else { - pyrna= (BPy_PropertyRNA *) PyObject_NEW(BPy_PropertyArrayRNA, &pyrna_prop_array_Type); - ((BPy_PropertyArrayRNA *)pyrna)->arraydim= 0; - ((BPy_PropertyArrayRNA *)pyrna)->arrayoffset= 0; + pyrna = (BPy_PropertyRNA *) PyObject_NEW(BPy_PropertyArrayRNA, &pyrna_prop_array_Type); + ((BPy_PropertyArrayRNA *)pyrna)->arraydim = 0; + ((BPy_PropertyArrayRNA *)pyrna)->arrayoffset = 0; #ifdef USE_WEAKREFS - ((BPy_PropertyArrayRNA *)pyrna)->in_weakreflist= NULL; + ((BPy_PropertyArrayRNA *)pyrna)->in_weakreflist = NULL; #endif } @@ -6115,8 +6119,8 @@ PyObject *pyrna_prop_CreatePyObject(PointerRNA *ptr, PropertyRNA *prop) return NULL; } - pyrna->ptr= *ptr; - pyrna->prop= prop; + pyrna->ptr = *ptr; + pyrna->prop = prop; #ifdef USE_PYRNA_INVALIDATE_WEAKREF if (ptr->id.data) { @@ -6130,16 +6134,16 @@ PyObject *pyrna_prop_CreatePyObject(PointerRNA *ptr, PropertyRNA *prop) void BPY_rna_init(void) { #ifdef USE_MATHUTILS // register mathutils callbacks, ok to run more then once. - mathutils_rna_array_cb_index= Mathutils_RegisterCallback(&mathutils_rna_array_cb); - mathutils_rna_matrix_cb_index= Mathutils_RegisterCallback(&mathutils_rna_matrix_cb); + mathutils_rna_array_cb_index = Mathutils_RegisterCallback(&mathutils_rna_array_cb); + mathutils_rna_matrix_cb_index = Mathutils_RegisterCallback(&mathutils_rna_matrix_cb); #endif /* for some reason MSVC complains of these */ #if defined(_MSC_VER) || defined(FREE_WINDOWS) - pyrna_struct_meta_idprop_Type.tp_base= &PyType_Type; + pyrna_struct_meta_idprop_Type.tp_base = &PyType_Type; - pyrna_prop_collection_iter_Type.tp_iter= PyObject_SelfIter; - pyrna_prop_collection_iter_Type.tp_getattro= PyObject_GenericGetAttr; + pyrna_prop_collection_iter_Type.tp_iter = PyObject_SelfIter; + pyrna_prop_collection_iter_Type.tp_getattro = PyObject_GenericGetAttr; #endif /* metaclass */ @@ -6171,7 +6175,7 @@ void BPY_rna_init(void) } /* bpy.data from python */ -static PointerRNA *rna_module_ptr= NULL; +static PointerRNA *rna_module_ptr = NULL; PyObject *BPY_rna_module(void) { BPy_StructRNA *pyrna; @@ -6179,9 +6183,9 @@ PyObject *BPY_rna_module(void) /* for now, return the base RNA type rather than a real module */ RNA_main_pointer_create(G.main, &ptr); - pyrna= (BPy_StructRNA *)pyrna_struct_CreatePyObject(&ptr); + pyrna = (BPy_StructRNA *)pyrna_struct_CreatePyObject(&ptr); - rna_module_ptr= &pyrna->ptr; + rna_module_ptr = &pyrna->ptr; return (PyObject *)pyrna; } @@ -6190,7 +6194,7 @@ void BPY_update_rna_module(void) #if 0 RNA_main_pointer_create(G.main, rna_module_ptr); #else - rna_module_ptr->data= G.main; /* just set data is enough */ + rna_module_ptr->data = G.main; /* just set data is enough */ #endif } @@ -6216,15 +6220,15 @@ static PyObject *pyrna_basetype_getattro(BPy_BaseTypeRNA *self, PyObject *pyname { PointerRNA newptr; PyObject *ret; - const char *name= _PyUnicode_AsString(pyname); + const char *name = _PyUnicode_AsString(pyname); if (name == NULL) { PyErr_SetString(PyExc_AttributeError, "bpy.types: __getattr__ must be a string"); - ret= NULL; + ret = NULL; } else if (RNA_property_collection_lookup_string(&self->ptr, self->prop, name, &newptr)) { - ret= pyrna_struct_Subtype(&newptr); - if (ret==NULL) { + ret = pyrna_struct_Subtype(&newptr); + if (ret == NULL) { PyErr_Format(PyExc_RuntimeError, "bpy.types.%.200s subtype could not be generated, this is a bug!", _PyUnicode_AsString(pyname)); @@ -6238,7 +6242,7 @@ static PyObject *pyrna_basetype_getattro(BPy_BaseTypeRNA *self, PyObject *pyname return NULL; #endif /* The error raised here will be displayed */ - ret= PyObject_GenericGetAttr((PyObject *)self, pyname); + ret = PyObject_GenericGetAttr((PyObject *)self, pyname); } return ret; @@ -6248,7 +6252,7 @@ static PyObject *pyrna_basetype_dir(BPy_BaseTypeRNA *self); static PyObject *pyrna_register_class(PyObject *self, PyObject *py_class); static PyObject *pyrna_unregister_class(PyObject *self, PyObject *py_class); -static struct PyMethodDef pyrna_basetype_methods[]= { +static struct PyMethodDef pyrna_basetype_methods[] = { {"__dir__", (PyCFunction)pyrna_basetype_dir, METH_NOARGS, ""}, {NULL, NULL, 0, NULL} }; @@ -6261,11 +6265,11 @@ static PyObject *pyrna_basetype_dir(BPy_BaseTypeRNA *self) PyMethodDef *meth; #endif - list= pyrna_prop_collection_keys(self); /* like calling structs.keys(), avoids looping here */ + list = pyrna_prop_collection_keys(self); /* like calling structs.keys(), avoids looping here */ #if 0 /* for now only contains __dir__ */ - for (meth=pyrna_basetype_methods; meth->ml_name; meth++) { - name= PyUnicode_FromString(meth->ml_name); + for (meth = pyrna_basetype_methods; meth->ml_name; meth++) { + name = PyUnicode_FromString(meth->ml_name); PyList_Append(list, name); Py_DECREF(name); } @@ -6273,53 +6277,53 @@ static PyObject *pyrna_basetype_dir(BPy_BaseTypeRNA *self) return list; } -static PyTypeObject pyrna_basetype_Type= BLANK_PYTHON_TYPE; +static PyTypeObject pyrna_basetype_Type = BLANK_PYTHON_TYPE; PyObject *BPY_rna_types(void) { BPy_BaseTypeRNA *self; - if ((pyrna_basetype_Type.tp_flags & Py_TPFLAGS_READY)==0) { - pyrna_basetype_Type.tp_name= "RNA_Types"; - pyrna_basetype_Type.tp_basicsize= sizeof(BPy_BaseTypeRNA); - pyrna_basetype_Type.tp_getattro= (getattrofunc) pyrna_basetype_getattro; - pyrna_basetype_Type.tp_flags= Py_TPFLAGS_DEFAULT; - pyrna_basetype_Type.tp_methods= pyrna_basetype_methods; + if ((pyrna_basetype_Type.tp_flags & Py_TPFLAGS_READY) == 0) { + pyrna_basetype_Type.tp_name = "RNA_Types"; + pyrna_basetype_Type.tp_basicsize = sizeof(BPy_BaseTypeRNA); + pyrna_basetype_Type.tp_getattro = (getattrofunc) pyrna_basetype_getattro; + pyrna_basetype_Type.tp_flags = Py_TPFLAGS_DEFAULT; + pyrna_basetype_Type.tp_methods = pyrna_basetype_methods; if (PyType_Ready(&pyrna_basetype_Type) < 0) return NULL; } - self= (BPy_BaseTypeRNA *)PyObject_NEW(BPy_BaseTypeRNA, &pyrna_basetype_Type); + self = (BPy_BaseTypeRNA *)PyObject_NEW(BPy_BaseTypeRNA, &pyrna_basetype_Type); /* avoid doing this lookup for every getattr */ RNA_blender_rna_pointer_create(&self->ptr); - self->prop= RNA_struct_find_property(&self->ptr, "structs"); + self->prop = RNA_struct_find_property(&self->ptr, "structs"); #ifdef USE_WEAKREFS - self->in_weakreflist= NULL; + self->in_weakreflist = NULL; #endif return (PyObject *)self; } StructRNA *pyrna_struct_as_srna(PyObject *self, int parent, const char *error_prefix) { - BPy_StructRNA *py_srna= NULL; + BPy_StructRNA *py_srna = NULL; StructRNA *srna; /* ack, PyObject_GetAttrString wont look up this types tp_dict first :/ */ if (PyType_Check(self)) { - py_srna= (BPy_StructRNA *)PyDict_GetItem(((PyTypeObject *)self)->tp_dict, bpy_intern_str_bl_rna); + py_srna = (BPy_StructRNA *)PyDict_GetItem(((PyTypeObject *)self)->tp_dict, bpy_intern_str_bl_rna); Py_XINCREF(py_srna); } if (parent) { /* be very careful with this since it will return a parent classes srna. * modifying this will do confusing stuff! */ - if (py_srna==NULL) - py_srna= (BPy_StructRNA*)PyObject_GetAttr(self, bpy_intern_str_bl_rna); + if (py_srna == NULL) + py_srna = (BPy_StructRNA *)PyObject_GetAttr(self, bpy_intern_str_bl_rna); } - if (py_srna==NULL) { + if (py_srna == NULL) { PyErr_Format(PyExc_RuntimeError, "%.200s, missing bl_rna attribute from '%.200s' instance (may not be registered)", error_prefix, Py_TYPE(self)->tp_name); @@ -6343,7 +6347,7 @@ StructRNA *pyrna_struct_as_srna(PyObject *self, int parent, const char *error_pr return NULL; } - srna= py_srna->ptr.data; + srna = py_srna->ptr.data; Py_DECREF(py_srna); return srna; @@ -6356,13 +6360,13 @@ StructRNA *pyrna_struct_as_srna(PyObject *self, int parent, const char *error_pr StructRNA *srna_from_self(PyObject *self, const char *error_prefix) { - if (self==NULL) { + if (self == NULL) { return NULL; } else if (PyCapsule_CheckExact(self)) { return PyCapsule_GetPointer(self, NULL); } - else if (PyType_Check(self)==0) { + else if (PyType_Check(self) == 0) { return NULL; } else { @@ -6375,7 +6379,7 @@ StructRNA *srna_from_self(PyObject *self, const char *error_prefix) PyErr_Fetch(&error_type, &error_value, &error_traceback); PyErr_Clear(); - srna= pyrna_struct_as_srna(self, 0, error_prefix); + srna = pyrna_struct_as_srna(self, 0, error_prefix); if (!PyErr_Occurred()) { PyErr_Restore(error_type, error_value, error_traceback); @@ -6396,22 +6400,22 @@ static int deferred_register_prop(StructRNA *srna, PyObject *key, PyObject *item if (PyArg_ParseTuple(item, "OO!", &py_func, &PyDict_Type, &py_kw)) { PyObject *args_fake; - if (*_PyUnicode_AsString(key)=='_') { + if (*_PyUnicode_AsString(key) == '_') { PyErr_Format(PyExc_ValueError, "bpy_struct \"%.200s\" registration error: " "%.200s could not register because the property starts with an '_'\n", RNA_struct_identifier(srna), _PyUnicode_AsString(key)); return -1; } - py_srna_cobject= PyCapsule_New(srna, NULL, NULL); + py_srna_cobject = PyCapsule_New(srna, NULL, NULL); /* not 100% nice :/, modifies the dict passed, should be ok */ PyDict_SetItem(py_kw, bpy_intern_str_attr, key); - args_fake= PyTuple_New(1); + args_fake = PyTuple_New(1); PyTuple_SET_ITEM(args_fake, 0, py_srna_cobject); - py_ret= PyObject_Call(py_func, args_fake, py_kw); + py_ret = PyObject_Call(py_func, args_fake, py_kw); Py_DECREF(args_fake); /* free's py_srna_cobject too */ @@ -6447,19 +6451,19 @@ static int pyrna_deferred_register_props(StructRNA *srna, PyObject *class_dict) { PyObject *item, *key; PyObject *order; - Py_ssize_t pos= 0; - int ret= 0; + Py_ssize_t pos = 0; + int ret = 0; /* in both cases PyDict_CheckExact(class_dict) will be true even * though Operators have a metaclass dict namespace */ - if ((order= PyDict_GetItem(class_dict, bpy_intern_str_order)) && PyList_CheckExact(order)) { - for (pos= 0; pos<PyList_GET_SIZE(order); pos++) { - key= PyList_GET_ITEM(order, pos); + if ((order = PyDict_GetItem(class_dict, bpy_intern_str_order)) && PyList_CheckExact(order)) { + for (pos = 0; pos < PyList_GET_SIZE(order); pos++) { + key = PyList_GET_ITEM(order, pos); /* however unlikely its possible * fails in py 3.3 beta with __qualname__ */ - if ((item= PyDict_GetItem(class_dict, key))) { - ret= deferred_register_prop(srna, key, item); + if ((item = PyDict_GetItem(class_dict, key))) { + ret = deferred_register_prop(srna, key, item); if (ret != 0) { break; } @@ -6468,7 +6472,7 @@ static int pyrna_deferred_register_props(StructRNA *srna, PyObject *class_dict) } else { while (PyDict_Next(class_dict, &pos, &key, &item)) { - ret= deferred_register_prop(srna, key, item); + ret = deferred_register_prop(srna, key, item); if (ret != 0) break; @@ -6480,12 +6484,12 @@ static int pyrna_deferred_register_props(StructRNA *srna, PyObject *class_dict) static int pyrna_deferred_register_class_recursive(StructRNA *srna, PyTypeObject *py_class) { - const int len= PyTuple_GET_SIZE(py_class->tp_bases); + const int len = PyTuple_GET_SIZE(py_class->tp_bases); int i, ret; /* first scan base classes for registerable properties */ - for (i=0; i<len; i++) { - PyTypeObject *py_superclass= (PyTypeObject *)PyTuple_GET_ITEM(py_class->tp_bases, i); + for (i = 0; i < len; i++) { + PyTypeObject *py_superclass = (PyTypeObject *)PyTuple_GET_ITEM(py_class->tp_bases, i); /* the rules for using these base classes are not clear, * 'object' is of course not worth looking into and @@ -6499,7 +6503,7 @@ static int pyrna_deferred_register_class_recursive(StructRNA *srna, PyTypeObject if (py_superclass != &PyBaseObject_Type && !PyObject_IsSubclass((PyObject *)py_superclass, (PyObject *)&pyrna_struct_Type) ) { - ret= pyrna_deferred_register_class_recursive(srna, py_superclass); + ret = pyrna_deferred_register_class_recursive(srna, py_superclass); if (ret != 0) { return ret; @@ -6525,13 +6529,13 @@ int pyrna_deferred_register_class(StructRNA *srna, PyObject *py_class) static int rna_function_arg_count(FunctionRNA *func) { - const ListBase *lb= RNA_function_defined_parameters(func); + const ListBase *lb = RNA_function_defined_parameters(func); PropertyRNA *parm; Link *link; - int count= (RNA_function_flag(func) & FUNC_NO_SELF) ? 0 : 1; + int count = (RNA_function_flag(func) & FUNC_NO_SELF) ? 0 : 1; - for (link=lb->first; link; link=link->next) { - parm= (PropertyRNA*)link; + for (link = lb->first; link; link = link->next) { + parm = (PropertyRNA *)link; if (!(RNA_property_flag(parm) & PROP_OUTPUT)) count++; } @@ -6545,13 +6549,13 @@ static int bpy_class_validate(PointerRNA *dummyptr, void *py_data, int *have_fun Link *link; FunctionRNA *func; PropertyRNA *prop; - StructRNA *srna= dummyptr->type; - const char *class_type= RNA_struct_identifier(srna); - PyObject *py_class= (PyObject*)py_data; - PyObject *base_class= RNA_struct_py_type_get(srna); + StructRNA *srna = dummyptr->type; + const char *class_type = RNA_struct_identifier(srna); + PyObject *py_class = (PyObject *)py_data; + PyObject *base_class = RNA_struct_py_type_get(srna); PyObject *item; int i, flag, arg_count, func_arg_count; - const char *py_class_name= ((PyTypeObject *)py_class)->tp_name; // __name__ + const char *py_class_name = ((PyTypeObject *)py_class)->tp_name; // __name__ if (base_class) { @@ -6564,22 +6568,22 @@ static int bpy_class_validate(PointerRNA *dummyptr, void *py_data, int *have_fun } /* verify callback functions */ - lb= RNA_struct_type_functions(srna); - i= 0; - for (link=lb->first; link; link=link->next) { - func= (FunctionRNA*)link; - flag= RNA_function_flag(func); + lb = RNA_struct_type_functions(srna); + i = 0; + for (link = lb->first; link; link = link->next) { + func = (FunctionRNA *)link; + flag = RNA_function_flag(func); if (!(flag & FUNC_REGISTER)) continue; - item= PyObject_GetAttrString(py_class, RNA_function_identifier(func)); + item = PyObject_GetAttrString(py_class, RNA_function_identifier(func)); - have_function[i]= (item != NULL); + have_function[i] = (item != NULL); i++; - if (item==NULL) { - if ((flag & FUNC_REGISTER_OPTIONAL)==0) { + if (item == NULL) { + if ((flag & FUNC_REGISTER_OPTIONAL) == 0) { PyErr_Format(PyExc_AttributeError, "expected %.200s, %.200s class to have an \"%.200s\" attribute", class_type, py_class_name, @@ -6592,16 +6596,16 @@ static int bpy_class_validate(PointerRNA *dummyptr, void *py_data, int *have_fun else { Py_DECREF(item); /* no need to keep a ref, the class owns it (technically we should keep a ref but...) */ if (flag & FUNC_NO_SELF) { - if (PyMethod_Check(item)==0) { + if (PyMethod_Check(item) == 0) { PyErr_Format(PyExc_TypeError, "expected %.200s, %.200s class \"%.200s\" attribute to be a method, not a %.200s", class_type, py_class_name, RNA_function_identifier(func), Py_TYPE(item)->tp_name); return -1; } - item= ((PyMethodObject *)item)->im_func; + item = ((PyMethodObject *)item)->im_func; } else { - if (PyFunction_Check(item)==0) { + if (PyFunction_Check(item) == 0) { PyErr_Format(PyExc_TypeError, "expected %.200s, %.200s class \"%.200s\" attribute to be a function, not a %.200s", class_type, py_class_name, RNA_function_identifier(func), Py_TYPE(item)->tp_name); @@ -6609,10 +6613,10 @@ static int bpy_class_validate(PointerRNA *dummyptr, void *py_data, int *have_fun } } - func_arg_count= rna_function_arg_count(func); + func_arg_count = rna_function_arg_count(func); if (func_arg_count >= 0) { /* -1 if we dont care*/ - arg_count= ((PyCodeObject *)PyFunction_GET_CODE(item))->co_argcount; + arg_count = ((PyCodeObject *)PyFunction_GET_CODE(item))->co_argcount; /* note, the number of args we check for and the number of args we give to * @classmethods are different (quirk of python), @@ -6632,24 +6636,24 @@ static int bpy_class_validate(PointerRNA *dummyptr, void *py_data, int *have_fun } /* verify properties */ - lb= RNA_struct_type_properties(srna); - for (link=lb->first; link; link=link->next) { + lb = RNA_struct_type_properties(srna); + for (link = lb->first; link; link = link->next) { const char *identifier; - prop= (PropertyRNA*)link; - flag= RNA_property_flag(prop); + prop = (PropertyRNA *)link; + flag = RNA_property_flag(prop); if (!(flag & PROP_REGISTER)) continue; - identifier= RNA_property_identifier(prop); - item= PyObject_GetAttrString(py_class, identifier); + identifier = RNA_property_identifier(prop); + item = PyObject_GetAttrString(py_class, identifier); - if (item==NULL) { + if (item == NULL) { /* Sneaky workaround to use the class name as the bl_idname */ #define BPY_REPLACEMENT_STRING(rna_attr, py_attr) \ if (strcmp(identifier, rna_attr) == 0) { \ - item= PyObject_GetAttrString(py_class, py_attr); \ + item = PyObject_GetAttrString(py_class, py_attr); \ if (item && item != Py_None) { \ if (pyrna_py_to_prop(dummyptr, prop, NULL, \ item, "validating class:") != 0) \ @@ -6691,36 +6695,36 @@ static int bpy_class_validate(PointerRNA *dummyptr, void *py_data, int *have_fun static int bpy_class_call(bContext *C, PointerRNA *ptr, FunctionRNA *func, ParameterList *parms) { PyObject *args; - PyObject *ret= NULL, *py_srna= NULL, *py_class_instance= NULL, *parmitem; + PyObject *ret = NULL, *py_srna = NULL, *py_class_instance = NULL, *parmitem; PyTypeObject *py_class; - void **py_class_instance_store= NULL; + void **py_class_instance_store = NULL; PropertyRNA *parm; ParameterIterator iter; PointerRNA funcptr; - int err= 0, i, flag, ret_len=0; - const char is_static= (RNA_function_flag(func) & FUNC_NO_SELF) != 0; + int err = 0, i, flag, ret_len = 0; + const char is_static = (RNA_function_flag(func) & FUNC_NO_SELF) != 0; /* annoying!, need to check if the screen gets set to NULL which is a * hint that the file was actually re-loaded. */ char is_valid_wm; - PropertyRNA *pret_single= NULL; - void *retdata_single= NULL; + PropertyRNA *pret_single = NULL; + void *retdata_single = NULL; PyGILState_STATE gilstate; #ifdef USE_PEDANTIC_WRITE - const int is_operator= RNA_struct_is_a(ptr->type, &RNA_Operator); - const char *func_id= RNA_function_identifier(func); + const int is_operator = RNA_struct_is_a(ptr->type, &RNA_Operator); + const char *func_id = RNA_function_identifier(func); /* testing, for correctness, not operator and not draw function */ - const short is_readonly= ((strncmp("draw", func_id, 4) ==0) || /* draw or draw_header */ + const short is_readonly = ((strncmp("draw", func_id, 4) == 0) || /* draw or draw_header */ /*strstr("render", func_id) ||*/ !is_operator); #endif - py_class= RNA_struct_py_type_get(ptr->type); + py_class = RNA_struct_py_type_get(ptr->type); /* rare case. can happen when registering subclasses */ - if (py_class==NULL) { + if (py_class == NULL) { fprintf(stderr, "%s: unable to get python class for rna struct '%.200s'\n", __func__, RNA_struct_identifier(ptr->type)); return -1; @@ -6728,10 +6732,10 @@ static int bpy_class_call(bContext *C, PointerRNA *ptr, FunctionRNA *func, Param /* XXX, this is needed because render engine calls without a context * this should be supported at some point but at the moment its not! */ - if (C==NULL) - C= BPy_GetContext(); + if (C == NULL) + C = BPy_GetContext(); - is_valid_wm= (CTX_wm_manager(C) != NULL); + is_valid_wm = (CTX_wm_manager(C) != NULL); bpy_context_set(C, &gilstate); @@ -6742,29 +6746,29 @@ static int bpy_class_call(bContext *C, PointerRNA *ptr, FunctionRNA *func, Param if (instance) { if (*instance) { - py_class_instance= *instance; + py_class_instance = *instance; Py_INCREF(py_class_instance); } else { /* store the instance here once its created */ - py_class_instance_store= instance; + py_class_instance_store = instance; } } } /* end exception */ - if (py_class_instance==NULL) - py_srna= pyrna_struct_CreatePyObject(ptr); + if (py_class_instance == NULL) + py_srna = pyrna_struct_CreatePyObject(ptr); if (py_class_instance) { /* special case, instance is cached */ } else if (py_srna == NULL) { - py_class_instance= NULL; + py_class_instance = NULL; } else if (py_srna == Py_None) { /* probably wont ever happen but possible */ Py_DECREF(py_srna); - py_class_instance= NULL; + py_class_instance = NULL; } else { #if 1 @@ -6774,106 +6778,106 @@ static int bpy_class_call(bContext *C, PointerRNA *ptr, FunctionRNA *func, Param */ if (py_class->tp_init) { #ifdef USE_PEDANTIC_WRITE - const int prev_write= rna_disallow_writes; - rna_disallow_writes= is_operator ? FALSE : TRUE; /* only operators can write on __init__ */ + const int prev_write = rna_disallow_writes; + rna_disallow_writes = is_operator ? FALSE : TRUE; /* only operators can write on __init__ */ #endif /* true in most cases even when the class its self doesn't define an __init__ function. */ - args= PyTuple_New(0); + args = PyTuple_New(0); if (py_class->tp_init(py_srna, args, NULL) < 0) { Py_DECREF(py_srna); - py_srna= NULL; + py_srna = NULL; /* err set below */ } Py_DECREF(args); #ifdef USE_PEDANTIC_WRITE - rna_disallow_writes= prev_write; + rna_disallow_writes = prev_write; #endif } - py_class_instance= py_srna; + py_class_instance = py_srna; #else - const int prev_write= rna_disallow_writes; - rna_disallow_writes= TRUE; + const int prev_write = rna_disallow_writes; + rna_disallow_writes = TRUE; /* 'almost' all the time calling the class isn't needed. * We could just do... - py_class_instance= py_srna; + py_class_instance = py_srna; Py_INCREF(py_class_instance); * This would work fine but means __init__ functions wouldnt run. * none of blenders default scripts use __init__ but its nice to call it * for general correctness. just to note why this is here when it could be safely removed. */ - args= PyTuple_New(1); + args = PyTuple_New(1); PyTuple_SET_ITEM(args, 0, py_srna); - py_class_instance= PyObject_Call(py_class, args, NULL); + py_class_instance = PyObject_Call(py_class, args, NULL); Py_DECREF(args); - rna_disallow_writes= prev_write; + rna_disallow_writes = prev_write; #endif if (py_class_instance == NULL) { - err= -1; /* so the error is not overridden below */ + err = -1; /* so the error is not overridden below */ } else if (py_class_instance_store) { - *py_class_instance_store= py_class_instance; + *py_class_instance_store = py_class_instance; Py_INCREF(py_class_instance); } } } if (err != -1 && (is_static || py_class_instance)) { /* Initializing the class worked, now run its invoke function */ - PyObject *item= PyObject_GetAttrString((PyObject *)py_class, RNA_function_identifier(func)); -// flag= RNA_function_flag(func); + PyObject *item = PyObject_GetAttrString((PyObject *)py_class, RNA_function_identifier(func)); +// flag = RNA_function_flag(func); if (item) { RNA_pointer_create(NULL, &RNA_Function, func, &funcptr); - args= PyTuple_New(rna_function_arg_count(func)); /* first arg is included in 'item' */ + args = PyTuple_New(rna_function_arg_count(func)); /* first arg is included in 'item' */ if (is_static) { - i= 0; + i = 0; } else { PyTuple_SET_ITEM(args, 0, py_class_instance); - i= 1; + i = 1; } RNA_parameter_list_begin(parms, &iter); /* parse function parameters */ for (; iter.valid; RNA_parameter_list_next(&iter)) { - parm= iter.parm; - flag= RNA_property_flag(parm); + parm = iter.parm; + flag = RNA_property_flag(parm); /* only useful for single argument returns, we'll need another list loop for multiple */ if (flag & PROP_OUTPUT) { ret_len++; - if (pret_single==NULL) { - pret_single= parm; - retdata_single= iter.data; + if (pret_single == NULL) { + pret_single = parm; + retdata_single = iter.data; } continue; } - parmitem= pyrna_param_to_py(&funcptr, parm, iter.data); + parmitem = pyrna_param_to_py(&funcptr, parm, iter.data); PyTuple_SET_ITEM(args, i, parmitem); i++; } #ifdef USE_PEDANTIC_WRITE - rna_disallow_writes= is_readonly ? TRUE:FALSE; + rna_disallow_writes = is_readonly ? TRUE:FALSE; #endif /* *** Main Caller *** */ - ret= PyObject_Call(item, args, NULL); + ret = PyObject_Call(item, args, NULL); /* *** Done Calling *** */ #ifdef USE_PEDANTIC_WRITE - rna_disallow_writes= FALSE; + rna_disallow_writes = FALSE; #endif RNA_parameter_list_end(&iter); @@ -6886,7 +6890,7 @@ static int bpy_class_call(bContext *C, PointerRNA *ptr, FunctionRNA *func, Param PyErr_Format(PyExc_TypeError, "could not find function %.200s in %.200s to execute callback", RNA_function_identifier(func), RNA_struct_identifier(ptr->type)); - err= -1; + err = -1; } } else { @@ -6895,23 +6899,23 @@ static int bpy_class_call(bContext *C, PointerRNA *ptr, FunctionRNA *func, Param PyErr_Format(PyExc_RuntimeError, "could not create instance of %.200s to call callback function %.200s", RNA_struct_identifier(ptr->type), RNA_function_identifier(func)); - err= -1; + err = -1; } } if (ret == NULL) { /* covers py_class_instance failing too */ - err= -1; + err = -1; } else { - if (ret_len==0 && ret != Py_None) { + if (ret_len == 0 && ret != Py_None) { PyErr_Format(PyExc_RuntimeError, "expected class %.200s, function %.200s to return None, not %.200s", RNA_struct_identifier(ptr->type), RNA_function_identifier(func), Py_TYPE(ret)->tp_name); - err= -1; + err = -1; } - else if (ret_len==1) { - err= pyrna_py_to_prop(&funcptr, pret_single, retdata_single, ret, ""); + else if (ret_len == 1) { + err = pyrna_py_to_prop(&funcptr, pret_single, retdata_single, ret, ""); /* when calling operator funcs only gives Function.result with * no line number since the func has finished calling on error, @@ -6926,32 +6930,32 @@ static int bpy_class_call(bContext *C, PointerRNA *ptr, FunctionRNA *func, Param } else if (ret_len > 1) { - if (PyTuple_Check(ret)==0) { + if (PyTuple_Check(ret) == 0) { PyErr_Format(PyExc_RuntimeError, "expected class %.200s, function %.200s to return a tuple of size %d, not %.200s", RNA_struct_identifier(ptr->type), RNA_function_identifier(func), ret_len, Py_TYPE(ret)->tp_name); - err= -1; + err = -1; } else if (PyTuple_GET_SIZE(ret) != ret_len) { PyErr_Format(PyExc_RuntimeError, "class %.200s, function %.200s to returned %d items, expected %d", RNA_struct_identifier(ptr->type), RNA_function_identifier(func), PyTuple_GET_SIZE(ret), ret_len); - err= -1; + err = -1; } else { RNA_parameter_list_begin(parms, &iter); /* parse function parameters */ - for (i= 0; iter.valid; RNA_parameter_list_next(&iter)) { - parm= iter.parm; - flag= RNA_property_flag(parm); + for (i = 0; iter.valid; RNA_parameter_list_next(&iter)) { + parm = iter.parm; + flag = RNA_property_flag(parm); /* only useful for single argument returns, we'll need another list loop for multiple */ if (flag & PROP_OUTPUT) { - err= pyrna_py_to_prop(&funcptr, parm, iter.data, + err = pyrna_py_to_prop(&funcptr, parm, iter.data, PyTuple_GET_ITEM(ret, i++), "calling class function:"); if (err) { @@ -6974,12 +6978,12 @@ static int bpy_class_call(bContext *C, PointerRNA *ptr, FunctionRNA *func, Param (RNA_struct_is_a(ptr->type, &RNA_Operator)) && (is_valid_wm == (CTX_wm_manager(C) != NULL))) { - wmOperator *op= ptr->data; - reports= op->reports; + wmOperator *op = ptr->data; + reports = op->reports; } else { /* wont alert users but they can view in 'info' space */ - reports= CTX_wm_reports(C); + reports = CTX_wm_reports(C); } BPy_errors_to_report(reports); @@ -6996,13 +7000,13 @@ static int bpy_class_call(bContext *C, PointerRNA *ptr, FunctionRNA *func, Param static void bpy_class_free(void *pyob_ptr) { - PyObject *self= (PyObject *)pyob_ptr; + PyObject *self = (PyObject *)pyob_ptr; PyGILState_STATE gilstate; - gilstate= PyGILState_Ensure(); + gilstate = PyGILState_Ensure(); // breaks re-registering classes - // PyDict_Clear(((PyTypeObject*)self)->tp_dict); + // PyDict_Clear(((PyTypeObject *)self)->tp_dict); // // remove the rna attribute instead. PyDict_DelItem(((PyTypeObject *)self)->tp_dict, bpy_intern_str_bl_rna); @@ -7028,14 +7032,14 @@ void pyrna_alloc_types(void) PointerRNA ptr; PropertyRNA *prop; - gilstate= PyGILState_Ensure(); + gilstate = PyGILState_Ensure(); /* avoid doing this lookup for every getattr */ RNA_blender_rna_pointer_create(&ptr); - prop= RNA_struct_find_property(&ptr, "structs"); + prop = RNA_struct_find_property(&ptr, "structs"); RNA_PROP_BEGIN(&ptr, itemptr, prop) { - PyObject *item= pyrna_struct_Subtype(&itemptr); + PyObject *item = pyrna_struct_Subtype(&itemptr); if (item == NULL) { if (PyErr_Occurred()) { PyErr_Print(); @@ -7059,12 +7063,12 @@ void pyrna_free_types(void) /* avoid doing this lookup for every getattr */ RNA_blender_rna_pointer_create(&ptr); - prop= RNA_struct_find_property(&ptr, "structs"); + prop = RNA_struct_find_property(&ptr, "structs"); RNA_PROP_BEGIN(&ptr, itemptr, prop) { - StructRNA *srna= srna_from_ptr(&itemptr); - void *py_ptr= RNA_struct_py_type_get(srna); + StructRNA *srna = srna_from_ptr(&itemptr); + void *py_ptr = RNA_struct_py_type_get(srna); if (py_ptr) { #if 0 // XXX - should be able to do this but makes python crash on exit @@ -7102,10 +7106,10 @@ PyDoc_STRVAR(pyrna_register_class_doc, " subclass of a registerable blender class.\n" "\n" ); -PyMethodDef meth_bpy_register_class= {"register_class", pyrna_register_class, METH_O, pyrna_register_class_doc}; +PyMethodDef meth_bpy_register_class = {"register_class", pyrna_register_class, METH_O, pyrna_register_class_doc}; static PyObject *pyrna_register_class(PyObject *UNUSED(self), PyObject *py_class) { - bContext *C= NULL; + bContext *C = NULL; ReportList reports; StructRegisterFunc reg; StructRNA *srna; @@ -7113,14 +7117,14 @@ static PyObject *pyrna_register_class(PyObject *UNUSED(self), PyObject *py_class const char *identifier; PyObject *py_cls_meth; - if (PyDict_GetItem(((PyTypeObject*)py_class)->tp_dict, bpy_intern_str_bl_rna)) { + if (PyDict_GetItem(((PyTypeObject *)py_class)->tp_dict, bpy_intern_str_bl_rna)) { PyErr_SetString(PyExc_AttributeError, "register_class(...): already registered as a subclass"); return NULL; } /* warning: gets parent classes srna, only for the register function */ - srna= pyrna_struct_as_srna(py_class, 1, "register_class(...):"); - if (srna==NULL) + srna = pyrna_struct_as_srna(py_class, 1, "register_class(...):"); + if (srna == NULL) return NULL; /* fails in cases, cant use this check but would like to :| */ @@ -7128,13 +7132,13 @@ static PyObject *pyrna_register_class(PyObject *UNUSED(self), PyObject *py_class if (RNA_struct_py_type_get(srna)) { PyErr_Format(PyExc_ValueError, "register_class(...): %.200s's parent class %.200s is already registered, this is not allowed", - ((PyTypeObject*)py_class)->tp_name, RNA_struct_identifier(srna)); + ((PyTypeObject *)py_class)->tp_name, RNA_struct_identifier(srna)); return NULL; } */ /* check that we have a register callback for this type */ - reg= RNA_struct_register(srna); + reg = RNA_struct_register(srna); if (!reg) { PyErr_Format(PyExc_ValueError, @@ -7145,15 +7149,15 @@ static PyObject *pyrna_register_class(PyObject *UNUSED(self), PyObject *py_class } /* get the context, so register callback can do necessary refreshes */ - C= BPy_GetContext(); + C = BPy_GetContext(); /* call the register callback with reports & identifier */ BKE_reports_init(&reports, RPT_STORE); - identifier= ((PyTypeObject*)py_class)->tp_name; + identifier = ((PyTypeObject *)py_class)->tp_name; - srna_new= reg(CTX_data_main(C), &reports, py_class, identifier, - bpy_class_validate, bpy_class_call, bpy_class_free); + srna_new = reg(CTX_data_main(C), &reports, py_class, identifier, + bpy_class_validate, bpy_class_call, bpy_class_free); if (BPy_reports_to_error(&reports, PyExc_RuntimeError, TRUE) == -1) return NULL; @@ -7173,18 +7177,18 @@ static PyObject *pyrna_register_class(PyObject *UNUSED(self), PyObject *py_class /* Can't use this because it returns a dict proxy * - * item= PyObject_GetAttrString(py_class, "__dict__"); + * item = PyObject_GetAttrString(py_class, "__dict__"); */ - if (pyrna_deferred_register_class(srna_new, py_class)!=0) + if (pyrna_deferred_register_class(srna_new, py_class) != 0) return NULL; /* call classed register method () */ - py_cls_meth= PyObject_GetAttr(py_class, bpy_intern_str_register); + py_cls_meth = PyObject_GetAttr(py_class, bpy_intern_str_register); if (py_cls_meth == NULL) { PyErr_Clear(); } else { - PyObject *ret= PyObject_CallObject(py_cls_meth, NULL); + PyObject *ret = PyObject_CallObject(py_cls_meth, NULL); if (ret) { Py_DECREF(ret); } @@ -7203,16 +7207,16 @@ static int pyrna_srna_contains_pointer_prop_srna(StructRNA *srna_props, StructRN LinkData *link; /* verify properties */ - const ListBase *lb= RNA_struct_type_properties(srna); + const ListBase *lb = RNA_struct_type_properties(srna); - for (link=lb->first; link; link=link->next) { - prop= (PropertyRNA*)link; + for (link = lb->first; link; link = link->next) { + prop = (PropertyRNA *)link; if (RNA_property_type(prop) == PROP_POINTER && !(RNA_property_flag(prop) & PROP_BUILTIN)) { PointerRNA tptr; RNA_pointer_create(NULL, &RNA_Struct, srna_props, &tptr); if (RNA_property_pointer_type(&tptr, prop) == srna) { - *prop_identifier= RNA_property_identifier(prop); + *prop_identifier = RNA_property_identifier(prop); return 1; } } @@ -7229,26 +7233,28 @@ PyDoc_STRVAR(pyrna_unregister_class_doc, " If the class has an *unregister* class method it will be called\n" " before unregistering.\n" ); -PyMethodDef meth_bpy_unregister_class= {"unregister_class", pyrna_unregister_class, METH_O, pyrna_unregister_class_doc}; +PyMethodDef meth_bpy_unregister_class = { + "unregister_class", pyrna_unregister_class, METH_O, pyrna_unregister_class_doc +}; static PyObject *pyrna_unregister_class(PyObject *UNUSED(self), PyObject *py_class) { - bContext *C= NULL; + bContext *C = NULL; StructUnregisterFunc unreg; StructRNA *srna; PyObject *py_cls_meth; - /*if (PyDict_GetItem(((PyTypeObject*)py_class)->tp_dict, bpy_intern_str_bl_rna)==NULL) { + /*if (PyDict_GetItem(((PyTypeObject *)py_class)->tp_dict, bpy_intern_str_bl_rna) == NULL) { PWM_cursor_wait(0); PyErr_SetString(PyExc_ValueError, "unregister_class(): not a registered as a subclass"); return NULL; }*/ - srna= pyrna_struct_as_srna(py_class, 0, "unregister_class(...):"); - if (srna==NULL) + srna = pyrna_struct_as_srna(py_class, 0, "unregister_class(...):"); + if (srna == NULL) return NULL; /* check that we have a unregister callback for this type */ - unreg= RNA_struct_unregister(srna); + unreg = RNA_struct_unregister(srna); if (!unreg) { PyErr_SetString(PyExc_ValueError, @@ -7258,12 +7264,12 @@ static PyObject *pyrna_unregister_class(PyObject *UNUSED(self), PyObject *py_cla } /* call classed unregister method */ - py_cls_meth= PyObject_GetAttr(py_class, bpy_intern_str_unregister); + py_cls_meth = PyObject_GetAttr(py_class, bpy_intern_str_unregister); if (py_cls_meth == NULL) { PyErr_Clear(); } else { - PyObject *ret= PyObject_CallObject(py_cls_meth, NULL); + PyObject *ret = PyObject_CallObject(py_cls_meth, NULL); if (ret) { Py_DECREF(ret); } @@ -7278,16 +7284,16 @@ static PyObject *pyrna_unregister_class(PyObject *UNUSED(self), PyObject *py_cla StructRNA *srna_iter; PointerRNA ptr_rna; PropertyRNA *prop_rna; - const char *prop_identifier= NULL; + const char *prop_identifier = NULL; RNA_blender_rna_pointer_create(&ptr_rna); - prop_rna= RNA_struct_find_property(&ptr_rna, "structs"); + prop_rna = RNA_struct_find_property(&ptr_rna, "structs"); /* loop over all structs */ RNA_PROP_BEGIN(&ptr_rna, itemptr, prop_rna) { - srna_iter= itemptr.data; + srna_iter = itemptr.data; if (pyrna_srna_contains_pointer_prop_srna(srna_iter, srna, &prop_identifier)) { break; } @@ -7303,7 +7309,7 @@ static PyObject *pyrna_unregister_class(PyObject *UNUSED(self), PyObject *py_cla } /* get the context, so register callback can do necessary refreshes */ - C= BPy_GetContext(); + C = BPy_GetContext(); /* call unregister */ unreg(CTX_data_main(C), srna); /* calls bpy_class_free, this decref's py_class */ diff --git a/source/blender/python/intern/bpy_rna_anim.c b/source/blender/python/intern/bpy_rna_anim.c index 3006e2a6b90..2371ca7dc50 100644 --- a/source/blender/python/intern/bpy_rna_anim.c +++ b/source/blender/python/intern/bpy_rna_anim.c @@ -59,11 +59,11 @@ static int pyrna_struct_anim_args_parse( PointerRNA *ptr, const char *error_prefix, const char *path, const char **path_full, int *index) { - const int is_idbase= RNA_struct_is_ID(ptr->type); + const int is_idbase = RNA_struct_is_ID(ptr->type); PropertyRNA *prop; PointerRNA r_ptr; - if (ptr->data==NULL) { + if (ptr->data == NULL) { PyErr_Format(PyExc_TypeError, "%.200s this struct has no data, can't be animated", error_prefix); @@ -72,9 +72,9 @@ static int pyrna_struct_anim_args_parse( /* full paths can only be given from ID base */ if (is_idbase) { - int r_index= -1; - if (RNA_path_resolve_full(ptr, path, &r_ptr, &prop, &r_index)==0) { - prop= NULL; + int r_index = -1; + if (RNA_path_resolve_full(ptr, path, &r_ptr, &prop, &r_index) == 0) { + prop = NULL; } else if (r_index != -1) { PyErr_Format(PyExc_ValueError, @@ -90,11 +90,11 @@ static int pyrna_struct_anim_args_parse( } } else { - prop= RNA_struct_find_property(ptr, path); - r_ptr= *ptr; + prop = RNA_struct_find_property(ptr, path); + r_ptr = *ptr; } - if (prop==NULL) { + if (prop == NULL) { PyErr_Format(PyExc_TypeError, "%.200s property \"%s\" not found", error_prefix, path); @@ -110,7 +110,7 @@ static int pyrna_struct_anim_args_parse( if (RNA_property_array_check(prop) == 0) { if ((*index) == -1) { - *index= 0; + *index = 0; } else { PyErr_Format(PyExc_TypeError, @@ -120,7 +120,7 @@ static int pyrna_struct_anim_args_parse( } } else { - int array_len= RNA_property_array_length(&r_ptr, prop); + int array_len = RNA_property_array_length(&r_ptr, prop); if ((*index) < -1 || (*index) >= array_len) { PyErr_Format(PyExc_TypeError, "%.200s index out of range \"%s\", given %d, array length is %d", @@ -130,12 +130,12 @@ static int pyrna_struct_anim_args_parse( } if (is_idbase) { - *path_full= BLI_strdup(path); + *path_full = BLI_strdup(path); } else { - *path_full= RNA_path_from_ID_to_property(&r_ptr, prop); + *path_full = RNA_path_from_ID_to_property(&r_ptr, prop); - if (*path_full==NULL) { + if (*path_full == NULL) { PyErr_Format(PyExc_TypeError, "%.200s could not make path to \"%s\"", error_prefix, path); @@ -151,7 +151,7 @@ static int pyrna_struct_keyframe_parse( PointerRNA *ptr, PyObject *args, PyObject *kw, const char *parse_str, const char *error_prefix, const char **path_full, int *index, float *cfra, const char **group_name) /* return values */ { - static const char *kwlist[]= {"data_path", "index", "frame", "group", NULL}; + static const char *kwlist[] = {"data_path", "index", "frame", "group", NULL}; const char *path; /* note, parse_str MUST start with 's|ifs' */ @@ -161,8 +161,8 @@ static int pyrna_struct_keyframe_parse( if (pyrna_struct_anim_args_parse(ptr, error_prefix, path, path_full, index) < 0) return -1; - if (*cfra==FLT_MAX) - *cfra= CTX_data_scene(BPy_GetContext())->r.cfra; + if (*cfra == FLT_MAX) + *cfra = CTX_data_scene(BPy_GetContext())->r.cfra; return 0; /* success */ } @@ -186,10 +186,10 @@ char pyrna_struct_keyframe_insert_doc[] = PyObject *pyrna_struct_keyframe_insert(BPy_StructRNA *self, PyObject *args, PyObject *kw) { /* args, pyrna_struct_keyframe_parse handles these */ - const char *path_full= NULL; - int index= -1; - float cfra= FLT_MAX; - const char *group_name= NULL; + const char *path_full = NULL; + int index = -1; + float cfra = FLT_MAX; + const char *group_name = NULL; PYRNA_STRUCT_CHECK_OBJ(self); @@ -205,7 +205,7 @@ PyObject *pyrna_struct_keyframe_insert(BPy_StructRNA *self, PyObject *args, PyOb BKE_reports_init(&reports, RPT_STORE); - result= insert_keyframe(&reports, (ID *)self->ptr.id.data, NULL, group_name, path_full, index, cfra, 0); + result = insert_keyframe(&reports, (ID *)self->ptr.id.data, NULL, group_name, path_full, index, cfra, 0); MEM_freeN((void *)path_full); if (BPy_reports_to_error(&reports, PyExc_RuntimeError, TRUE) == -1) @@ -234,10 +234,10 @@ char pyrna_struct_keyframe_delete_doc[] = PyObject *pyrna_struct_keyframe_delete(BPy_StructRNA *self, PyObject *args, PyObject *kw) { /* args, pyrna_struct_keyframe_parse handles these */ - const char *path_full= NULL; - int index= -1; - float cfra= FLT_MAX; - const char *group_name= NULL; + const char *path_full = NULL; + int index = -1; + float cfra = FLT_MAX; + const char *group_name = NULL; PYRNA_STRUCT_CHECK_OBJ(self); @@ -254,7 +254,7 @@ PyObject *pyrna_struct_keyframe_delete(BPy_StructRNA *self, PyObject *args, PyOb BKE_reports_init(&reports, RPT_STORE); - result= delete_keyframe(&reports, (ID *)self->ptr.id.data, NULL, group_name, path_full, index, cfra, 0); + result = delete_keyframe(&reports, (ID *)self->ptr.id.data, NULL, group_name, path_full, index, cfra, 0); MEM_freeN((void *)path_full); if (BPy_reports_to_error(&reports, PyExc_RuntimeError, TRUE) == -1) @@ -280,7 +280,7 @@ char pyrna_struct_driver_add_doc[] = PyObject *pyrna_struct_driver_add(BPy_StructRNA *self, PyObject *args) { const char *path, *path_full; - int index= -1; + int index = -1; PYRNA_STRUCT_CHECK_OBJ(self); @@ -291,39 +291,39 @@ PyObject *pyrna_struct_driver_add(BPy_StructRNA *self, PyObject *args) return NULL; } else { - PyObject *ret= NULL; + PyObject *ret = NULL; ReportList reports; int result; BKE_reports_init(&reports, RPT_STORE); - result= ANIM_add_driver(&reports, (ID *)self->ptr.id.data, path_full, index, 0, DRIVER_TYPE_PYTHON); + result = ANIM_add_driver(&reports, (ID *)self->ptr.id.data, path_full, index, 0, DRIVER_TYPE_PYTHON); if (BPy_reports_to_error(&reports, PyExc_RuntimeError, TRUE) == -1) return NULL; if (result) { - ID *id= self->ptr.id.data; - AnimData *adt= BKE_animdata_from_id(id); + ID *id = self->ptr.id.data; + AnimData *adt = BKE_animdata_from_id(id); FCurve *fcu; PointerRNA tptr; PyObject *item; if (index == -1) { /* all, use a list */ - int i= 0; - ret= PyList_New(0); - while ((fcu= list_find_fcurve(&adt->drivers, path_full, i++))) { + int i = 0; + ret = PyList_New(0); + while ((fcu = list_find_fcurve(&adt->drivers, path_full, i++))) { RNA_pointer_create(id, &RNA_FCurve, fcu, &tptr); - item= pyrna_struct_CreatePyObject(&tptr); + item = pyrna_struct_CreatePyObject(&tptr); PyList_Append(ret, item); Py_DECREF(item); } } else { - fcu= list_find_fcurve(&adt->drivers, path_full, index); + fcu = list_find_fcurve(&adt->drivers, path_full, index); RNA_pointer_create(id, &RNA_FCurve, fcu, &tptr); - ret= pyrna_struct_CreatePyObject(&tptr); + ret = pyrna_struct_CreatePyObject(&tptr); } WM_event_add_notifier(BPy_GetContext(), NC_ANIMATION|ND_FCURVES_ORDER, NULL); @@ -356,7 +356,7 @@ char pyrna_struct_driver_remove_doc[] = PyObject *pyrna_struct_driver_remove(BPy_StructRNA *self, PyObject *args) { const char *path, *path_full; - int index= -1; + int index = -1; PYRNA_STRUCT_CHECK_OBJ(self); @@ -372,7 +372,7 @@ PyObject *pyrna_struct_driver_remove(BPy_StructRNA *self, PyObject *args) BKE_reports_init(&reports, RPT_STORE); - result= ANIM_remove_driver(&reports, (ID *)self->ptr.id.data, path_full, index, 0); + result = ANIM_remove_driver(&reports, (ID *)self->ptr.id.data, path_full, index, 0); MEM_freeN((void *)path_full); diff --git a/source/blender/python/intern/bpy_rna_array.c b/source/blender/python/intern/bpy_rna_array.c index 2a4c004d84c..a74d0417ca2 100644 --- a/source/blender/python/intern/bpy_rna_array.c +++ b/source/blender/python/intern/bpy_rna_array.c @@ -55,14 +55,14 @@ typedef void (*RNA_SetIndexFunc)(PointerRNA *, PropertyRNA *, int index, void *) */ /* - arr[2]= x + arr[2] = x py_to_array_index(arraydim=0, arrayoffset=0, index=2) validate_array(lvalue_dim=0) ... make real index ... */ -/* arr[3]=x, self->arraydim is 0, lvalue_dim is 1 */ +/* arr[3] = x, self->arraydim is 0, lvalue_dim is 1 */ /* Ensures that a python sequence has expected number of items/sub-items and items are of desired type. */ static int validate_array_type(PyObject *seq, int dim, int totdim, int dimsize[], ItemTypeCheckFunc check_item_type, const char *item_type_str, const char *error_prefix) @@ -72,59 +72,62 @@ static int validate_array_type(PyObject *seq, int dim, int totdim, int dimsize[] /* not the last dimension */ if (dim + 1 < totdim) { /* check that a sequence contains dimsize[dim] items */ - const Py_ssize_t seq_size= PySequence_Size(seq); + const Py_ssize_t seq_size = PySequence_Size(seq); if (seq_size == -1) { PyErr_Format(PyExc_ValueError, "%s sequence expected at dimension %d, not '%s'", error_prefix, (int)dim + 1, Py_TYPE(seq)->tp_name); return -1; } - for (i= 0; i < seq_size; i++) { + for (i = 0; i < seq_size; i++) { PyObject *item; - int ok= 1; - item= PySequence_GetItem(seq, i); + int ok = 1; + item = PySequence_GetItem(seq, i); if (item == NULL) { PyErr_Format(PyExc_TypeError, "%s sequence type '%s' failed to retrieve index %d", error_prefix, Py_TYPE(seq)->tp_name, i); - ok= 0; + ok = 0; } else if (!PySequence_Check(item)) { /* BLI_snprintf(error_str, error_str_size, "expected a sequence of %s", item_type_str); */ PyErr_Format(PyExc_TypeError, "%s expected a sequence of %s, not %s", error_prefix, item_type_str, Py_TYPE(item)->tp_name); - ok= 0; + ok = 0; } /* arr[3][4][5] - dimsize[1]=4 - dimsize[2]=5 - - dim=0 */ + * dimsize[1] = 4 + * dimsize[2] = 5 + * + * dim = 0 */ else if (PySequence_Size(item) != dimsize[dim + 1]) { - /* BLI_snprintf(error_str, error_str_size, "sequences of dimension %d should contain %d items", (int)dim + 1, (int)dimsize[dim + 1]); */ + /* BLI_snprintf(error_str, error_str_size, + "sequences of dimension %d should contain %d items", + (int)dim + 1, (int)dimsize[dim + 1]); */ PyErr_Format(PyExc_ValueError, "%s sequences of dimension %d should contain %d items", error_prefix, (int)dim + 1, (int)dimsize[dim + 1]); - ok= 0; + ok = 0; } else if (validate_array_type(item, dim + 1, totdim, dimsize, check_item_type, item_type_str, error_prefix) == -1) { - ok= 0; + ok = 0; } Py_XDECREF(item); - if (!ok) + if (!ok) { return -1; + } } } else { /* check that items are of correct type */ - const int seq_size= PySequence_Size(seq); + const int seq_size = PySequence_Size(seq); if (seq_size == -1) { PyErr_Format(PyExc_ValueError, "%s sequence expected at dimension %d, not '%s'", error_prefix, (int)dim + 1, Py_TYPE(seq)->tp_name); return -1; } - for (i= 0; i < seq_size; i++) { - PyObject *item= PySequence_GetItem(seq, i); + for (i = 0; i < seq_size; i++) { + PyObject *item = PySequence_GetItem(seq, i); if (item == NULL) { PyErr_Format(PyExc_TypeError, "%s sequence type '%s' failed to retrieve index %d", @@ -150,32 +153,32 @@ static int validate_array_type(PyObject *seq, int dim, int totdim, int dimsize[] /* Returns the number of items in a single- or multi-dimensional sequence. */ static int count_items(PyObject *seq, int dim) { - int totitem= 0; + int totitem = 0; if (dim > 1) { - const Py_ssize_t seq_size= PySequence_Size(seq); + const Py_ssize_t seq_size = PySequence_Size(seq); Py_ssize_t i; - for (i= 0; i < seq_size; i++) { - PyObject *item= PySequence_GetItem(seq, i); + for (i = 0; i < seq_size; i++) { + PyObject *item = PySequence_GetItem(seq, i); if (item) { - const int tot= count_items(item, dim - 1); + const int tot = count_items(item, dim - 1); Py_DECREF(item); if (tot != -1) { totitem += tot; } else { - totitem= -1; + totitem = -1; break; } } else { - totitem= -1; + totitem = -1; break; } } } else { - totitem= PySequence_Size(seq); + totitem = PySequence_Size(seq); } return totitem; @@ -188,8 +191,8 @@ static int validate_array_length(PyObject *rvalue, PointerRNA *ptr, PropertyRNA int dimsize[MAX_ARRAY_DIMENSION]; int tot, totdim, len; - totdim= RNA_property_array_dimension(ptr, prop, dimsize); - tot= count_items(rvalue, totdim - lvalue_dim); + totdim = RNA_property_array_dimension(ptr, prop, dimsize); + tot = count_items(rvalue, totdim - lvalue_dim); if (tot == -1) { PyErr_Format(PyExc_ValueError, "%s %.200s.%.200s, error validating the sequence length", @@ -201,45 +204,47 @@ static int validate_array_length(PyObject *rvalue, PointerRNA *ptr, PropertyRNA #if 0 /* length is flexible */ if (!RNA_property_dynamic_array_set_length(ptr, prop, tot)) { - /* BLI_snprintf(error_str, error_str_size, "%s.%s: array length cannot be changed to %d", RNA_struct_identifier(ptr->type), RNA_property_identifier(prop), tot); */ + /* BLI_snprintf(error_str, error_str_size, + "%s.%s: array length cannot be changed to %d", + RNA_struct_identifier(ptr->type), RNA_property_identifier(prop), tot); */ PyErr_Format(PyExc_ValueError, "%s %s.%s: array length cannot be changed to %d", error_prefix, RNA_struct_identifier(ptr->type), RNA_property_identifier(prop), tot); return -1; } #else - *totitem= tot; + *totitem = tot; return 0; #endif } - len= tot; + len = tot; } else { /* length is a constraint */ if (!lvalue_dim) { - len= RNA_property_array_length(ptr, prop); + len = RNA_property_array_length(ptr, prop); } /* array item assignment */ else { int i; - len= 1; + len = 1; /* arr[3][4][5] - arr[2]= x - dimsize={4, 5} - dimsize[1]= 4 - dimsize[2]= 5 - lvalue_dim=0, totdim=3 + arr[2] = x + dimsize = {4, 5} + dimsize[1] = 4 + dimsize[2] = 5 + lvalue_dim = 0, totdim = 3 - arr[2][3]= x - lvalue_dim=1 + arr[2][3] = x + lvalue_dim = 1 - arr[2][3][4]= x - lvalue_dim=2 */ - for (i= lvalue_dim; i < totdim; i++) + arr[2][3][4] = x + lvalue_dim = 2 */ + for (i = lvalue_dim; i < totdim; i++) len *= dimsize[i]; } @@ -251,7 +256,7 @@ static int validate_array_length(PyObject *rvalue, PointerRNA *ptr, PropertyRNA } } - *totitem= len; + *totitem = len; return 0; } @@ -261,7 +266,7 @@ static int validate_array(PyObject *rvalue, PointerRNA *ptr, PropertyRNA *prop, const char *error_prefix) { int dimsize[MAX_ARRAY_DIMENSION]; - int totdim= RNA_property_array_dimension(ptr, prop, dimsize); + int totdim = RNA_property_array_dimension(ptr, prop, dimsize); /* validate type first because length validation may modify property array length */ @@ -269,7 +274,7 @@ static int validate_array(PyObject *rvalue, PointerRNA *ptr, PropertyRNA *prop, #ifdef USE_MATHUTILS if (lvalue_dim == 0) { /* only valid for first level array */ if (MatrixObject_Check(rvalue)) { - MatrixObject *pymat= (MatrixObject *)rvalue; + MatrixObject *pymat = (MatrixObject *)rvalue; if (BaseMath_ReadCallback(pymat) == -1) return -1; @@ -292,7 +297,7 @@ static int validate_array(PyObject *rvalue, PointerRNA *ptr, PropertyRNA *prop, return -1; } else { - *totitem= dimsize[0] * dimsize[1]; + *totitem = dimsize[0] * dimsize[1]; return 0; } } @@ -317,7 +322,7 @@ static char *copy_value_single(PyObject *item, PointerRNA *ptr, PropertyRNA *pro convert_item(item, value); rna_set_index(ptr, prop, *index, value); - *index= *index + 1; + *index = *index + 1; } else { convert_item(item, data); @@ -331,8 +336,8 @@ static char *copy_values(PyObject *seq, PointerRNA *ptr, PropertyRNA *prop, int dim, char *data, unsigned int item_size, int *index, ItemConvertFunc convert_item, RNA_SetIndexFunc rna_set_index) { - int totdim= RNA_property_array_dimension(ptr, prop, NULL); - const Py_ssize_t seq_size= PySequence_Size(seq); + int totdim = RNA_property_array_dimension(ptr, prop, NULL); + const Py_ssize_t seq_size = PySequence_Size(seq); Py_ssize_t i; /* Regarding PySequence_GetItem() failing. @@ -352,8 +357,8 @@ static char *copy_values(PyObject *seq, PointerRNA *ptr, PropertyRNA *prop, #ifdef USE_MATHUTILS if (dim == 0) { if (MatrixObject_Check(seq)) { - MatrixObject *pymat= (MatrixObject *)seq; - size_t allocsize= pymat->num_col * pymat->num_row * sizeof(float); + MatrixObject *pymat = (MatrixObject *)seq; + size_t allocsize = pymat->num_col * pymat->num_row * sizeof(float); /* read callback already done by validate */ /* since this is the first iteration we can assume data is allocated */ @@ -368,14 +373,14 @@ static char *copy_values(PyObject *seq, PointerRNA *ptr, PropertyRNA *prop, #endif /* USE_MATHUTILS */ - for (i= 0; i < seq_size; i++) { - PyObject *item= PySequence_GetItem(seq, i); + for (i = 0; i < seq_size; i++) { + PyObject *item = PySequence_GetItem(seq, i); if (item) { if (dim + 1 < totdim) { - data= copy_values(item, ptr, prop, dim + 1, data, item_size, index, convert_item, rna_set_index); + data = copy_values(item, ptr, prop, dim + 1, data, item_size, index, convert_item, rna_set_index); } else { - data= copy_value_single(item, ptr, prop, data, item_size, index, convert_item, rna_set_index); + data = copy_value_single(item, ptr, prop, data, item_size, index, convert_item, rna_set_index); } Py_DECREF(item); @@ -396,9 +401,9 @@ static int py_to_array(PyObject *seq, PointerRNA *ptr, PropertyRNA *prop, { /*int totdim, dim_size[MAX_ARRAY_DIMENSION];*/ int totitem; - char *data= NULL; + char *data = NULL; - /*totdim= RNA_property_array_dimension(ptr, prop, dim_size);*/ /*UNUSED*/ + /*totdim = RNA_property_array_dimension(ptr, prop, dim_size);*/ /*UNUSED*/ if (validate_array(seq, ptr, prop, 0, check_item_type, item_type_str, &totitem, error_prefix) == -1) { return -1; @@ -408,30 +413,30 @@ static int py_to_array(PyObject *seq, PointerRNA *ptr, PropertyRNA *prop, /* note: this code is confusing */ if (param_data && RNA_property_flag(prop) & PROP_DYNAMIC) { /* not freeing allocated mem, RNA_parameter_list_free() will do this */ - ParameterDynAlloc *param_alloc= (ParameterDynAlloc *)param_data; - param_alloc->array_tot= (int)totitem; - param_alloc->array= MEM_callocN(item_size * totitem, "py_to_array dyn"); /* freeing param list will free */ + ParameterDynAlloc *param_alloc = (ParameterDynAlloc *)param_data; + param_alloc->array_tot = (int)totitem; + param_alloc->array = MEM_callocN(item_size * totitem, "py_to_array dyn"); /* freeing param list will free */ - data= param_alloc->array; + data = param_alloc->array; } else if (param_data) { - data= param_data; + data = param_data; } else { - data= PyMem_MALLOC(item_size * totitem); + data = PyMem_MALLOC(item_size * totitem); } /* will only fail in very rare cases since we already validated the * python data, the check here is mainly for completeness. */ if (copy_values(seq, ptr, prop, 0, data, item_size, NULL, convert_item, NULL) != NULL) { - if (param_data==NULL) { + if (param_data == NULL) { /* NULL can only pass through in case RNA property arraylength is 0 (impossible?) */ rna_set_array(ptr, prop, data); PyMem_FREE(data); } } else { - if (param_data==NULL) { + if (param_data == NULL) { PyMem_FREE(data); } @@ -452,21 +457,21 @@ static int py_to_array_index(PyObject *py, PointerRNA *ptr, PropertyRNA *prop, int totdim, dimsize[MAX_ARRAY_DIMENSION]; int totitem, i; - totdim= RNA_property_array_dimension(ptr, prop, dimsize); + totdim = RNA_property_array_dimension(ptr, prop, dimsize); /* convert index */ /* arr[3][4][5] - arr[2]= x - lvalue_dim=0, index= 0 + 2 * 4 * 5 + arr[2] = x + lvalue_dim = 0, index = 0 + 2 * 4 * 5 - arr[2][3]= x - lvalue_dim=1, index= 40 + 3 * 5 */ + arr[2][3] = x + lvalue_dim = 1, index = 40 + 3 * 5 */ lvalue_dim++; - for (i= lvalue_dim; i < totdim; i++) + for (i = lvalue_dim; i < totdim; i++) index *= dimsize[i]; index += arrayoffset; @@ -495,17 +500,17 @@ static int py_to_array_index(PyObject *py, PointerRNA *ptr, PropertyRNA *prop, static void py_to_float(PyObject *py, char *data) { - *(float*)data= (float)PyFloat_AsDouble(py); + *(float *)data = (float)PyFloat_AsDouble(py); } static void py_to_int(PyObject *py, char *data) { - *(int*)data= (int)PyLong_AsSsize_t(py); + *(int *)data = (int)PyLong_AsSsize_t(py); } static void py_to_bool(PyObject *py, char *data) { - *(int*)data= (int)PyObject_IsTrue(py); + *(int *)data = (int)PyObject_IsTrue(py); } static int py_float_check(PyObject *py) @@ -527,17 +532,17 @@ static int py_bool_check(PyObject *py) static void float_set_index(PointerRNA *ptr, PropertyRNA *prop, int index, void *value) { - RNA_property_float_set_index(ptr, prop, index, *(float*)value); + RNA_property_float_set_index(ptr, prop, index, *(float *)value); } static void int_set_index(PointerRNA *ptr, PropertyRNA *prop, int index, void *value) { - RNA_property_int_set_index(ptr, prop, index, *(int*)value); + RNA_property_int_set_index(ptr, prop, index, *(int *)value); } static void bool_set_index(PointerRNA *ptr, PropertyRNA *prop, int index, void *value) { - RNA_property_boolean_set_index(ptr, prop, index, *(int*)value); + RNA_property_boolean_set_index(ptr, prop, index, *(int *)value); } int pyrna_py_to_array(PointerRNA *ptr, PropertyRNA *prop, char *param_data, @@ -546,20 +551,20 @@ int pyrna_py_to_array(PointerRNA *ptr, PropertyRNA *prop, char *param_data, int ret; switch (RNA_property_type(prop)) { case PROP_FLOAT: - ret= py_to_array(py, ptr, prop, param_data, py_float_check, "float", sizeof(float), + ret = py_to_array(py, ptr, prop, param_data, py_float_check, "float", sizeof(float), py_to_float, (RNA_SetArrayFunc)RNA_property_float_set_array, error_prefix); break; case PROP_INT: - ret= py_to_array(py, ptr, prop, param_data, py_int_check, "int", sizeof(int), + ret = py_to_array(py, ptr, prop, param_data, py_int_check, "int", sizeof(int), py_to_int, (RNA_SetArrayFunc)RNA_property_int_set_array, error_prefix); break; case PROP_BOOLEAN: - ret= py_to_array(py, ptr, prop, param_data, py_bool_check, "boolean", sizeof(int), + ret = py_to_array(py, ptr, prop, param_data, py_bool_check, "boolean", sizeof(int), py_to_bool, (RNA_SetArrayFunc)RNA_property_boolean_set_array, error_prefix); break; default: PyErr_SetString(PyExc_TypeError, "not an array type"); - ret= -1; + ret = -1; } return ret; @@ -571,20 +576,20 @@ int pyrna_py_to_array_index(PointerRNA *ptr, PropertyRNA *prop, int arraydim, in int ret; switch (RNA_property_type(prop)) { case PROP_FLOAT: - ret= py_to_array_index(py, ptr, prop, arraydim, arrayoffset, index, + ret = py_to_array_index(py, ptr, prop, arraydim, arrayoffset, index, py_float_check, "float", py_to_float, float_set_index, error_prefix); break; case PROP_INT: - ret= py_to_array_index(py, ptr, prop, arraydim, arrayoffset, index, + ret = py_to_array_index(py, ptr, prop, arraydim, arrayoffset, index, py_int_check, "int", py_to_int, int_set_index, error_prefix); break; case PROP_BOOLEAN: - ret= py_to_array_index(py, ptr, prop, arraydim, arrayoffset, index, + ret = py_to_array_index(py, ptr, prop, arraydim, arrayoffset, index, py_bool_check, "boolean", py_to_bool, bool_set_index, error_prefix); break; default: PyErr_SetString(PyExc_TypeError, "not an array type"); - ret= -1; + ret = -1; } return ret; @@ -596,17 +601,17 @@ PyObject *pyrna_array_index(PointerRNA *ptr, PropertyRNA *prop, int index) switch (RNA_property_type(prop)) { case PROP_FLOAT: - item= PyFloat_FromDouble(RNA_property_float_get_index(ptr, prop, index)); + item = PyFloat_FromDouble(RNA_property_float_get_index(ptr, prop, index)); break; case PROP_BOOLEAN: - item= PyBool_FromLong(RNA_property_boolean_get_index(ptr, prop, index)); + item = PyBool_FromLong(RNA_property_boolean_get_index(ptr, prop, index)); break; case PROP_INT: - item= PyLong_FromSsize_t(RNA_property_int_get_index(ptr, prop, index)); + item = PyLong_FromSsize_t(RNA_property_int_get_index(ptr, prop, index)); break; default: PyErr_SetString(PyExc_TypeError, "not an array type"); - item= NULL; + item = NULL; } return item; @@ -619,20 +624,20 @@ static PyObject *pyrna_py_from_array_internal(PointerRNA *ptr, PropertyRNA *prop { PyObject *tuple; int i, len; - int totdim= RNA_property_array_dimension(ptr, prop, NULL); + int totdim = RNA_property_array_dimension(ptr, prop, NULL); - len= RNA_property_multi_array_length(ptr, prop, dim); + len = RNA_property_multi_array_length(ptr, prop, dim); - tuple= PyTuple_New(len); + tuple = PyTuple_New(len); - for (i= 0; i < len; i++) { + for (i = 0; i < len; i++) { PyObject *item; if (dim + 1 < totdim) - item= pyrna_py_from_array_internal(ptr, prop, dim + 1, index); + item = pyrna_py_from_array_internal(ptr, prop, dim + 1, index); else { - item= pyrna_array_index(ptr, prop, *index); - *index= *index + 1; + item = pyrna_array_index(ptr, prop, *index); + *index = *index + 1; } if (!item) { @@ -650,13 +655,13 @@ static PyObject *pyrna_py_from_array_internal(PointerRNA *ptr, PropertyRNA *prop PyObject *pyrna_py_from_array_index(BPy_PropertyArrayRNA *self, PointerRNA *ptr, PropertyRNA *prop, int index) { int totdim, arraydim, arrayoffset, dimsize[MAX_ARRAY_DIMENSION], i, len; - BPy_PropertyArrayRNA *ret= NULL; + BPy_PropertyArrayRNA *ret = NULL; - arraydim= self ? self->arraydim : 0; - arrayoffset= self ? self->arrayoffset : 0; + arraydim = self ? self->arraydim : 0; + arrayoffset = self ? self->arrayoffset : 0; /* just in case check */ - len= RNA_property_multi_array_length(ptr, prop, arraydim); + len = RNA_property_multi_array_length(ptr, prop, arraydim); if (index >= len || index < 0) { /* this shouldn't happen because higher level funcs must check for invalid index */ if (G.f & G_DEBUG) printf("pyrna_py_from_array_index: invalid index %d for array with length=%d\n", index, len); @@ -665,38 +670,38 @@ PyObject *pyrna_py_from_array_index(BPy_PropertyArrayRNA *self, PointerRNA *ptr, return NULL; } - totdim= RNA_property_array_dimension(ptr, prop, dimsize); + totdim = RNA_property_array_dimension(ptr, prop, dimsize); if (arraydim + 1 < totdim) { - ret= (BPy_PropertyArrayRNA*)pyrna_prop_CreatePyObject(ptr, prop); - ret->arraydim= arraydim + 1; + ret = (BPy_PropertyArrayRNA *)pyrna_prop_CreatePyObject(ptr, prop); + ret->arraydim = arraydim + 1; /* arr[3][4][5] - x= arr[2] - index= 0 + 2 * 4 * 5 + x = arr[2] + index = 0 + 2 * 4 * 5 - x= arr[2][3] - index= offset + 3 * 5 */ + x = arr[2][3] + index = offset + 3 * 5 */ - for (i= arraydim + 1; i < totdim; i++) + for (i = arraydim + 1; i < totdim; i++) index *= dimsize[i]; - ret->arrayoffset= arrayoffset + index; + ret->arrayoffset = arrayoffset + index; } else { - index= arrayoffset + index; - ret= (BPy_PropertyArrayRNA *)pyrna_array_index(ptr, prop, index); + index = arrayoffset + index; + ret = (BPy_PropertyArrayRNA *)pyrna_array_index(ptr, prop, index); } - return (PyObject*)ret; + return (PyObject *)ret; } PyObject *pyrna_py_from_array(PointerRNA *ptr, PropertyRNA *prop) { PyObject *ret; - ret= pyrna_math_object_from_array(ptr, prop); + ret = pyrna_math_object_from_array(ptr, prop); /* is this a maths object? */ if (ret) return ret; @@ -707,11 +712,11 @@ PyObject *pyrna_py_from_array(PointerRNA *ptr, PropertyRNA *prop) /* TODO, multi-dimensional arrays */ int pyrna_array_contains_py(PointerRNA *ptr, PropertyRNA *prop, PyObject *value) { - int len= RNA_property_array_length(ptr, prop); + int len = RNA_property_array_length(ptr, prop); int type; int i; - if (len==0) /* possible with dynamic arrays */ + if (len == 0) /* possible with dynamic arrays */ return 0; if (RNA_property_array_dimension(ptr, prop, NULL) > 1) { @@ -719,13 +724,13 @@ int pyrna_array_contains_py(PointerRNA *ptr, PropertyRNA *prop, PyObject *value) return -1; } - type= RNA_property_type(prop); + type = RNA_property_type(prop); switch (type) { case PROP_FLOAT: { - float value_f= PyFloat_AsDouble(value); - if (value_f==-1 && PyErr_Occurred()) { + float value_f = PyFloat_AsDouble(value); + if (value_f == -1 && PyErr_Occurred()) { PyErr_Clear(); return 0; } @@ -734,15 +739,15 @@ int pyrna_array_contains_py(PointerRNA *ptr, PropertyRNA *prop, PyObject *value) float *tmp_arr; if (len * sizeof(float) > sizeof(tmp)) { - tmp_arr= PyMem_MALLOC(len * sizeof(float)); + tmp_arr = PyMem_MALLOC(len * sizeof(float)); } else { - tmp_arr= tmp; + tmp_arr = tmp; } RNA_property_float_get_array(ptr, prop, tmp_arr); - for (i=0; i<len; i++) { + for (i = 0; i < len; i++) { if (tmp_arr[i] == value_f) { break; } @@ -751,15 +756,15 @@ int pyrna_array_contains_py(PointerRNA *ptr, PropertyRNA *prop, PyObject *value) if (tmp_arr != tmp) PyMem_FREE(tmp_arr); - return i<len ? 1 : 0; + return i < len ? 1 : 0; } break; } case PROP_BOOLEAN: case PROP_INT: { - int value_i= PyLong_AsSsize_t(value); - if (value_i==-1 && PyErr_Occurred()) { + int value_i = PyLong_AsSsize_t(value); + if (value_i == -1 && PyErr_Occurred()) { PyErr_Clear(); return 0; } @@ -768,18 +773,18 @@ int pyrna_array_contains_py(PointerRNA *ptr, PropertyRNA *prop, PyObject *value) int *tmp_arr; if (len * sizeof(int) > sizeof(tmp)) { - tmp_arr= PyMem_MALLOC(len * sizeof(int)); + tmp_arr = PyMem_MALLOC(len * sizeof(int)); } else { - tmp_arr= tmp; + tmp_arr = tmp; } - if (type==PROP_BOOLEAN) + if (type == PROP_BOOLEAN) RNA_property_boolean_get_array(ptr, prop, tmp_arr); else RNA_property_int_get_array(ptr, prop, tmp_arr); - for (i=0; i<len; i++) { + for (i = 0; i < len; i++) { if (tmp_arr[i] == value_i) { break; } @@ -788,7 +793,7 @@ int pyrna_array_contains_py(PointerRNA *ptr, PropertyRNA *prop, PyObject *value) if (tmp_arr != tmp) PyMem_FREE(tmp_arr); - return i<len ? 1 : 0; + return i < len ? 1 : 0; } break; } diff --git a/source/blender/python/intern/bpy_rna_callback.c b/source/blender/python/intern/bpy_rna_callback.c index 134cbfda71f..7704ab2a417 100644 --- a/source/blender/python/intern/bpy_rna_callback.c +++ b/source/blender/python/intern/bpy_rna_callback.c @@ -56,9 +56,9 @@ static void cb_region_draw(const bContext *C, ARegion *UNUSED(ar), void *customd bpy_context_set((bContext *)C, &gilstate); - cb_func= PyTuple_GET_ITEM((PyObject *)customdata, 0); - cb_args= PyTuple_GET_ITEM((PyObject *)customdata, 1); - result= PyObject_CallObject(cb_func, cb_args); + cb_func = PyTuple_GET_ITEM((PyObject *)customdata, 0); + cb_args = PyTuple_GET_ITEM((PyObject *)customdata, 1); + result = PyObject_CallObject(cb_func, cb_args); if (result) { Py_DECREF(result); @@ -76,7 +76,7 @@ PyObject *pyrna_callback_add(BPy_StructRNA *self, PyObject *args) void *handle; PyObject *cb_func, *cb_args; - char *cb_event_str= NULL; + char *cb_event_str = NULL; int cb_event; if (!PyArg_ParseTuple(args, "OO!|s:bpy_struct.callback_add", &cb_func, &PyTuple_Type, &cb_args, &cb_event_str)) @@ -89,7 +89,7 @@ PyObject *pyrna_callback_add(BPy_StructRNA *self, PyObject *args) if (RNA_struct_is_a(self->ptr.type, &RNA_Region)) { if (cb_event_str) { - static EnumPropertyItem region_draw_mode_items[]= { + static EnumPropertyItem region_draw_mode_items[] = { {REGION_DRAW_POST_PIXEL, "POST_PIXEL", 0, "Post Pixel", ""}, {REGION_DRAW_POST_VIEW, "POST_VIEW", 0, "Post View", ""}, {REGION_DRAW_PRE_VIEW, "PRE_VIEW", 0, "Pre View", ""}, @@ -100,10 +100,10 @@ PyObject *pyrna_callback_add(BPy_StructRNA *self, PyObject *args) } } else { - cb_event= REGION_DRAW_POST_PIXEL; + cb_event = REGION_DRAW_POST_PIXEL; } - handle= ED_region_draw_cb_activate(((ARegion *)self->ptr.data)->type, cb_region_draw, (void *)args, cb_event); + handle = ED_region_draw_cb_activate(((ARegion *)self->ptr.data)->type, cb_region_draw, (void *)args, cb_event); Py_INCREF(args); } else { @@ -123,15 +123,15 @@ PyObject *pyrna_callback_remove(BPy_StructRNA *self, PyObject *args) if (!PyArg_ParseTuple(args, "O!:callback_remove", &PyCapsule_Type, &py_handle)) return NULL; - handle= PyCapsule_GetPointer(py_handle, RNA_CAPSULE_ID); + handle = PyCapsule_GetPointer(py_handle, RNA_CAPSULE_ID); - if (handle==NULL) { + if (handle == NULL) { PyErr_SetString(PyExc_ValueError, "callback_remove(handle): NULL handle given, invalid or already removed"); return NULL; } if (RNA_struct_is_a(self->ptr.type, &RNA_Region)) { - customdata= ED_region_draw_cb_customdata(handle); + customdata = ED_region_draw_cb_customdata(handle); Py_DECREF((PyObject *)customdata); ED_region_draw_cb_exit(((ARegion *)self->ptr.data)->type, handle); diff --git a/source/blender/python/intern/bpy_traceback.c b/source/blender/python/intern/bpy_traceback.c index 599c4312985..e3272c9da1a 100644 --- a/source/blender/python/intern/bpy_traceback.c +++ b/source/blender/python/intern/bpy_traceback.c @@ -33,7 +33,7 @@ static const char *traceback_filepath(PyTracebackObject *tb, PyObject **coerce) { - return PyBytes_AS_STRING((*coerce= PyUnicode_EncodeFSDefault(tb->tb_frame->f_code->co_filename))); + return PyBytes_AS_STRING((*coerce = PyUnicode_EncodeFSDefault(tb->tb_frame->f_code->co_filename))); } /* copied from pythonrun.c, 3.2.0 */ @@ -110,8 +110,8 @@ void python_script_error_jump(const char *filepath, int *lineno, int *offset) PyObject *exception, *value; PyTracebackObject *tb; - *lineno= -1; - *offset= 0; + *lineno = -1; + *offset = 0; PyErr_Fetch(&exception, &value, (PyObject **)&tb); @@ -133,11 +133,11 @@ void python_script_error_jump(const char *filepath, int *lineno, int *offset) /* good */ } else { - *lineno= -1; + *lineno = -1; } } else { - *lineno= -1; + *lineno = -1; } } } @@ -146,17 +146,17 @@ void python_script_error_jump(const char *filepath, int *lineno, int *offset) PyErr_Restore(exception, value, (PyObject *)tb); /* takes away reference! */ PyErr_Print(); - for (tb= (PyTracebackObject *)PySys_GetObject("last_traceback"); + for (tb = (PyTracebackObject *)PySys_GetObject("last_traceback"); tb && (PyObject *)tb != Py_None; - tb= tb->tb_next) + tb = tb->tb_next) { PyObject *coerce; - const char *tb_filepath= traceback_filepath(tb, &coerce); - const int match= strcmp(tb_filepath, filepath) != 0; + const char *tb_filepath = traceback_filepath(tb, &coerce); + const int match = strcmp(tb_filepath, filepath) != 0; Py_DECREF(coerce); if (match) { - *lineno= tb->tb_lineno; + *lineno = tb->tb_lineno; break; } } diff --git a/source/blender/python/intern/bpy_util.c b/source/blender/python/intern/bpy_util.c index fb42f7d59e0..ec7eff1756a 100644 --- a/source/blender/python/intern/bpy_util.c +++ b/source/blender/python/intern/bpy_util.c @@ -37,22 +37,22 @@ #include "../generic/py_capi_utils.h" -static bContext* __py_context= NULL; +static bContext* __py_context = NULL; bContext* BPy_GetContext(void) { return __py_context; } -void BPy_SetContext(bContext *C) { __py_context= C; } +void BPy_SetContext(bContext *C) { __py_context = C; } char *BPy_enum_as_string(EnumPropertyItem *item) { - DynStr *dynstr= BLI_dynstr_new(); + DynStr *dynstr = BLI_dynstr_new(); EnumPropertyItem *e; char *cstring; - for (e= item; item->identifier; item++) { + for (e = item; item->identifier; item++) { if (item->identifier[0]) - BLI_dynstr_appendf(dynstr, (e==item)?"'%s'":", '%s'", item->identifier); + BLI_dynstr_appendf(dynstr, (e == item)?"'%s'":", '%s'", item->identifier); } - cstring= BLI_dynstr_get_cstring(dynstr); + cstring = BLI_dynstr_get_cstring(dynstr); BLI_dynstr_free(dynstr); return cstring; } @@ -61,7 +61,7 @@ short BPy_reports_to_error(ReportList *reports, PyObject *exception, const short { char *report_str; - report_str= BKE_reports_string(reports, RPT_ERROR); + report_str = BKE_reports_string(reports, RPT_ERROR); if (clear) { BKE_reports_clear(reports); @@ -79,7 +79,7 @@ short BPy_reports_to_error(ReportList *reports, PyObject *exception, const short short BPy_errors_to_report(ReportList *reports) { PyObject *pystring; - PyObject *pystring_format= NULL; // workaround, see below + PyObject *pystring_format = NULL; // workaround, see below char *cstring; const char *filename; @@ -89,30 +89,30 @@ short BPy_errors_to_report(ReportList *reports) return 1; /* less hassle if we allow NULL */ - if (reports==NULL) { + if (reports == NULL) { PyErr_Print(); PyErr_Clear(); return 1; } - pystring= PyC_ExceptionBuffer(); + pystring = PyC_ExceptionBuffer(); - if (pystring==NULL) { + if (pystring == NULL) { BKE_report(reports, RPT_ERROR, "unknown py-exception, couldn't convert"); return 0; } PyC_FileAndNum(&filename, &lineno); - if (filename==NULL) - filename= "<unknown location>"; + if (filename == NULL) + filename = "<unknown location>"; - cstring= _PyUnicode_AsString(pystring); + cstring = _PyUnicode_AsString(pystring); #if 0 // ARG!. workaround for a bug in blenders use of vsnprintf BKE_reportf(reports, RPT_ERROR, "%s\nlocation:%s:%d\n", cstring, filename, lineno); #else - pystring_format= PyUnicode_FromFormat("%s\nlocation:%s:%d\n", cstring, filename, lineno); - cstring= _PyUnicode_AsString(pystring_format); + pystring_format = PyUnicode_FromFormat("%s\nlocation:%s:%d\n", cstring, filename, lineno); + cstring = _PyUnicode_AsString(pystring_format); BKE_report(reports, RPT_ERROR, cstring); #endif diff --git a/source/blender/python/mathutils/mathutils.c b/source/blender/python/mathutils/mathutils.c index 739206feefd..c9afb7edf4b 100644 --- a/source/blender/python/mathutils/mathutils.c +++ b/source/blender/python/mathutils/mathutils.c @@ -284,7 +284,7 @@ PyObject *mathutils_dynstr_to_py(struct DynStr *ds) /* Mathutils Callbacks */ /* for mathutils internal use only, eventually should re-alloc but to start with we only have a few users */ -static Mathutils_Callback *mathutils_callbacks[8] = {NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL}; +static Mathutils_Callback *mathutils_callbacks[8] = {NULL}; int Mathutils_RegisterCallback(Mathutils_Callback *cb) { @@ -459,6 +459,7 @@ PyMODINIT_FUNC PyInit_mathutils(void) mathutils_matrix_row_cb_index = Mathutils_RegisterCallback(&mathutils_matrix_row_cb); mathutils_matrix_col_cb_index = Mathutils_RegisterCallback(&mathutils_matrix_col_cb); + mathutils_matrix_translation_cb_index = Mathutils_RegisterCallback(&mathutils_matrix_translation_cb); return submodule; } diff --git a/source/blender/python/mathutils/mathutils_Euler.c b/source/blender/python/mathutils/mathutils_Euler.c index 02ed208b35d..66caed50aa9 100644 --- a/source/blender/python/mathutils/mathutils_Euler.c +++ b/source/blender/python/mathutils/mathutils_Euler.c @@ -198,7 +198,7 @@ static PyObject *Euler_rotate_axis(EulerObject *self, PyObject *args) float angle = 0.0f; int axis; /* actually a character */ - if (!PyArg_ParseTuple(args, "Cf:rotate", &axis, &angle)) { + if (!PyArg_ParseTuple(args, "Cf:rotate_axis", &axis, &angle)) { PyErr_SetString(PyExc_TypeError, "Euler.rotate_axis(): " "expected an axis 'X', 'Y', 'Z' and an angle (float)"); diff --git a/source/blender/python/mathutils/mathutils_Matrix.c b/source/blender/python/mathutils/mathutils_Matrix.c index 7e881fd5dda..c44443f0ed5 100644 --- a/source/blender/python/mathutils/mathutils_Matrix.c +++ b/source/blender/python/mathutils/mathutils_Matrix.c @@ -48,22 +48,53 @@ static int Matrix_ass_slice(MatrixObject *self, int begin, int end, PyObject *va static PyObject *matrix__apply_to_copy(PyNoArgsFunction matrix_func, MatrixObject *self); static PyObject *MatrixAccess_CreatePyObject(MatrixObject *matrix, const eMatrixAccess_t type); -/* matrix row callbacks */ +static int matrix_row_vector_check(MatrixObject *mat, VectorObject *vec, int row) +{ + if ((vec->size != mat->num_col) || (row >= mat->num_row)) { + PyErr_SetString(PyExc_AttributeError, + "Matrix(): " + "owner matrix has been resized since this row vector was created"); + return 0; + } + else { + return 1; + } +} + +static int matrix_col_vector_check(MatrixObject *mat, VectorObject *vec, int col) +{ + if ((vec->size != mat->num_row) || (col >= mat->num_col)) { + PyErr_SetString(PyExc_AttributeError, + "Matrix(): " + "owner matrix has been resized since this column vector was created"); + return 0; + } + else { + return 1; + } +} + +/* ---------------------------------------------------------------------------- + * matrix row callbacks + * this is so you can do matrix[i][j] = val OR matrix.row[i][j] = val */ + int mathutils_matrix_row_cb_index = -1; -static int mathutils_matrix_vector_check(BaseMathObject *bmo) +static int mathutils_matrix_row_check(BaseMathObject *bmo) { MatrixObject *self = (MatrixObject *)bmo->cb_user; return BaseMath_ReadCallback(self); } -static int mathutils_matrix_vector_get(BaseMathObject *bmo, int row) +static int mathutils_matrix_row_get(BaseMathObject *bmo, int row) { MatrixObject *self = (MatrixObject *)bmo->cb_user; int col; if (BaseMath_ReadCallback(self) == -1) return -1; + if (!matrix_row_vector_check(self, (VectorObject *)bmo, row)) + return -1; for (col = 0; col < self->num_col; col++) { bmo->data[col] = MATRIX_ITEM(self, row, col); @@ -72,13 +103,15 @@ static int mathutils_matrix_vector_get(BaseMathObject *bmo, int row) return 0; } -static int mathutils_matrix_vector_set(BaseMathObject *bmo, int row) +static int mathutils_matrix_row_set(BaseMathObject *bmo, int row) { MatrixObject *self = (MatrixObject *)bmo->cb_user; int col; if (BaseMath_ReadCallback(self) == -1) return -1; + if (!matrix_row_vector_check(self, (VectorObject *)bmo, row)) + return -1; for (col = 0; col < self->num_col; col++) { MATRIX_ITEM(self, row, col) = bmo->data[col]; @@ -88,23 +121,27 @@ static int mathutils_matrix_vector_set(BaseMathObject *bmo, int row) return 0; } -static int mathutils_matrix_vector_get_index(BaseMathObject *bmo, int row, int col) +static int mathutils_matrix_row_get_index(BaseMathObject *bmo, int row, int col) { MatrixObject *self = (MatrixObject *)bmo->cb_user; if (BaseMath_ReadCallback(self) == -1) return -1; + if (!matrix_row_vector_check(self, (VectorObject *)bmo, row)) + return -1; bmo->data[col] = MATRIX_ITEM(self, row, col); return 0; } -static int mathutils_matrix_vector_set_index(BaseMathObject *bmo, int row, int col) +static int mathutils_matrix_row_set_index(BaseMathObject *bmo, int row, int col) { MatrixObject *self = (MatrixObject *)bmo->cb_user; if (BaseMath_ReadCallback(self) == -1) return -1; + if (!matrix_row_vector_check(self, (VectorObject *)bmo, row)) + return -1; MATRIX_ITEM(self, row, col) = bmo->data[col]; @@ -113,24 +150,27 @@ static int mathutils_matrix_vector_set_index(BaseMathObject *bmo, int row, int c } Mathutils_Callback mathutils_matrix_row_cb = { - mathutils_matrix_vector_check, - mathutils_matrix_vector_get, - mathutils_matrix_vector_set, - mathutils_matrix_vector_get_index, - mathutils_matrix_vector_set_index + mathutils_matrix_row_check, + mathutils_matrix_row_get, + mathutils_matrix_row_set, + mathutils_matrix_row_get_index, + mathutils_matrix_row_set_index }; -/* matrix vector callbacks, this is so you can do matrix[i][j] = val */ -/* matrix row callbacks */ + +/* ---------------------------------------------------------------------------- + * matrix row callbacks + * this is so you can do matrix.col[i][j] = val */ + int mathutils_matrix_col_cb_index = -1; -static int mathutils_matrix_column_check(BaseMathObject *bmo) +static int mathutils_matrix_col_check(BaseMathObject *bmo) { MatrixObject *self = (MatrixObject *)bmo->cb_user; return BaseMath_ReadCallback(self); } -static int mathutils_matrix_column_get(BaseMathObject *bmo, int col) +static int mathutils_matrix_col_get(BaseMathObject *bmo, int col) { MatrixObject *self = (MatrixObject *)bmo->cb_user; int num_row; @@ -138,6 +178,8 @@ static int mathutils_matrix_column_get(BaseMathObject *bmo, int col) if (BaseMath_ReadCallback(self) == -1) return -1; + if (!matrix_col_vector_check(self, (VectorObject *)bmo, col)) + return -1; /* for 'translation' size will always be '3' even on 4x4 vec */ num_row = MIN2(self->num_row, ((VectorObject *)bmo)->size); @@ -149,7 +191,7 @@ static int mathutils_matrix_column_get(BaseMathObject *bmo, int col) return 0; } -static int mathutils_matrix_column_set(BaseMathObject *bmo, int col) +static int mathutils_matrix_col_set(BaseMathObject *bmo, int col) { MatrixObject *self = (MatrixObject *)bmo->cb_user; int num_row; @@ -157,6 +199,8 @@ static int mathutils_matrix_column_set(BaseMathObject *bmo, int col) if (BaseMath_ReadCallback(self) == -1) return -1; + if (!matrix_col_vector_check(self, (VectorObject *)bmo, col)) + return -1; /* for 'translation' size will always be '3' even on 4x4 vec */ num_row = MIN2(self->num_row, ((VectorObject *)bmo)->size); @@ -169,23 +213,27 @@ static int mathutils_matrix_column_set(BaseMathObject *bmo, int col) return 0; } -static int mathutils_matrix_column_get_index(BaseMathObject *bmo, int col, int row) +static int mathutils_matrix_col_get_index(BaseMathObject *bmo, int col, int row) { MatrixObject *self = (MatrixObject *)bmo->cb_user; if (BaseMath_ReadCallback(self) == -1) return -1; + if (!matrix_col_vector_check(self, (VectorObject *)bmo, col)) + return -1; bmo->data[row] = MATRIX_ITEM(self, row, col); return 0; } -static int mathutils_matrix_column_set_index(BaseMathObject *bmo, int col, int row) +static int mathutils_matrix_col_set_index(BaseMathObject *bmo, int col, int row) { MatrixObject *self = (MatrixObject *)bmo->cb_user; if (BaseMath_ReadCallback(self) == -1) return -1; + if (!matrix_col_vector_check(self, (VectorObject *)bmo, col)) + return -1; MATRIX_ITEM(self, row, col) = bmo->data[row]; @@ -194,12 +242,91 @@ static int mathutils_matrix_column_set_index(BaseMathObject *bmo, int col, int r } Mathutils_Callback mathutils_matrix_col_cb = { - mathutils_matrix_column_check, - mathutils_matrix_column_get, - mathutils_matrix_column_set, - mathutils_matrix_column_get_index, - mathutils_matrix_column_set_index + mathutils_matrix_col_check, + mathutils_matrix_col_get, + mathutils_matrix_col_set, + mathutils_matrix_col_get_index, + mathutils_matrix_col_set_index +}; + + +/* ---------------------------------------------------------------------------- + * matrix row callbacks + * this is so you can do matrix.translation = val + * note, this is _exactly like matrix.col except the 4th component is always omitted */ + +int mathutils_matrix_translation_cb_index = -1; + +static int mathutils_matrix_translation_check(BaseMathObject *bmo) +{ + MatrixObject *self = (MatrixObject *)bmo->cb_user; + return BaseMath_ReadCallback(self); +} + +static int mathutils_matrix_translation_get(BaseMathObject *bmo, int col) +{ + MatrixObject *self = (MatrixObject *)bmo->cb_user; + int row; + + if (BaseMath_ReadCallback(self) == -1) + return -1; + + for (row = 0; row < 3; row++) { + bmo->data[row] = MATRIX_ITEM(self, row, col); + } + + return 0; +} + +static int mathutils_matrix_translation_set(BaseMathObject *bmo, int col) +{ + MatrixObject *self = (MatrixObject *)bmo->cb_user; + int row; + + if (BaseMath_ReadCallback(self) == -1) + return -1; + + for (row = 0; row < 3; row++) { + MATRIX_ITEM(self, row, col) = bmo->data[row]; + } + + (void)BaseMath_WriteCallback(self); + return 0; +} + +static int mathutils_matrix_translation_get_index(BaseMathObject *bmo, int col, int row) +{ + MatrixObject *self = (MatrixObject *)bmo->cb_user; + + if (BaseMath_ReadCallback(self) == -1) + return -1; + + bmo->data[row] = MATRIX_ITEM(self, row, col); + return 0; +} + +static int mathutils_matrix_translation_set_index(BaseMathObject *bmo, int col, int row) +{ + MatrixObject *self = (MatrixObject *)bmo->cb_user; + + if (BaseMath_ReadCallback(self) == -1) + return -1; + + MATRIX_ITEM(self, row, col) = bmo->data[row]; + + (void)BaseMath_WriteCallback(self); + return 0; +} + +Mathutils_Callback mathutils_matrix_translation_cb = { + mathutils_matrix_translation_check, + mathutils_matrix_translation_get, + mathutils_matrix_translation_set, + mathutils_matrix_translation_get_index, + mathutils_matrix_translation_set_index }; + + /* matrix column callbacks, this is so you can do matrix.translation = Vector() */ //----------------------------------mathutils.Matrix() ----------------- @@ -305,13 +432,12 @@ static PyObject *C_Matrix_Rotation(PyObject *cls, PyObject *args) const char *axis = NULL; int matSize; double angle; /* use double because of precision problems at high values */ - float mat[16] = {0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, - 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f}; + float mat[16] = {0.0f, 0.0f, 0.0f, 0.0f, + 0.0f, 0.0f, 0.0f, 0.0f, + 0.0f, 0.0f, 0.0f, 0.0f, + 0.0f, 0.0f, 0.0f, 1.0f}; - if (!PyArg_ParseTuple(args, "di|O", &angle, &matSize, &vec)) { - PyErr_SetString(PyExc_TypeError, - "Matrix.Rotation(angle, size, axis): " - "expected float int and a string or vector"); + if (!PyArg_ParseTuple(args, "di|O:Matrix.Rotation", &angle, &matSize, &vec)) { return NULL; } @@ -425,8 +551,10 @@ static PyObject *C_Matrix_Scale(PyObject *cls, PyObject *args) float tvec[3]; float factor; int matSize; - float mat[16] = {0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, - 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f}; + float mat[16] = {0.0f, 0.0f, 0.0f, 0.0f, + 0.0f, 0.0f, 0.0f, 0.0f, + 0.0f, 0.0f, 0.0f, 0.0f, + 0.0f, 0.0f, 0.0f, 1.0f}; if (!PyArg_ParseTuple(args, "fi|O:Matrix.Scale", &factor, &matSize, &vec)) { return NULL; @@ -439,7 +567,9 @@ static PyObject *C_Matrix_Scale(PyObject *cls, PyObject *args) } if (vec) { vec_size = (matSize == 2 ? 2 : 3); - if (mathutils_array_parse(tvec, vec_size, vec_size, vec, "Matrix.Scale(factor, size, axis), invalid 'axis' arg") == -1) { + if (mathutils_array_parse(tvec, vec_size, vec_size, vec, + "Matrix.Scale(factor, size, axis), invalid 'axis' arg") == -1) + { return NULL; } } @@ -511,8 +641,10 @@ static PyObject *C_Matrix_OrthoProjection(PyObject *cls, PyObject *args) int matSize, x; float norm = 0.0f; - float mat[16] = {0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, - 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f}; + float mat[16] = {0.0f, 0.0f, 0.0f, 0.0f, + 0.0f, 0.0f, 0.0f, 0.0f, + 0.0f, 0.0f, 0.0f, 0.0f, + 0.0f, 0.0f, 0.0f, 1.0f}; if (!PyArg_ParseTuple(args, "Oi:Matrix.OrthoProjection", &axis, &matSize)) { return NULL; @@ -630,8 +762,10 @@ static PyObject *C_Matrix_Shear(PyObject *cls, PyObject *args) int matSize; const char *plane; PyObject *fac; - float mat[16] = {0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, - 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f}; + float mat[16] = {0.0f, 0.0f, 0.0f, 0.0f, + 0.0f, 0.0f, 0.0f, 0.0f, + 0.0f, 0.0f, 0.0f, 0.0f, + 0.0f, 0.0f, 0.0f, 1.0f}; if (!PyArg_ParseTuple(args, "siO:Matrix.Shear", &plane, &matSize, &fac)) { return NULL; @@ -1624,8 +1758,11 @@ static int Matrix_ass_slice(MatrixObject *self, int begin, int end, PyObject *va /* parse each sub sequence */ PyObject *item = PySequence_Fast_GET_ITEM(value_fast, row - begin); - if (mathutils_array_parse(vec, self->num_col, self->num_col, item, "matrix[begin:end] = value assignment") < 0) + if (mathutils_array_parse(vec, self->num_col, self->num_col, item, + "matrix[begin:end] = value assignment") < 0) + { return -1; + } for (col = 0; col < self->num_col; col++) { mat[col * self->num_row + row] = vec[col]; @@ -1739,7 +1876,7 @@ static PyObject *Matrix_mul(PyObject *m1, PyObject *m2) 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f}; - double dot = 0.0f; + int col, row, item; if (mat1->num_col != mat2->num_row) { @@ -1751,11 +1888,11 @@ static PyObject *Matrix_mul(PyObject *m1, PyObject *m2) for (col = 0; col < mat2->num_col; col++) { for (row = 0; row < mat1->num_row; row++) { + double dot = 0.0f; for (item = 0; item < mat1->num_col; item++) { dot += MATRIX_ITEM(mat1, row, item) * MATRIX_ITEM(mat2, item, col); } mat[(col * mat1->num_row) + row] = (float)dot; - dot = 0.0f; } } @@ -1972,7 +2109,7 @@ static PyObject *Matrix_translation_get(MatrixObject *self, void *UNUSED(closure return NULL; } - ret = (PyObject *)Vector_CreatePyObject_cb((PyObject *)self, 3, mathutils_matrix_col_cb_index, 3); + ret = (PyObject *)Vector_CreatePyObject_cb((PyObject *)self, 3, mathutils_matrix_translation_cb_index, 3); return ret; } @@ -1992,8 +2129,9 @@ static int Matrix_translation_set(MatrixObject *self, PyObject *value, void *UNU return -1; } - if ((mathutils_array_parse(tvec, 3, 3, value, "Matrix.translation")) == -1) + if ((mathutils_array_parse(tvec, 3, 3, value, "Matrix.translation")) == -1) { return -1; + } copy_v3_v3(((float (*)[4])self->matrix)[3], tvec); diff --git a/source/blender/python/mathutils/mathutils_Matrix.h b/source/blender/python/mathutils/mathutils_Matrix.h index 7602f98dea4..2ecbc55da35 100644 --- a/source/blender/python/mathutils/mathutils_Matrix.h +++ b/source/blender/python/mathutils/mathutils_Matrix.h @@ -75,8 +75,11 @@ PyObject *Matrix_CreatePyObject_cb(PyObject *user, extern int mathutils_matrix_row_cb_index; /* default */ extern int mathutils_matrix_col_cb_index; +extern int mathutils_matrix_translation_cb_index; + extern struct Mathutils_Callback mathutils_matrix_row_cb; /* default */ extern struct Mathutils_Callback mathutils_matrix_col_cb; +extern struct Mathutils_Callback mathutils_matrix_translation_cb; void matrix_as_3x3(float mat[3][3], MatrixObject *self); diff --git a/source/blender/python/mathutils/mathutils_Quaternion.c b/source/blender/python/mathutils/mathutils_Quaternion.c index 258a802b92b..20e951800c2 100644 --- a/source/blender/python/mathutils/mathutils_Quaternion.c +++ b/source/blender/python/mathutils/mathutils_Quaternion.c @@ -194,8 +194,10 @@ static PyObject *Quaternion_cross(QuaternionObject *self, PyObject *value) if (BaseMath_ReadCallback(self) == -1) return NULL; - if (mathutils_array_parse(tquat, QUAT_SIZE, QUAT_SIZE, value, "Quaternion.cross(other), invalid 'other' arg") == -1) + if (mathutils_array_parse(tquat, QUAT_SIZE, QUAT_SIZE, value, + "Quaternion.cross(other), invalid 'other' arg") == -1) { return NULL; + } mul_qt_qtqt(quat, self->quat, tquat); return Quaternion_CreatePyObject(quat, Py_NEW, Py_TYPE(self)); diff --git a/source/blender/python/mathutils/mathutils_Vector.c b/source/blender/python/mathutils/mathutils_Vector.c index 79abf384eb0..e137c7846bb 100644 --- a/source/blender/python/mathutils/mathutils_Vector.c +++ b/source/blender/python/mathutils/mathutils_Vector.c @@ -279,7 +279,9 @@ static PyObject *C_Vector_Repeat(PyObject *cls, PyObject *args) return NULL; } - if ((value_size = mathutils_array_parse_alloc(&iter_vec, 2, value, "Vector.Repeat(vector, size), invalid 'vector' arg")) == -1) { + if ((value_size = mathutils_array_parse_alloc(&iter_vec, 2, value, + "Vector.Repeat(vector, size), invalid 'vector' arg")) == -1) + { PyMem_Free(iter_vec); return NULL; } @@ -1489,7 +1491,6 @@ static PyObject *Vector_isub(PyObject *v1, PyObject *v2) int column_vector_multiplication(float r_vec[MAX_DIMENSIONS], VectorObject *vec, MatrixObject *mat) { float vec_cpy[MAX_DIMENSIONS]; - double dot = 0.0f; int row, col, z = 0; if (mat->num_col != vec->size) { @@ -1510,11 +1511,11 @@ int column_vector_multiplication(float r_vec[MAX_DIMENSIONS], VectorObject *vec, r_vec[3] = 1.0f; for (row = 0; row < mat->num_row; row++) { + double dot = 0.0f; for (col = 0; col < mat->num_col; col++) { dot += (double)(MATRIX_ITEM(mat, row, col) * vec_cpy[col]); } r_vec[z++] = (float)dot; - dot = 0.0f; } return 0; @@ -2625,7 +2626,7 @@ if len(unique) != len(items): * [2][5][8] * [3][6][9] * vector/matrix multiplication IS NOT COMMUTATIVE!!!! */ -static int row_vector_multiplication(float rvec[MAX_DIMENSIONS], VectorObject *vec, MatrixObject *mat) +static int row_vector_multiplication(float r_vec[MAX_DIMENSIONS], VectorObject *vec, MatrixObject *mat) { float vec_cpy[MAX_DIMENSIONS]; int row, col, z = 0, vec_size = vec->size; @@ -2647,14 +2648,14 @@ static int row_vector_multiplication(float rvec[MAX_DIMENSIONS], VectorObject *v memcpy(vec_cpy, vec->vec, vec_size * sizeof(float)); - rvec[3] = 1.0f; + r_vec[3] = 1.0f; //muliplication for (col = 0; col < mat->num_col; col++) { double dot = 0.0; for (row = 0; row < mat->num_row; row++) { dot += MATRIX_ITEM(mat, row, col) * vec_cpy[row]; } - rvec[z++] = (float)dot; + r_vec[z++] = (float)dot; } return 0; } diff --git a/source/creator/creator.c b/source/creator/creator.c index c1de6868f7b..27bf95c3e80 100644 --- a/source/creator/creator.c +++ b/source/creator/creator.c @@ -305,7 +305,7 @@ static int print_help(int UNUSED(argc), const char **UNUSED(argv), void *data) printf (" $BLENDER_USER_CONFIG Directory for user configuration files.\n"); printf (" $BLENDER_USER_SCRIPTS Directory for user scripts.\n"); printf (" $BLENDER_SYSTEM_SCRIPTS Directory for system wide scripts.\n"); - printf (" $BLENDER_USER_DAT`AFILES Directory for user data files (icons, translations, ..).\n"); + printf (" $Directory for user data files (icons, translations, ..).\n"); printf (" $BLENDER_SYSTEM_DATAFILES Directory for system wide data files.\n"); printf (" $BLENDER_SYSTEM_PYTHON Directory for system python libraries.\n"); #ifdef WIN32 |