~jderose/ubuntu/precise/dbus-python/oneiric-backport

« back to all changes in this revision

Viewing changes to _dbus_bindings/dbus_bindings-internal.h

  • Committer: Package Import Robot
  • Author(s): Barry Warsaw
  • Date: 2012-01-12 14:47:33 UTC
  • Revision ID: package-import@ubuntu.com-20120112144733-xtfbmgw30h0j40d2
Tags: 0.84.0-2ubuntu1
* debian/patches:
  - since-0.84.0.patch: Upstream unreleased changes from git tag
    dbus-python-0.84.0 to HEAD.  This is a precursor to the following.
  - python3-support.patch: Upstream unreleased changes from git
    `python3` branch for supporting Python 3. (LP: #893091)
* debian/rules: Enable the test suite.

Show diffs side-by-side

added added

removed removed

Lines of Context:
30
30
 
31
31
#include <Python.h>
32
32
 
33
 
/* Python < 2.5 compat */
34
 
#if PY_VERSION_HEX < 0x02050000 && !defined(PY_SSIZE_T_MIN)
35
 
typedef int Py_ssize_t;
36
 
#define PY_SSIZE_T_MAX INT_MAX
37
 
#define PY_SSIZE_T_MIN INT_MIN
38
 
#endif
39
 
 
40
33
#define INSIDE_DBUS_PYTHON_BINDINGS
41
34
#include "dbus-python.h"
42
35
 
55
48
} \
56
49
static inline int type##_CheckExact (PyObject *o) \
57
50
{ \
58
 
    return ((o)->ob_type == &type##_Type); \
 
51
    return (Py_TYPE(o) == &type##_Type); \
59
52
}
60
53
 
 
54
/* This is a clever little trick to make writing the various object reprs
 
55
 * easier.  It relies on Python's %V format option which consumes two
 
56
 * arguments.  The first is a unicode object which may be NULL, and the second
 
57
 * is a char* which will be used if the first parameter is NULL.
 
58
 *
 
59
 * The issue is that we don't know whether the `parent_repr` at the call site
 
60
 * is a unicode or a bytes (a.k.a. 8-bit string).  Under Python 3, it will
 
61
 * always be a unicode.  Under Python 2 it will *probably* be a bytes/str, but
 
62
 * could potentially be a unicode.  So, we check the type, and if it's a
 
63
 * unicode, we pass that as the first argument, leaving NULL as the second
 
64
 * argument (since it will never be checked).  However, if the object is not a
 
65
 * unicode, it better be a bytes.  In that case, we'll pass NULL as the first
 
66
 * argument so that the second one gets used, and we'll dig the char* out of
 
67
 * the bytes object for that purpose.
 
68
 *
 
69
 * You might think that this would crash if obj is neither a bytes/str or
 
70
 * unicode, and you'd be right *except* that Python doesn't allow any other
 
71
 * types to be returned in the reprs.  Also, since obj will always be the repr
 
72
 * of a built-in type, it will never be anything other than a bytes or a
 
73
 * unicode in any version of Python.  So in practice, this is safe.
 
74
 */
 
75
#define REPRV(obj) \
 
76
    (PyUnicode_Check(obj) ? (obj) : NULL), \
 
77
    (PyUnicode_Check(obj) ? NULL : PyBytes_AS_STRING(obj))
 
78
 
 
79
#ifdef PY3
 
80
#define NATIVEINT_TYPE (PyLong_Type)
 
81
#define NATIVEINT_FROMLONG(x) (PyLong_FromLong(x))
 
82
#define NATIVEINT_ASLONG(x) (PyLong_AsLong(x))
 
83
#define INTORLONG_CHECK(obj) (PyLong_Check(obj))
 
84
#define NATIVESTR_TYPE (PyUnicode_Type)
 
85
#define NATIVESTR_CHECK(obj) (PyUnicode_Check(obj))
 
86
#define NATIVESTR_FROMSTR(obj) (PyUnicode_FromString(obj))
 
87
#else
 
88
#define NATIVEINT_TYPE (PyInt_Type)
 
89
#define NATIVEINT_FROMLONG(x) (PyInt_FromLong(x))
 
90
#define NATIVEINT_ASLONG(x) (PyInt_AsLong(x))
 
91
#define INTORLONG_CHECK(obj) (PyLong_Check(obj) || PyInt_Check(obj))
 
92
#define NATIVESTR_TYPE (PyBytes_Type)
 
93
#define NATIVESTR_CHECK(obj) (PyBytes_Check(obj))
 
94
#define NATIVESTR_FROMSTR(obj) (PyBytes_FromString(obj))
 
95
#endif
 
96
 
 
97
#ifdef PY3
 
98
PyMODINIT_FUNC PyInit__dbus_bindings(void);
 
99
#else
61
100
PyMODINIT_FUNC init_dbus_bindings(void);
 
101
#endif
62
102
 
63
103
/* conn.c */
64
104
extern PyTypeObject DBusPyConnection_Type;
96
136
extern PyTypeObject DBusPyByte_Type, DBusPyByteArray_Type;
97
137
DEFINE_CHECK(DBusPyByteArray)
98
138
DEFINE_CHECK(DBusPyByte)
99
 
extern PyTypeObject DBusPyUTF8String_Type, DBusPyString_Type;
 
139
extern PyTypeObject DBusPyString_Type;
 
140
DEFINE_CHECK(DBusPyString)
 
141
#ifndef PY3
 
142
extern PyTypeObject DBusPyUTF8String_Type;
100
143
DEFINE_CHECK(DBusPyUTF8String)
101
 
DEFINE_CHECK(DBusPyString)
 
144
#endif
102
145
extern PyTypeObject DBusPyDouble_Type;
103
146
DEFINE_CHECK(DBusPyDouble)
104
147
extern PyTypeObject DBusPyInt16_Type, DBusPyUInt16_Type;
134
177
/* generic */
135
178
extern void dbus_py_take_gil_and_xdecref(PyObject *);
136
179
extern int dbus_py_immutable_setattro(PyObject *, PyObject *, PyObject *);
137
 
extern PyObject *dbus_py_tp_richcompare_by_pointer(PyObject *,
138
 
                                                   PyObject *,
139
 
                                                   int);
140
 
extern long dbus_py_tp_hash_by_pointer(PyObject *self);
141
180
extern PyObject *dbus_py_empty_tuple;
142
181
extern dbus_bool_t dbus_py_init_generic(void);
143
182
 
212
251
void _dbus_py_whereami(void);
213
252
void _dbus_py_dbg_dump_message(DBusMessage *);
214
253
 
215
 
#   define TRACE(self) do { fprintf(stderr, "TRACE: <%s at %p> in %s, " \
216
 
                                    "%d refs\n", \
217
 
                                    self->ob_type->tp_name, \
218
 
                                    self, __func__, \
219
 
                                    self->ob_refcnt); } while (0)
 
254
#   define TRACE(self) do { \
 
255
    fprintf(stderr, "TRACE: <%s at %p> in %s, "                 \
 
256
            "%d refs\n",                                        \
 
257
            self ? Py_TYPE(self)->tp_name : NULL,               \
 
258
            self, __func__,                                     \
 
259
            self ? (int)Py_REFCNT(self) : 0);                   \
 
260
    } while (0)
220
261
#   define DBG(format, ...) fprintf(stderr, "DEBUG: " format "\n",\
221
262
                                    __VA_ARGS__)
222
263
#   define DBG_EXC(format, ...) do {DBG(format, __VA_ARGS__); \