56
49
static inline int type##_CheckExact (PyObject *o) \
58
return ((o)->ob_type == &type##_Type); \
51
return (Py_TYPE(o) == &type##_Type); \
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.
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.
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.
76
(PyUnicode_Check(obj) ? (obj) : NULL), \
77
(PyUnicode_Check(obj) ? NULL : PyBytes_AS_STRING(obj))
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))
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))
98
PyMODINIT_FUNC PyInit__dbus_bindings(void);
61
100
PyMODINIT_FUNC init_dbus_bindings(void);
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)
142
extern PyTypeObject DBusPyUTF8String_Type;
100
143
DEFINE_CHECK(DBusPyUTF8String)
101
DEFINE_CHECK(DBusPyString)
102
145
extern PyTypeObject DBusPyDouble_Type;
103
146
DEFINE_CHECK(DBusPyDouble)
104
147
extern PyTypeObject DBusPyInt16_Type, DBusPyUInt16_Type;
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 *,
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);
212
251
void _dbus_py_whereami(void);
213
252
void _dbus_py_dbg_dump_message(DBusMessage *);
215
# define TRACE(self) do { fprintf(stderr, "TRACE: <%s at %p> in %s, " \
217
self->ob_type->tp_name, \
219
self->ob_refcnt); } while (0)
254
# define TRACE(self) do { \
255
fprintf(stderr, "TRACE: <%s at %p> in %s, " \
257
self ? Py_TYPE(self)->tp_name : NULL, \
259
self ? (int)Py_REFCNT(self) : 0); \
220
261
# define DBG(format, ...) fprintf(stderr, "DEBUG: " format "\n",\
222
263
# define DBG_EXC(format, ...) do {DBG(format, __VA_ARGS__); \