diff options
Diffstat (limited to 'python')
| -rw-r--r-- | python/apt_pkgmodule.cc | 9 | ||||
| -rw-r--r-- | python/apt_pkgmodule.h | 6 | ||||
| -rw-r--r-- | python/configuration.cc | 116 |
3 files changed, 13 insertions, 118 deletions
diff --git a/python/apt_pkgmodule.cc b/python/apt_pkgmodule.cc index 3f18f785..e4fd0dfc 100644 --- a/python/apt_pkgmodule.cc +++ b/python/apt_pkgmodule.cc @@ -527,8 +527,7 @@ extern "C" void initapt_pkg() #endif { // Finalize our types to add slots, etc. - if (PyType_Ready(&PyConfigurationPtr_Type) == -1) INIT_ERROR; - if (PyType_Ready(&PyConfigurationSub_Type) == -1) INIT_ERROR; + if (PyType_Ready(&PyConfiguration_Type) == -1) INIT_ERROR; if (PyType_Ready(&PyCacheFile_Type) == -1) INIT_ERROR; // Initialize the module @@ -539,8 +538,10 @@ extern "C" void initapt_pkg() #endif // Global variable linked to the global configuration class - CppPyObject<Configuration *> *Config = CppPyObject_NEW<Configuration *>(&PyConfigurationPtr_Type); + CppOwnedPyObject<Configuration*> *Config = CppOwnedPyObject_NEW<Configuration*>(NULL, &PyConfiguration_Type); Config->Object = _config; + // Global configuration, should never be deleted. + Config->NoDelete = true; PyModule_AddObject(Module,"config",Config); #ifdef COMPAT_0_7 Py_INCREF(Config); @@ -568,8 +569,6 @@ extern "C" void initapt_pkg() ADDTYPE(Module,"Cdrom",&PyCdrom_Type); /* ========================= configuration.cc ========================= */ ADDTYPE(Module,"Configuration",&PyConfiguration_Type); - //ADDTYPE(Module,"ConfigurationSub",&PyConfigurationSub_Type); // NO __new__() - //ADDTYPE(Module,"ConfigurationPtr",&PyConfigurationPtr_Type); // NO __new__() /* ========================= depcache.cc ========================= */ ADDTYPE(Module,"ActionGroup",&PyActionGroup_Type); ADDTYPE(Module,"DepCache",&PyDepCache_Type); diff --git a/python/apt_pkgmodule.h b/python/apt_pkgmodule.h index 7b835ca8..f77c5e73 100644 --- a/python/apt_pkgmodule.h +++ b/python/apt_pkgmodule.h @@ -14,12 +14,8 @@ #include <apt-pkg/hashes.h> // Configuration Stuff -#define Configuration_Check(op) ((op)->ob_type == &PyConfiguration_Type || \ - (op)->ob_type == &PyConfigurationPtr_Type || \ - (op)->ob_type == &PyConfigurationSub_Type) +#define Configuration_Check(op) ((op)->ob_type == &PyConfiguration_Type) extern PyTypeObject PyConfiguration_Type; -extern PyTypeObject PyConfigurationPtr_Type; -extern PyTypeObject PyConfigurationSub_Type; extern PyTypeObject PyVersion_Type; extern char *doc_LoadConfig; diff --git a/python/configuration.cc b/python/configuration.cc index ba075133..e7e31cc8 100644 --- a/python/configuration.cc +++ b/python/configuration.cc @@ -5,11 +5,8 @@ Configuration - Binding for the configuration object. - There are three seperate classes.. - Configuration - A stand alone configuration instance - ConfigurationPtr - A pointer to a configuration instance, used only - for the global instance (_config) - ConfigurationSub - A subtree - has a reference to its owner. + The Configuration object can have an owner (a parent Configuration object), + and it always uses a pointer. The wrapping is mostly 1:1 with the C++ code, but there are additions to wrap the linked tree walking into nice flat sequence walking. @@ -25,33 +22,13 @@ #include <Python.h> /*}}}*/ -/* If we create a sub tree then it is of this type, the Owner is used - to manage reference counting. */ -struct SubConfiguration : public CppPyObject<Configuration> -{ - PyObject *Owner; -}; - - /*}}}*/ -// CnfSubFree - Free a sub configuration /*{{{*/ -// --------------------------------------------------------------------- -/* */ -void CnfSubFree(PyObject *Obj) -{ - SubConfiguration *Self = (SubConfiguration *)Obj; - Py_DECREF(Self->Owner); - CppDealloc<Configuration>(Obj); -} - /*}}}*/ // GetSelf - Convert PyObject to Configuration /*{{{*/ // --------------------------------------------------------------------- /* */ static inline Configuration &GetSelf(PyObject *Obj) { - if (Obj->ob_type == &PyConfigurationPtr_Type) - return *GetCpp<Configuration *>(Obj); - return GetCpp<Configuration>(Obj); + return *GetCpp<Configuration*>(Obj); } /*}}}*/ @@ -160,13 +137,8 @@ static PyObject *CnfSubTree(PyObject *Self,PyObject *Args) return 0; } - // Create a new sub configuration. - SubConfiguration *New = (SubConfiguration*)(&PyConfigurationSub_Type) - ->tp_alloc(&PyConfigurationSub_Type,0); - new (&New->Object) Configuration(Itm); - New->Owner = Self; - Py_INCREF(Self); - return New; + return CppOwnedPyObject_NEW<Configuration*>(Self,&PyConfiguration_Type, + new Configuration(Itm)); } // Return a list of items at a specific level @@ -495,7 +467,7 @@ static PyObject *CnfNew(PyTypeObject *type, PyObject *args, PyObject *kwds) { char *kwlist[] = {NULL}; if (PyArg_ParseTupleAndKeywords(args,kwds,"",kwlist) == 0) return 0; - return CppPyObject_NEW<Configuration>(type); + return CppOwnedPyObject_NEW<Configuration*>(NULL, type, new Configuration()); } // Type for a Normal Configuration object @@ -505,10 +477,10 @@ PyTypeObject PyConfiguration_Type = { PyVarObject_HEAD_INIT(&PyType_Type, 0) "apt_pkg.Configuration", // tp_name - sizeof(CppPyObject<Configuration>), // tp_basicsize + sizeof(CppOwnedPyObject<Configuration*>), // tp_basicsize 0, // tp_itemsize // Methods - CppDealloc<Configuration>, // tp_dealloc + CppOwnedDeallocPtr<Configuration*>, // tp_dealloc 0, // tp_print 0, // tp_getattr 0, // tp_setattr @@ -545,75 +517,3 @@ PyTypeObject PyConfiguration_Type = CnfNew, // tp_new }; -PyTypeObject PyConfigurationPtr_Type = -{ - PyVarObject_HEAD_INIT(&PyType_Type, 0) - "apt_pkg.ConfigurationPtr", // tp_name - sizeof(CppPyObject<Configuration *>), // tp_basicsize - 0, // tp_itemsize - // Methods - (destructor)PyObject_Free, // tp_dealloc - 0, // tp_print - 0, // tp_getattr - 0, // tp_setattr - 0, // tp_compare - 0, // tp_repr - 0, // tp_as_number - &ConfigurationSeq, // tp_as_sequence - &ConfigurationMap, // tp_as_mapping - 0, // tp_hash - 0, // tp_call - 0, // tp_str - 0, // tp_getattro - 0, // tp_setattro - 0, // tp_as_buffer - Py_TPFLAGS_DEFAULT, // tp_flags - "ConfigurationPtr Object", // tp_doc - 0, // tp_traverse - 0, // tp_clear - 0, // tp_richcompare - 0, // tp_weaklistoffset - 0, // tp_iter - 0, // tp_iternext - CnfMethods, // tp_methods - 0, // tp_members - 0, // tp_getset - &PyConfiguration_Type, // tp_base -}; - -PyTypeObject PyConfigurationSub_Type = -{ - PyVarObject_HEAD_INIT(&PyType_Type, 0) - "apt_pkg.ConfigurationSub", // tp_name - sizeof(SubConfiguration), // tp_basicsize - 0, // tp_itemsize - // Methods - CnfSubFree, // tp_dealloc - 0, // tp_print - 0, // tp_getattr - 0, // tp_setattr - 0, // tp_compare - 0, // tp_repr - 0, // tp_as_number - &ConfigurationSeq, // tp_as_sequence - &ConfigurationMap, // tp_as_mapping - 0, // tp_hash - 0, // tp_call - 0, // tp_str - 0, // tp_getattro - 0, // tp_setattro - 0, // tp_as_buffer - Py_TPFLAGS_DEFAULT, // tp_flags - "ConfigurationSub Object", // tp_doc - 0, // tp_traverse - 0, // tp_clear - 0, // tp_richcompare - 0, // tp_weaklistoffset - 0, // tp_iter - 0, // tp_iternext - CnfMethods, // tp_methods - 0, // tp_members - 0, // tp_getset - &PyConfiguration_Type, // tp_base -}; - |
