From e1a600aba9e691241ea98a9a5c29104be200841b Mon Sep 17 00:00:00 2001 From: "Ralf W. Grosse-Kunstleve" Date: Tue, 6 Mar 2001 23:08:29 +0000 Subject: [PATCH] SPECIAL_PYCVTSOBJECT removed for now. [SVN r9468] --- include/boost/python/x_class_builder.hpp | 77 ------------------------ src/x_class_builder.cpp | 39 ------------ 2 files changed, 116 deletions(-) diff --git a/include/boost/python/x_class_builder.hpp b/include/boost/python/x_class_builder.hpp index 7a5fd8cd..813357a2 100644 --- a/include/boost/python/x_class_builder.hpp +++ b/include/boost/python/x_class_builder.hpp @@ -3,12 +3,6 @@ # include -//QUESTIONMARK -// Do we really need the special PyCvtsObject? -// Is there a better way of creating the special PyCvtsObject? -// My solution adds a lot of code including several reinterpret_cast. -//#define SPECIAL_PYCVTSOBJECT - namespace boost { namespace python { struct import_error : error_already_set {}; struct export_error : error_already_set {}; @@ -21,15 +15,9 @@ namespace boost { namespace python { namespace detail { const int EXPORT_CONVERTERS_API_MAJOR = 1; const int EXPORT_CONVERTERS_API_MINOR = 1; const std::string converters_attribute_name = "__converters__"; -#ifndef SPECIAL_PYCVTSOBJECT void *import_converters(const std::string& module_name, const std::string& klass_name, const std::string& attribute_name); -#else -PyObject *new_import_converters(const std::string& module_name, - const std::string& klass_name, - const std::string& attribute_name); -#endif void check_export_converters_api(const int importing_major, const int importing_minor, const int imported_major, @@ -222,74 +210,14 @@ template boost::python::export_converters_base* import_extension_class::imported_converters = 0; -#ifdef SPECIAL_PYCVTSOBJECT - -// A special PyObject for passing pointers to export_converters_base -template -struct PyCvtsObject { - PyObject_HEAD - export_converters_base* cvts; -}; - -template -void DEL_PyCvtsObject(PyCvtsObject* self) { PyMem_DEL(self); } - -template -PyObject *create_PyCvtsObject(export_converters_base* cvts) -{ - static char PyCvtsObject_Type__doc__[] = - "Boost Python Library (BPL) converters objects to be exported from\n" - "one extension module to another."; - - static PyTypeObject PyCvtsObject_Type = { - PyObject_HEAD_INIT(&PyType_Type) - 0, /*ob_size*/ - "PyCvtsObject", /*tp_name*/ - sizeof(PyCvtsObject), /*tp_basicsize*/ - 0, /*tp_itemsize*/ - /* methods */ - (destructor)(static_cast*)> - (DEL_PyCvtsObject)), /*tp_dealloc*/ - (printfunc)0, /*tp_print*/ - (getattrfunc)0, /*tp_getattr*/ - (setattrfunc)0, /*tp_setattr*/ - (cmpfunc)0, /*tp_compare*/ - (reprfunc)0, /*tp_repr*/ - 0, /*tp_as_number*/ - 0, /*tp_as_sequence*/ - 0, /*tp_as_mapping*/ - (hashfunc)0, /*tp_hash*/ - (ternaryfunc)0, /*tp_call*/ - (reprfunc)0, /*tp_str*/ - - /* Space for future expansion */ - 0L,0L,0L,0L, - PyCvtsObject_Type__doc__ /* Documentation string */ - }; - - PyCvtsObject* self = PyObject_NEW(PyCvtsObject, &PyCvtsObject_Type); - if (self == 0) throw export_error(); - self->cvts = cvts; - return reinterpret_cast(self); -} - -#endif // SPECIAL_PYCVTSOBJECT - template boost::python::export_converters_base* import_extension_class::get_converters() { if (imported_converters == 0) { -#ifndef SPECIAL_PYCVTSOBJECT void *cobject = import_converters(m_module, m_klass, converters_attribute_name); imported_converters = static_cast*>(cobject); -#else - ref cvts_obj( - new_import_converters(m_module, m_klass, converters_attribute_name)); - PyCvtsObject* cvts = reinterpret_cast*>(cvts_obj.get()); - imported_converters = cvts->cvts; -#endif check_export_converters_api( EXPORT_CONVERTERS_API_MAJOR, EXPORT_CONVERTERS_API_MINOR, @@ -338,14 +266,9 @@ class x_class_builder public: x_class_builder(module_builder& module, const char* name) : class_builder(module, name) { -#ifndef SPECIAL_PYCVTSOBJECT add( ref(PyCObject_FromVoidPtr(reinterpret_cast(&export_cvts), NULL)), const_cast(detail::converters_attribute_name.c_str())); -#else - add(ref(detail::create_PyCvtsObject(&export_cvts)), - const_cast(detail::converters_attribute_name.c_str())); -#endif } }; diff --git a/src/x_class_builder.cpp b/src/x_class_builder.cpp index cf81a3f7..a8bc3b03 100644 --- a/src/x_class_builder.cpp +++ b/src/x_class_builder.cpp @@ -16,8 +16,6 @@ namespace { namespace boost { namespace python { namespace detail { -#ifndef SPECIAL_PYCVTSOBJECT - void *import_converters(const std::string& module_name, const std::string& klass_name, const std::string& attribute_name) @@ -50,43 +48,6 @@ void *import_converters(const std::string& module_name, return PyCObject_AsVoidPtr(c_obj.get()); } -#else - -PyObject *new_import_converters(const std::string& module_name, - const std::string& klass_name, - const std::string& attribute_name) -{ - static std::string err; - PyObject *module_dict - = get_module_dict(const_cast(module_name.c_str())); - PyObject *klass - = PyDict_GetItemString(module_dict, const_cast(klass_name.c_str())); - if (klass == 0) { - err = std::string("module ") + module_name + " has no attribute " - + klass_name; - PyErr_SetString(PyExc_RuntimeError, const_cast(err.c_str())); - throw python::import_error(); - } - python::ref cvts_obj(PyObject_GetAttrString(klass, - const_cast(attribute_name.c_str())), ref::null_ok); - if (cvts_obj.get() == 0) { - err = std::string("object ") + module_name + "." + klass_name - + " has no attribute " + attribute_name; - PyErr_SetString(PyExc_RuntimeError, const_cast(err.c_str())); - throw python::import_error(); - } - // Weak point: direct access to ob_type->tp_name - if (strcmp(cvts_obj->ob_type->tp_name, "PyCvtsObject") != 0) { - err = std::string("object ") + module_name + "." + klass_name + "." - + attribute_name + " is not a PyCvtsObject"; - PyErr_SetString(PyExc_RuntimeError, const_cast(err.c_str())); - throw python::import_error(); - } - return cvts_obj.release(); -} - -#endif // SPECIAL_PYCVTSOBJECT - void check_export_converters_api(const int importing_major, const int importing_minor, const int imported_major,