[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [19125] branches/blender2.5/blender/source /blender/python/intern: update to build with python 3.0. 1 which removed Py_InitModule3, added richcompare functions to the operator api.
Campbell Barton
ideasman42 at gmail.com
Thu Feb 26 06:50:31 CET 2009
Revision: 19125
http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=19125
Author: campbellbarton
Date: 2009-02-26 06:50:19 +0100 (Thu, 26 Feb 2009)
Log Message:
-----------
update to build with python 3.0.1 which removed Py_InitModule3, added richcompare functions to the operator api.
Modified Paths:
--------------
branches/blender2.5/blender/source/blender/python/intern/bpy_operator.c
branches/blender2.5/blender/source/blender/python/intern/bpy_operator.h
branches/blender2.5/blender/source/blender/python/intern/bpy_rna.c
branches/blender2.5/blender/source/blender/python/intern/bpy_ui.c
branches/blender2.5/blender/source/blender/python/intern/bpy_util.c
Modified: branches/blender2.5/blender/source/blender/python/intern/bpy_operator.c
===================================================================
--- branches/blender2.5/blender/source/blender/python/intern/bpy_operator.c 2009-02-26 05:17:54 UTC (rev 19124)
+++ branches/blender2.5/blender/source/blender/python/intern/bpy_operator.c 2009-02-26 05:50:19 UTC (rev 19125)
@@ -115,6 +115,18 @@
return (strcmp(a->name, b->name)==0) ? 0 : -1;
}
+/* For some reason python3 needs these :/ */
+static PyObject *pyop_func_richcmp(BPy_StructRNA * a, BPy_StructRNA * b, int op)
+{
+ int cmp_result= -1; /* assume false */
+ if (BPy_OperatorFunc_Check(a) && BPy_OperatorFunc_Check(b)) {
+ cmp_result= pyop_func_compare(a, b);
+ }
+
+ return Py_CmpToRich(op, cmp_result);
+}
+
+
/*----------------------repr--------------------------------------------*/
static PyObject *pyop_base_repr( BPy_OperatorBase * self )
{
@@ -379,7 +391,7 @@
NULL, /* printfunc tp_print; */
NULL, /* getattrfunc tp_getattr; */
NULL, /* setattrfunc tp_setattr; */
- ( cmpfunc ) pyop_func_compare, /* tp_compare */
+ NULL, /* tp_compare */ /* DEPRECATED in python 3.0! */
( reprfunc ) pyop_func_repr, /* tp_repr */
/* Method suites for standard classes */
@@ -412,7 +424,7 @@
/*** Assigned meaning in release 2.1 ***/
/*** rich comparisons ***/
- NULL, /* richcmpfunc tp_richcompare; */
+ (richcmpfunc)pyop_func_richcmp, /* richcmpfunc tp_richcompare; */
/*** weak reference enabler ***/
0, /* long tp_weaklistoffset; */
Modified: branches/blender2.5/blender/source/blender/python/intern/bpy_operator.h
===================================================================
--- branches/blender2.5/blender/source/blender/python/intern/bpy_operator.h 2009-02-26 05:17:54 UTC (rev 19124)
+++ branches/blender2.5/blender/source/blender/python/intern/bpy_operator.h 2009-02-26 05:50:19 UTC (rev 19125)
@@ -35,6 +35,9 @@
extern PyTypeObject pyop_base_Type;
extern PyTypeObject pyop_func_Type;
+#define BPy_OperatorFunc_Check(v) (PyObject_TypeCheck(v, &pyop_func_Type))
+#define BPy_PropertyRNA_Check(v) (PyObject_TypeCheck(v, &pyop_func_Type))
+
typedef struct {
PyObject_HEAD /* required python macro */
bContext *C;
Modified: branches/blender2.5/blender/source/blender/python/intern/bpy_rna.c
===================================================================
--- branches/blender2.5/blender/source/blender/python/intern/bpy_rna.c 2009-02-26 05:17:54 UTC (rev 19124)
+++ branches/blender2.5/blender/source/blender/python/intern/bpy_rna.c 2009-02-26 05:50:19 UTC (rev 19125)
@@ -984,7 +984,7 @@
NULL, /* printfunc tp_print; */
NULL, /* getattrfunc tp_getattr; */
NULL, /* setattrfunc tp_setattr; */
- ( cmpfunc ) pyrna_struct_compare, /* tp_compare */
+ NULL, /* tp_compare */ /* DEPRECATED in python 3.0! */
( reprfunc ) pyrna_struct_repr, /* tp_repr */
/* Method suites for standard classes */
@@ -1070,7 +1070,7 @@
NULL, /* printfunc tp_print; */
NULL, /* getattrfunc tp_getattr; */
NULL, /* setattrfunc tp_setattr; */
- ( cmpfunc ) pyrna_prop_compare, /* tp_compare */
+ NULL, /* tp_compare */ /* DEPRECATED in python 3.0! */
( reprfunc ) pyrna_prop_repr, /* tp_repr */
/* Method suites for standard classes */
Modified: branches/blender2.5/blender/source/blender/python/intern/bpy_ui.c
===================================================================
--- branches/blender2.5/blender/source/blender/python/intern/bpy_ui.c 2009-02-26 05:17:54 UTC (rev 19124)
+++ branches/blender2.5/blender/source/blender/python/intern/bpy_ui.c 2009-02-26 05:50:19 UTC (rev 19125)
@@ -247,9 +247,23 @@
{NULL, NULL, 0, NULL}
};
+#if PY_VERSION_HEX >= 0x03000000
+static struct PyModuleDef ui_module = {
+ PyModuleDef_HEAD_INIT,
+ "bpyui",
+ "",
+ -1,/* multiple "initialization" just copies the module dict. */
+ ui_methods,
+ NULL, NULL, NULL, NULL
+};
+
PyObject *BPY_ui_module( void )
{
- PyObject *submodule;
- submodule = Py_InitModule3( "bpyui", ui_methods, "" );
- return submodule;
+ return PyModule_Create(&ui_module);
}
+#else /* Py2.x */
+PyObject *BPY_ui_module( void )
+{
+ return Py_InitModule3( "bpyui", ui_methods, "" );
+}
+#endif
Modified: branches/blender2.5/blender/source/blender/python/intern/bpy_util.c
===================================================================
--- branches/blender2.5/blender/source/blender/python/intern/bpy_util.c 2009-02-26 05:17:54 UTC (rev 19124)
+++ branches/blender2.5/blender/source/blender/python/intern/bpy_util.c 2009-02-26 05:50:19 UTC (rev 19125)
@@ -112,7 +112,7 @@
/* Copied from pythons 3's Object.c */
-#if PY_VERSION_HEX < 0x03000000
+#ifndef Py_CmpToRich
PyObject *
Py_CmpToRich(int op, int cmp)
{
More information about the Bf-blender-cvs
mailing list