From caef6ff047586413cbd2daef969f29c38481fa86 Mon Sep 17 00:00:00 2001 From: Julian Andres Klode Date: Tue, 14 Apr 2009 19:07:07 +0200 Subject: * python/depcache.cc: Use tp_methods and tp_getset for PkgDepCacheType --- python/apt_pkgmodule.cc | 1 + python/depcache.cc | 77 +++++++++++++++++++++++++++++++------------------ 2 files changed, 50 insertions(+), 28 deletions(-) (limited to 'python') diff --git a/python/apt_pkgmodule.cc b/python/apt_pkgmodule.cc index 49b6a35f..8ed3e599 100644 --- a/python/apt_pkgmodule.cc +++ b/python/apt_pkgmodule.cc @@ -484,6 +484,7 @@ extern "C" void initapt_pkg() if (PyType_Ready(&PkgSourceListType) == -1) return; if (PyType_Ready(&PkgCacheType) == -1) return; if (PyType_Ready(&DependencyType) == -1) return; + if (PyType_Ready(&PkgDepCacheType) == -1) return; // Initialize the module diff --git a/python/depcache.cc b/python/depcache.cc index 2c73a1a9..ade3d4f5 100644 --- a/python/depcache.cc +++ b/python/depcache.cc @@ -560,50 +560,71 @@ static PyMethodDef PkgDepCacheMethods[] = {} }; - -static PyObject *DepCacheAttr(PyObject *Self,char *Name) -{ - pkgDepCache *depcache = GetCpp(Self); - - // size querries - if(strcmp("KeepCount",Name) == 0) - return Py_BuildValue("l", depcache->KeepCount()); - else if(strcmp("InstCount",Name) == 0) - return Py_BuildValue("l", depcache->InstCount()); - else if(strcmp("DelCount",Name) == 0) - return Py_BuildValue("l", depcache->DelCount()); - else if(strcmp("BrokenCount",Name) == 0) - return Py_BuildValue("l", depcache->BrokenCount()); - else if(strcmp("UsrSize",Name) == 0) - return Py_BuildValue("d", depcache->UsrSize()); - else if(strcmp("DebSize",Name) == 0) - return Py_BuildValue("d", depcache->DebSize()); - - - return Py_FindMethod(PkgDepCacheMethods,Self,Name); +#define depcache (GetCpp(Self)) +static PyObject *PkgDepCacheGetKeepCount(PyObject *Self,void*) { + return Py_BuildValue("l", depcache->KeepCount()); } +static PyObject *PkgDepCacheGetInstCount(PyObject *Self,void*) { + return Py_BuildValue("l", depcache->InstCount()); +} +static PyObject *PkgDepCacheGetDelCount(PyObject *Self,void*) { + return Py_BuildValue("l", depcache->DelCount()); +} +static PyObject *PkgDepCacheGetBrokenCount(PyObject *Self,void*) { + return Py_BuildValue("l", depcache->BrokenCount()); +} +static PyObject *PkgDepCacheGetUsrSize(PyObject *Self,void*) { + return Py_BuildValue("d", depcache->UsrSize()); +} +static PyObject *PkgDepCacheGetDebSize(PyObject *Self,void*) { + return Py_BuildValue("d", depcache->DebSize()); +} +#undef depcache - - +static PyGetSetDef PkgDepCacheGetSet[] = { + {"BrokenCount",PkgDepCacheGetBrokenCount}, + {"DebSize",PkgDepCacheGetDebSize}, + {"DelCount",PkgDepCacheGetDelCount}, + {"InstCount",PkgDepCacheGetInstCount}, + {"KeepCount",PkgDepCacheGetKeepCount}, + {"UsrSize",PkgDepCacheGetUsrSize}, + {} +}; PyTypeObject PkgDepCacheType = { PyObject_HEAD_INIT(&PyType_Type) - 0, // ob_size - "pkgDepCache", // tp_name + 0, // ob_size + "pkgDepCache", // tp_name sizeof(CppOwnedPyObject), // tp_basicsize 0, // tp_itemsize // Methods - CppOwnedDealloc, // tp_dealloc + CppOwnedDealloc, // tp_dealloc 0, // tp_print - DepCacheAttr, // tp_getattr + 0, // tp_getattr 0, // tp_setattr 0, // tp_compare 0, // tp_repr 0, // tp_as_number 0, // tp_as_sequence - 0, // tp_as_mapping + 0, // 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 + "pkgDepCache Object", // tp_doc + 0, // tp_traverse + 0, // tp_clear + 0, // tp_richcompare + 0, // tp_weaklistoffset + 0, // tp_iter + 0, // tp_iternext + PkgDepCacheMethods, // tp_methods + 0, // tp_members + PkgDepCacheGetSet, // tp_getset }; -- cgit v1.2.3