From 7440fee85c6d2d4c5854337ae8bf3ed7aea91a50 Mon Sep 17 00:00:00 2001 From: Campbell Barton Date: Mon, 10 Aug 2009 00:07:34 +0000 Subject: remove python2.x support --- source/blender/python/intern/bpy_compat.h | 126 ----------------------- source/blender/python/intern/bpy_interface.c | 20 +--- source/blender/python/intern/bpy_operator.c | 1 - source/blender/python/intern/bpy_operator_wrap.c | 1 - source/blender/python/intern/bpy_rna.c | 39 +------ source/blender/python/intern/bpy_ui.c | 7 -- source/blender/python/intern/bpy_util.c | 4 - source/blender/python/intern/bpy_util.h | 5 +- 8 files changed, 10 insertions(+), 193 deletions(-) delete mode 100644 source/blender/python/intern/bpy_compat.h (limited to 'source/blender/python/intern') diff --git a/source/blender/python/intern/bpy_compat.h b/source/blender/python/intern/bpy_compat.h deleted file mode 100644 index e999f57c733..00000000000 --- a/source/blender/python/intern/bpy_compat.h +++ /dev/null @@ -1,126 +0,0 @@ -/** - * $Id$ - * - * ***** BEGIN GPL LICENSE BLOCK ***** - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License - * as published by the Free Software Foundation; either version 2 - * of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software Foundation, - * Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - * - * Contributor(s): Campbell Barton - * - * ***** END GPL LICENSE BLOCK ***** - */ - -/* This file is only to contain definitions to functions that enable - * the python api to compile with different python versions. - * no utility functions please - */ - -#ifndef BPY_COMPAT_H__ -#define BPY_COMPAT_H__ - -/* if you are NOT using python 3.0 - define these */ -#if PY_VERSION_HEX < 0x03000000 -#define _PyUnicode_AsString PyString_AsString - -#undef PyUnicode_Check -#define PyUnicode_Check PyString_Check - -#define PyLong_FromSsize_t PyInt_FromLong -#define PyLong_AsSsize_t PyInt_AsLong - -#undef PyLong_Check -#define PyLong_Check PyInt_Check - - -#ifdef PyUnicode_FromString -#undef PyUnicode_FromString -#endif -#define PyUnicode_FromString PyString_FromString - -#ifdef PyUnicode_FromFormat -#undef PyUnicode_FromFormat -#endif -#define PyUnicode_FromFormat PyString_FromFormat - -#endif - -#ifndef Py_REFCNT -#define Py_REFCNT(ob) (((PyObject*)(ob))->ob_refcnt) -#endif - -#ifndef Py_TYPE -#define Py_TYPE(ob) (((PyObject*)(ob))->ob_type) -#endif - -#ifndef Py_TYPE -#define Py_SIZE(ob) (((PyVarObject*)(ob))->ob_size) -#endif - -/* older then python 2.6 - define these */ -// #if (PY_VERSION_HEX < 0x02060000) -// #endif - -/* older then python 2.5 - define these */ -#if (PY_VERSION_HEX < 0x02050000) -#define Py_ssize_t ssize_t -typedef Py_ssize_t (*lenfunc)(PyObject *); -#ifndef Py_RETURN_NONE -#define Py_RETURN_NONE return Py_BuildValue("O", Py_None) -#endif -#ifndef Py_RETURN_FALSE -#define Py_RETURN_FALSE return PyBool_FromLong(0) -#endif -#ifndef Py_RETURN_TRUE -#define Py_RETURN_TRUE return PyBool_FromLong(1) -#endif - -#define PyInt_FromSsize_t PyInt_FromLong -#define PyNumber_AsSsize_t(ob, exc) PyInt_AsLong(ob) -#define PyIndex_Check(ob) PyInt_Check(ob) - - -#endif - - -#if PY_VERSION_HEX < 0x03000000 -#ifndef ssizeargfunc -#define ssizeargfunc intargfunc -#endif - -#ifndef ssizessizeargfunc -#define ssizessizeargfunc intintargfunc -#endif - -#ifndef ssizeobjargproc -#define ssizeobjargproc intobjargproc -#endif - -#ifndef ssizessizeobjargproc -#define ssizessizeobjargproc intintobjargproc -#endif -#endif - - - -/* defined in bpy_util.c */ -#if PY_VERSION_HEX < 0x03000000 -PyObject *Py_CmpToRich(int op, int cmp); -#endif - -#ifndef Py_CmpToRich -PyObject *Py_CmpToRich(int op, int cmp); /* bpy_util.c */ -#endif - -#endif /* BPY_COMPAT_H__ */ diff --git a/source/blender/python/intern/bpy_interface.c b/source/blender/python/intern/bpy_interface.c index 4fd4c9caf89..e37e75ab80d 100644 --- a/source/blender/python/intern/bpy_interface.c +++ b/source/blender/python/intern/bpy_interface.c @@ -14,8 +14,6 @@ #include "compile.h" /* for the PyCodeObject */ #include "eval.h" /* for PyEval_EvalCode */ -#include "bpy_compat.h" - #include "bpy_rna.h" #include "bpy_operator.h" #include "bpy_ui.h" @@ -149,18 +147,11 @@ static void bpy_init_modules( void ) /* stand alone utility modules not related to blender directly */ - Geometry_Init("Geometry"); - Mathutils_Init("Mathutils"); - BGL_Init("BGL"); + Geometry_Init(); + Mathutils_Init(); + BGL_Init(); } -#if (PY_VERSION_HEX < 0x02050000) -PyObject *PyImport_ImportModuleLevel(char *name, void *a, void *b, void *c, int d) -{ - return PyImport_ImportModule(name); -} -#endif - void BPY_update_modules( void ) { PyObject *mod= PyImport_ImportModuleLevel("bpy", NULL, NULL, NULL, 0); @@ -244,9 +235,7 @@ void BPY_start_python( int argc, char **argv ) Py_Initialize( ); -#if (PY_VERSION_HEX < 0x03000000) - PySys_SetArgv( argc, argv); -#else + // PySys_SetArgv( argc, argv); // broken in py3, not a huge deal /* sigh, why do python guys not have a char** version anymore? :( */ { int i; @@ -258,7 +247,6 @@ void BPY_start_python( int argc, char **argv ) PySys_SetObject("argv", py_argv); Py_DECREF(py_argv); } -#endif /* Initialize thread support (also acquires lock) */ PyEval_InitThreads(); diff --git a/source/blender/python/intern/bpy_operator.c b/source/blender/python/intern/bpy_operator.c index 034440d77ac..e431f2a21e9 100644 --- a/source/blender/python/intern/bpy_operator.c +++ b/source/blender/python/intern/bpy_operator.c @@ -30,7 +30,6 @@ #include "bpy_operator.h" #include "bpy_operator_wrap.h" #include "bpy_rna.h" /* for setting arg props only - pyrna_py_to_prop() */ -#include "bpy_compat.h" #include "bpy_util.h" #include "WM_api.h" diff --git a/source/blender/python/intern/bpy_operator_wrap.c b/source/blender/python/intern/bpy_operator_wrap.c index a0cbc4637a4..9a74bf0aee8 100644 --- a/source/blender/python/intern/bpy_operator_wrap.c +++ b/source/blender/python/intern/bpy_operator_wrap.c @@ -37,7 +37,6 @@ #include "RNA_define.h" #include "bpy_rna.h" -#include "bpy_compat.h" #include "bpy_util.h" #include "../generic/bpy_internal_import.h" // our own imports diff --git a/source/blender/python/intern/bpy_rna.c b/source/blender/python/intern/bpy_rna.c index c3fcb9a6036..6c959b9f42c 100644 --- a/source/blender/python/intern/bpy_rna.c +++ b/source/blender/python/intern/bpy_rna.c @@ -23,7 +23,6 @@ */ #include "bpy_rna.h" -#include "bpy_compat.h" #include "bpy_util.h" //#include "blendef.h" #include "BLI_dynstr.h" @@ -904,10 +903,6 @@ static PyObject *prop_subscript_collection_str(BPy_PropertyRNA * self, char *key } /* static PyObject *prop_subscript_array_str(BPy_PropertyRNA * self, char *keyname) */ - - - -#if PY_VERSION_HEX >= 0x03000000 static PyObject *prop_subscript_collection_slice(BPy_PropertyRNA * self, int start, int stop) { PointerRNA newptr; @@ -942,7 +937,6 @@ static PyObject *prop_subscript_array_slice(BPy_PropertyRNA * self, int start, i return list; } -#endif static PyObject *prop_subscript_collection(BPy_PropertyRNA * self, PyObject *key) { @@ -956,7 +950,6 @@ static PyObject *prop_subscript_collection(BPy_PropertyRNA * self, PyObject *key return prop_subscript_collection_int(self, i); } -#if PY_VERSION_HEX >= 0x03000000 else if (PySlice_Check(key)) { int len= RNA_property_collection_length(&self->ptr, self->prop); Py_ssize_t start, stop, step, slicelength; @@ -975,7 +968,6 @@ static PyObject *prop_subscript_collection(BPy_PropertyRNA * self, PyObject *key return NULL; } } -#endif else { PyErr_Format(PyExc_TypeError, "invalid rna key, key must be a string or an int instead of %.200s instance.", Py_TYPE(key)->tp_name); return NULL; @@ -993,7 +985,6 @@ static PyObject *prop_subscript_array(BPy_PropertyRNA * self, PyObject *key) return NULL; return prop_subscript_array_int(self, PyLong_AsSsize_t(key)); } -#if PY_VERSION_HEX >= 0x03000000 else if (PySlice_Check(key)) { int len= RNA_property_array_length(self->prop); Py_ssize_t start, stop, step, slicelength; @@ -1012,7 +1003,6 @@ static PyObject *prop_subscript_array(BPy_PropertyRNA * self, PyObject *key) return NULL; } } -#endif else { PyErr_SetString(PyExc_AttributeError, "invalid key, key must be an int"); return NULL; @@ -1032,7 +1022,6 @@ static PyObject *pyrna_prop_subscript( BPy_PropertyRNA * self, PyObject *key ) } -#if PY_VERSION_HEX >= 0x03000000 static int prop_subscript_ass_array_slice(BPy_PropertyRNA * self, int begin, int end, PyObject *value) { int count; @@ -1049,7 +1038,6 @@ static int prop_subscript_ass_array_slice(BPy_PropertyRNA * self, int begin, int return 0; } -#endif static int prop_subscript_ass_array_int(BPy_PropertyRNA * self, int keynum, PyObject *value) { @@ -1087,7 +1075,6 @@ static int pyrna_prop_ass_subscript( BPy_PropertyRNA * self, PyObject *key, PyOb return prop_subscript_ass_array_int(self, i, value); } -#if PY_VERSION_HEX >= 0x03000000 else if (PySlice_Check(key)) { int len= RNA_property_array_length(self->prop); Py_ssize_t start, stop, step, slicelength; @@ -1106,7 +1093,6 @@ static int pyrna_prop_ass_subscript( BPy_PropertyRNA * self, PyObject *key, PyOb return -1; } } -#endif else { PyErr_SetString(PyExc_AttributeError, "invalid key, key must be an int"); return -1; @@ -1458,7 +1444,7 @@ static PyObject *pyrna_prop_get(BPy_PropertyRNA *self, PyObject *args) } -#if (PY_VERSION_HEX >= 0x03000000) /* foreach needs py3 */ + static void foreach_attr_type( BPy_PropertyRNA *self, char *attr, /* values to assign */ RawPropertyType *raw_type, int *attr_tot, int *attr_signed ) @@ -1693,7 +1679,6 @@ static PyObject *pyrna_prop_foreach_set(BPy_PropertyRNA *self, PyObject *args) { return foreach_getset(self, args, 1); } -#endif /* #if (PY_VERSION_HEX >= 0x03000000) */ /* A bit of a kludge, make a list out of a collection or array, * then return the lists iter function, not especially fast but convenient for now */ @@ -1744,11 +1729,10 @@ static struct PyMethodDef pyrna_prop_methods[] = { {"get", (PyCFunction)pyrna_prop_get, METH_VARARGS, NULL}, -#if (PY_VERSION_HEX >= 0x03000000) /* array accessor function */ {"foreach_get", (PyCFunction)pyrna_prop_foreach_get, METH_VARARGS, NULL}, {"foreach_set", (PyCFunction)pyrna_prop_foreach_set, METH_VARARGS, NULL}, -#endif + {NULL, NULL, 0, NULL} }; @@ -2112,13 +2096,7 @@ static PyObject * pyrna_func_call(PyObject * self, PyObject *args, PyObject *kw) /*-----------------------BPy_StructRNA method def------------------------------*/ PyTypeObject pyrna_struct_Type = { -#if (PY_VERSION_HEX >= 0x02060000) PyVarObject_HEAD_INIT(NULL, 0) -#else - /* python 2.5 and below */ - PyObject_HEAD_INIT( NULL ) /* required py macro */ - 0, /* ob_size */ -#endif "StructRNA", /* tp_name */ sizeof( BPy_StructRNA ), /* tp_basicsize */ 0, /* tp_itemsize */ @@ -2197,14 +2175,7 @@ PyTypeObject pyrna_struct_Type = { /*-----------------------BPy_PropertyRNA method def------------------------------*/ PyTypeObject pyrna_prop_Type = { -#if (PY_VERSION_HEX >= 0x02060000) PyVarObject_HEAD_INIT(NULL, 0) -#else - /* python 2.5 and below */ - PyObject_HEAD_INIT( NULL ) /* required py macro */ - 0, /* ob_size */ -#endif - "PropertyRNA", /* tp_name */ sizeof( BPy_PropertyRNA ), /* tp_basicsize */ 0, /* tp_itemsize */ @@ -2555,7 +2526,6 @@ static struct PyMethodDef props_methods[] = { {NULL, NULL, 0, NULL} }; -#if PY_VERSION_HEX >= 0x03000000 static struct PyModuleDef props_module = { PyModuleDef_HEAD_INIT, "bpy.props", @@ -2564,16 +2534,11 @@ static struct PyModuleDef props_module = { props_methods, NULL, NULL, NULL, NULL }; -#endif PyObject *BPY_rna_props( void ) { PyObject *submodule; -#if PY_VERSION_HEX >= 0x03000000 submodule= PyModule_Create(&props_module); -#else /* Py2.x */ - submodule= Py_InitModule3( "bpy.props", props_methods, "" ); -#endif /* INCREF since its its assumed that all these functions return the * module with a new ref like PyDict_New, since they are passed to diff --git a/source/blender/python/intern/bpy_ui.c b/source/blender/python/intern/bpy_ui.c index 59e566b3b37..af3588f458c 100644 --- a/source/blender/python/intern/bpy_ui.c +++ b/source/blender/python/intern/bpy_ui.c @@ -26,7 +26,6 @@ #include "bpy_util.h" #include "bpy_rna.h" /* for rna buttons */ #include "bpy_operator.h" /* for setting button operator properties */ -#include "bpy_compat.h" #include "WM_types.h" /* for WM_OP_INVOKE_DEFAULT & friends */ @@ -47,7 +46,6 @@ static struct PyMethodDef ui_methods[] = { {NULL, NULL, 0, NULL} }; -#if PY_VERSION_HEX >= 0x03000000 static struct PyModuleDef ui_module = { PyModuleDef_HEAD_INIT, "bpy.ui", @@ -56,16 +54,11 @@ static struct PyModuleDef ui_module = { ui_methods, NULL, NULL, NULL, NULL }; -#endif PyObject *BPY_ui_module( void ) { PyObject *submodule, *mod; -#if PY_VERSION_HEX >= 0x03000000 submodule= PyModule_Create(&ui_module); -#else /* Py2.x */ - submodule= Py_InitModule3( "bpy.ui", ui_methods, "" ); -#endif /* INCREF since its its assumed that all these functions return the * module with a new ref like PyDict_New, since they are passed to diff --git a/source/blender/python/intern/bpy_util.c b/source/blender/python/intern/bpy_util.c index 3084cc1f871..25967d96dab 100644 --- a/source/blender/python/intern/bpy_util.c +++ b/source/blender/python/intern/bpy_util.c @@ -373,11 +373,7 @@ PyObject *BPY_exception_buffer(void) * string_io = StringIO.StringIO() */ -#if PY_VERSION_HEX < 0x03000000 - if(! (string_io_mod= PyImport_ImportModule("StringIO")) ) { -#else if(! (string_io_mod= PyImport_ImportModule("io")) ) { -#endif goto error_cleanup; } else if (! (string_io = PyObject_CallMethod(string_io_mod, "StringIO", NULL))) { goto error_cleanup; diff --git a/source/blender/python/intern/bpy_util.h b/source/blender/python/intern/bpy_util.h index df204b7b90d..6751ab59396 100644 --- a/source/blender/python/intern/bpy_util.h +++ b/source/blender/python/intern/bpy_util.h @@ -27,7 +27,10 @@ #ifndef BPY_UTIL_H #define BPY_UTIL_H -#include "bpy_compat.h" +#if PY_VERSION_HEX < 0x03010000 +#error Python versions below 3.1 are not supported anymore, you'll need to update your python. +#endif + #include "RNA_types.h" /* for EnumPropertyItem only */ struct EnumPropertyItem; -- cgit v1.2.3