diff options
author | Igor Pashev <pashev.igor@gmail.com> | 2015-07-05 22:06:22 +0300 |
---|---|---|
committer | Igor Pashev <pashev.igor@gmail.com> | 2015-07-05 22:06:22 +0300 |
commit | 622812485150fa7864910ee2f710d5aab2fa9e6d (patch) | |
tree | b3bc4fd72bb80e74ba5a60d8b3d47e610dff012e /python/generic.h | |
parent | 798846ab8337471998b0a4d796d6d409453faa7d (diff) | |
parent | fdd173dd444098ed533cbcd541a7f10f228bc47e (diff) | |
download | python-apt-622812485150fa7864910ee2f710d5aab2fa9e6d.tar.gz |
Merge git://anonscm.debian.org/apt/python-apt
Conflicts:
debian/changelog
python/apt_pkgmodule.cc
Diffstat (limited to 'python/generic.h')
-rw-r--r-- | python/generic.h | 53 |
1 files changed, 46 insertions, 7 deletions
diff --git a/python/generic.h b/python/generic.h index 914456e2..bcc4a5e4 100644 --- a/python/generic.h +++ b/python/generic.h @@ -58,8 +58,6 @@ typedef int Py_ssize_t; #define PyInt_Check PyLong_Check #define PyInt_AsLong PyLong_AsLong #define PyInt_FromLong PyLong_FromLong -// Force 0.7 compatibility to be off in Python 3 builds -#undef COMPAT_0_7 #else // Compatibility for Python 2.5 and previous. #if (PY_MAJOR_VERSION == 2 && PY_MINOR_VERSION <= 5) @@ -77,6 +75,11 @@ typedef int Py_ssize_t; #define PyErr_WarnEx(cat,msg,stacklevel) PyErr_Warn(cat,msg) #endif +#define PY_APT_BEGIN_DEPRECATED { \ + _Pragma("GCC diagnostic push"); \ + _Pragma("GCC diagnostic ignored \"-Wdeprecated-declarations\""); } +#define PY_APT_END_DEPRECATED _Pragma("GCC diagnostic pop") + static inline const char *PyUnicode_AsString(PyObject *op) { // Convert to bytes object, using the default encoding. @@ -247,14 +250,50 @@ inline PyObject *MkPyNumber(long long o) { return PyLong_FromLongLong(o); } inline PyObject *MkPyNumber(long o) { return PyInt_FromLong(o); } inline PyObject *MkPyNumber(int o) { return PyInt_FromLong(o); } inline PyObject *MkPyNumber(short o) { return PyInt_FromLong(o); } -inline PyObject *MkPyNumber(char o) { return PyInt_FromLong(o); } +inline PyObject *MkPyNumber(signed char o) { return PyInt_FromLong(o); } inline PyObject *MkPyNumber(double o) { return PyFloat_FromDouble(o); } -# ifdef COMPAT_0_7 -PyObject *_PyAptObject_getattro(PyObject *self, PyObject *attr); -# else # define _PyAptObject_getattro 0 -# endif + + +/** + * Magic class for file name handling + * + * This manages decoding file names from Python objects; bytes and unicode + * objects. On Python 2, this does the same conversion as PyObject_AsString, + * on Python3, it uses PyUnicode_EncodeFSDefault for unicode objects. + */ +class PyApt_Filename { +public: + PyObject *object; + const char *path; + + PyApt_Filename() { + object = NULL; + path = NULL; + } + + int init(PyObject *object); + + ~PyApt_Filename() { + Py_XDECREF(object); + } + + static int Converter(PyObject *object, void *out) { + return static_cast<PyApt_Filename *>(out)->init(object); + } + + operator const char *() { + return path; + } + operator const std::string() { + return path; + } + + const char *operator=(const char *path) { + return this->path = path; + } +}; #endif |