update to build with python 3.0.1 which removed Py_InitModule3, added richcompare...
authorCampbell Barton <ideasman42@gmail.com>
Thu, 26 Feb 2009 05:50:19 +0000 (05:50 +0000)
committerCampbell Barton <ideasman42@gmail.com>
Thu, 26 Feb 2009 05:50:19 +0000 (05:50 +0000)
source/blender/python/intern/bpy_operator.c
source/blender/python/intern/bpy_operator.h
source/blender/python/intern/bpy_rna.c
source/blender/python/intern/bpy_ui.c
source/blender/python/intern/bpy_util.c

index 72f4d7fb11e562fd522ad432348f19919cf468fe..3947dc8ab1ebb185b3949c96b437383acf7c0586 100644 (file)
@@ -115,6 +115,18 @@ static int pyop_func_compare( BPy_OperatorFunc * a, BPy_OperatorFunc * b )
        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 @@ PyTypeObject pyop_func_Type = {
        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 @@ PyTypeObject pyop_func_Type = {
 
   /***  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; */
index 5cc3ba64e0e2f797cd481e4765faf4e2cfb540c7..fa12857fe19ecfec75b57db05b15f685b8792898 100644 (file)
@@ -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;
index 35febecfe157e2391d02afe951b025a64f98cc24..e879be52be6551cdfaa15b5d3d24204f152dd1a2 100644 (file)
@@ -984,7 +984,7 @@ PyTypeObject pyrna_struct_Type = {
        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 @@ PyTypeObject pyrna_prop_Type = {
        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 */
index f622c130d6f9c2c7f3720a95fc6e3a6dc0ab7f04..575620443f0349ef13293b92c92323250fb20795 100644 (file)
@@ -247,9 +247,23 @@ static struct PyMethodDef ui_methods[] = {
        {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 )
+{
+       return PyModule_Create(&ui_module);
+}
+#else /* Py2.x */
 PyObject *BPY_ui_module( void )
 {
-       PyObject *submodule;
-       submodule = Py_InitModule3( "bpyui", ui_methods, "" );
-       return submodule;
+       return Py_InitModule3( "bpyui", ui_methods, "" );
 }
+#endif
index bbf766c23eb0c10b48cd1a7528d9b1216d366ab5..63112295d18699bb6e5de993f38a8ab74af21157 100644 (file)
@@ -112,7 +112,7 @@ int BPY_flag_from_seq(BPY_flag_def *flagdef, PyObject *seq, int *flag)
 
 
 /* Copied from pythons 3's Object.c */
-#if PY_VERSION_HEX < 0x03000000
+#ifndef Py_CmpToRich
 PyObject *
 Py_CmpToRich(int op, int cmp)
 {