Blame _dbus_bindings/dbus_bindings-internal.h

Packit 130fc8
/* _dbus_bindings internal API. For use within _dbus_bindings only.
Packit 130fc8
 *
Packit 130fc8
 * Copyright (C) 2006 Collabora Ltd. <http://www.collabora.co.uk/>
Packit 130fc8
 *
Packit 130fc8
 * Permission is hereby granted, free of charge, to any person
Packit 130fc8
 * obtaining a copy of this software and associated documentation
Packit 130fc8
 * files (the "Software"), to deal in the Software without
Packit 130fc8
 * restriction, including without limitation the rights to use, copy,
Packit 130fc8
 * modify, merge, publish, distribute, sublicense, and/or sell copies
Packit 130fc8
 * of the Software, and to permit persons to whom the Software is
Packit 130fc8
 * furnished to do so, subject to the following conditions:
Packit 130fc8
 *
Packit 130fc8
 * The above copyright notice and this permission notice shall be
Packit 130fc8
 * included in all copies or substantial portions of the Software.
Packit 130fc8
 *
Packit 130fc8
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
Packit 130fc8
 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
Packit 130fc8
 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
Packit 130fc8
 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
Packit 130fc8
 * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
Packit 130fc8
 * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
Packit 130fc8
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
Packit 130fc8
 * DEALINGS IN THE SOFTWARE.
Packit 130fc8
 */
Packit 130fc8
Packit 130fc8
#ifndef DBUS_BINDINGS_INTERNAL_H
Packit 130fc8
#define DBUS_BINDINGS_INTERNAL_H
Packit 130fc8
Packit 130fc8
#define PY_SSIZE_T_CLEAN 1
Packit 130fc8
#define PY_SIZE_T_CLEAN 1
Packit 130fc8
Packit 130fc8
#include <Python.h>
Packit 130fc8
Packit 130fc8
#define INSIDE_DBUS_PYTHON_BINDINGS
Packit 130fc8
#include "dbus/dbus-python.h"
Packit 130fc8
Packit 130fc8
#if defined(__GNUC__)
Packit 130fc8
#   if __GNUC__ >= 3
Packit 130fc8
#       define UNUSED __attribute__((__unused__))
Packit 130fc8
#       define NORETURN __attribute__((__noreturn__))
Packit 130fc8
#   else
Packit 130fc8
#       define UNUSED /*nothing*/
Packit 130fc8
#       define NORETURN /*nothing*/
Packit 130fc8
#   endif
Packit 130fc8
#else
Packit 130fc8
#   define UNUSED /*nothing*/
Packit 130fc8
#   define NORETURN /*nothing*/
Packit 130fc8
#endif
Packit 130fc8
Packit 130fc8
/* no need for extern "C", this is only for internal use */
Packit 130fc8
Packit 130fc8
/* on/off switch for debugging support (see below) */
Packit 130fc8
#undef USING_DBG
Packit 130fc8
#if 0 && !defined(DBG_IS_TOO_VERBOSE)
Packit 130fc8
#   define USING_DBG 1
Packit 130fc8
#endif
Packit 130fc8
Packit 130fc8
#define DEFINE_CHECK(type) \
Packit 130fc8
static inline int type##_Check (PyObject *o) \
Packit 130fc8
{ \
Packit 130fc8
    return (PyObject_TypeCheck (o, &type##_Type)); \
Packit 130fc8
} \
Packit 130fc8
static inline int type##_CheckExact (PyObject *o) \
Packit 130fc8
{ \
Packit 130fc8
    return (Py_TYPE(o) == &type##_Type); \
Packit 130fc8
}
Packit 130fc8
Packit 130fc8
/* This is a clever little trick to make writing the various object reprs
Packit 130fc8
 * easier.  It relies on Python's %V format option which consumes two
Packit 130fc8
 * arguments.  The first is a unicode object which may be NULL, and the second
Packit 130fc8
 * is a char* which will be used if the first parameter is NULL.
Packit 130fc8
 *
Packit 130fc8
 * The issue is that we don't know whether the `parent_repr` at the call site
Packit 130fc8
 * is a unicode or a bytes (a.k.a. 8-bit string).  Under Python 3, it will
Packit 130fc8
 * always be a unicode.  Under Python 2 it will *probably* be a bytes/str, but
Packit 130fc8
 * could potentially be a unicode.  So, we check the type, and if it's a
Packit 130fc8
 * unicode, we pass that as the first argument, leaving NULL as the second
Packit 130fc8
 * argument (since it will never be checked).  However, if the object is not a
Packit 130fc8
 * unicode, it better be a bytes.  In that case, we'll pass NULL as the first
Packit 130fc8
 * argument so that the second one gets used, and we'll dig the char* out of
Packit 130fc8
 * the bytes object for that purpose.
Packit 130fc8
 *
Packit 130fc8
 * You might think that this would crash if obj is neither a bytes/str or
Packit 130fc8
 * unicode, and you'd be right *except* that Python doesn't allow any other
Packit 130fc8
 * types to be returned in the reprs.  Also, since obj will always be the repr
Packit 130fc8
 * of a built-in type, it will never be anything other than a bytes or a
Packit 130fc8
 * unicode in any version of Python.  So in practice, this is safe.
Packit 130fc8
 */
Packit 130fc8
#define REPRV(obj) \
Packit 130fc8
    (PyUnicode_Check(obj) ? (obj) : NULL), \
Packit 130fc8
    (PyUnicode_Check(obj) ? NULL : PyBytes_AS_STRING(obj))
Packit 130fc8
Packit 130fc8
#ifdef PY3
Packit 130fc8
#define NATIVEINT_TYPE (PyLong_Type)
Packit 130fc8
#define NATIVEINT_FROMLONG(x) (PyLong_FromLong(x))
Packit 130fc8
#define NATIVEINT_ASLONG(x) (PyLong_AsLong(x))
Packit 130fc8
#define INTORLONG_CHECK(obj) (PyLong_Check(obj))
Packit 130fc8
#define NATIVESTR_TYPE (PyUnicode_Type)
Packit 130fc8
#define NATIVESTR_CHECK(obj) (PyUnicode_Check(obj))
Packit 130fc8
#define NATIVESTR_FROMSTR(obj) (PyUnicode_FromString(obj))
Packit 130fc8
#else
Packit 130fc8
#define NATIVEINT_TYPE (PyInt_Type)
Packit 130fc8
#define NATIVEINT_FROMLONG(x) (PyInt_FromLong(x))
Packit 130fc8
#define NATIVEINT_ASLONG(x) (PyInt_AsLong(x))
Packit 130fc8
#define INTORLONG_CHECK(obj) (PyLong_Check(obj) || PyInt_Check(obj))
Packit 130fc8
#define NATIVESTR_TYPE (PyBytes_Type)
Packit 130fc8
#define NATIVESTR_CHECK(obj) (PyBytes_Check(obj))
Packit 130fc8
#define NATIVESTR_FROMSTR(obj) (PyBytes_FromString(obj))
Packit 130fc8
#endif
Packit 130fc8
Packit 130fc8
#ifdef PY3
Packit 130fc8
PyMODINIT_FUNC PyInit__dbus_bindings(void);
Packit 130fc8
#else
Packit 130fc8
PyMODINIT_FUNC init_dbus_bindings(void);
Packit 130fc8
#endif
Packit 130fc8
Packit 130fc8
/* conn.c */
Packit 130fc8
extern PyTypeObject DBusPyConnection_Type;
Packit 130fc8
DEFINE_CHECK(DBusPyConnection)
Packit 130fc8
extern dbus_bool_t dbus_py_init_conn_types(void);
Packit 130fc8
extern dbus_bool_t dbus_py_insert_conn_types(PyObject *this_module);
Packit 130fc8
Packit 130fc8
/* libdbusconn.c */
Packit 130fc8
extern PyTypeObject DBusPyLibDBusConnection_Type;
Packit 130fc8
DEFINE_CHECK(DBusPyLibDBusConnection)
Packit 130fc8
PyObject *DBusPyLibDBusConnection_New(DBusConnection *conn);
Packit 130fc8
extern dbus_bool_t dbus_py_init_libdbus_conn_types(void);
Packit 130fc8
extern dbus_bool_t dbus_py_insert_libdbus_conn_types(PyObject *this_module);
Packit 130fc8
Packit 130fc8
/* bus.c */
Packit 130fc8
extern dbus_bool_t dbus_py_init_bus_types(void);
Packit 130fc8
extern dbus_bool_t dbus_py_insert_bus_types(PyObject *this_module);
Packit 130fc8
Packit 130fc8
/* exceptions.c */
Packit 130fc8
extern PyObject *DBusPyException_SetString(const char *msg);
Packit 130fc8
extern PyObject *DBusPyException_ConsumeError(DBusError *error);
Packit 130fc8
extern dbus_bool_t dbus_py_init_exception_types(void);
Packit 130fc8
extern dbus_bool_t dbus_py_insert_exception_types(PyObject *this_module);
Packit 130fc8
Packit 130fc8
/* types */
Packit 130fc8
extern PyTypeObject DBusPyBoolean_Type;
Packit 130fc8
DEFINE_CHECK(DBusPyBoolean)
Packit 130fc8
extern PyTypeObject DBusPyObjectPath_Type, DBusPySignature_Type;
Packit 130fc8
DEFINE_CHECK(DBusPyObjectPath)
Packit 130fc8
DEFINE_CHECK(DBusPySignature)
Packit 130fc8
extern PyTypeObject DBusPyArray_Type, DBusPyDict_Type, DBusPyStruct_Type;
Packit 130fc8
DEFINE_CHECK(DBusPyArray)
Packit 130fc8
DEFINE_CHECK(DBusPyDict)
Packit 130fc8
DEFINE_CHECK(DBusPyStruct)
Packit 130fc8
extern PyTypeObject DBusPyByte_Type, DBusPyByteArray_Type;
Packit 130fc8
DEFINE_CHECK(DBusPyByteArray)
Packit 130fc8
DEFINE_CHECK(DBusPyByte)
Packit 130fc8
extern PyTypeObject DBusPyString_Type;
Packit 130fc8
DEFINE_CHECK(DBusPyString)
Packit 130fc8
#ifndef PY3
Packit 130fc8
extern PyTypeObject DBusPyUTF8String_Type;
Packit 130fc8
DEFINE_CHECK(DBusPyUTF8String)
Packit 130fc8
#endif
Packit 130fc8
extern PyTypeObject DBusPyDouble_Type;
Packit 130fc8
DEFINE_CHECK(DBusPyDouble)
Packit 130fc8
extern PyTypeObject DBusPyInt16_Type, DBusPyUInt16_Type;
Packit 130fc8
DEFINE_CHECK(DBusPyInt16)
Packit 130fc8
DEFINE_CHECK(DBusPyUInt16)
Packit 130fc8
extern PyTypeObject DBusPyInt32_Type, DBusPyUInt32_Type;
Packit 130fc8
DEFINE_CHECK(DBusPyInt32)
Packit 130fc8
DEFINE_CHECK(DBusPyUInt32)
Packit 130fc8
extern PyTypeObject DBusPyUnixFd_Type;
Packit 130fc8
DEFINE_CHECK(DBusPyUnixFd)
Packit 130fc8
extern PyTypeObject DBusPyInt64_Type, DBusPyUInt64_Type;
Packit 130fc8
DEFINE_CHECK(DBusPyInt64)
Packit 130fc8
DEFINE_CHECK(DBusPyUInt64)
Packit 130fc8
extern dbus_bool_t dbus_py_init_abstract(void);
Packit 130fc8
extern dbus_bool_t dbus_py_init_signature(void);
Packit 130fc8
extern dbus_bool_t dbus_py_init_int_types(void);
Packit 130fc8
extern dbus_bool_t dbus_py_init_unixfd_type(void);
Packit 130fc8
extern dbus_bool_t dbus_py_init_string_types(void);
Packit 130fc8
extern dbus_bool_t dbus_py_init_float_types(void);
Packit 130fc8
extern dbus_bool_t dbus_py_init_container_types(void);
Packit 130fc8
extern dbus_bool_t dbus_py_init_byte_types(void);
Packit 130fc8
extern dbus_bool_t dbus_py_insert_abstract_types(PyObject *this_module);
Packit 130fc8
extern dbus_bool_t dbus_py_insert_signature(PyObject *this_module);
Packit 130fc8
extern dbus_bool_t dbus_py_insert_int_types(PyObject *this_module);
Packit 130fc8
extern dbus_bool_t dbus_py_insert_unixfd_type(PyObject *this_module);
Packit 130fc8
extern dbus_bool_t dbus_py_insert_string_types(PyObject *this_module);
Packit 130fc8
extern dbus_bool_t dbus_py_insert_float_types(PyObject *this_module);
Packit 130fc8
extern dbus_bool_t dbus_py_insert_container_types(PyObject *this_module);
Packit 130fc8
extern dbus_bool_t dbus_py_insert_byte_types(PyObject *this_module);
Packit 130fc8
Packit 130fc8
int dbus_py_unix_fd_get_fd(PyObject *self);
Packit 130fc8
Packit 130fc8
/* generic */
Packit 130fc8
extern void dbus_py_take_gil_and_xdecref(PyObject *);
Packit 130fc8
extern int dbus_py_immutable_setattro(PyObject *, PyObject *, PyObject *);
Packit 130fc8
extern PyObject *dbus_py_empty_tuple;
Packit 130fc8
extern dbus_bool_t dbus_py_init_generic(void);
Packit 130fc8
Packit 130fc8
/* message.c */
Packit 130fc8
extern DBusMessage *DBusPyMessage_BorrowDBusMessage(PyObject *msg);
Packit 130fc8
extern PyObject *DBusPyMessage_ConsumeDBusMessage(DBusMessage *);
Packit 130fc8
extern dbus_bool_t dbus_py_init_message_types(void);
Packit 130fc8
extern dbus_bool_t dbus_py_insert_message_types(PyObject *this_module);
Packit 130fc8
Packit 130fc8
/* pending-call.c */
Packit 130fc8
extern PyObject *DBusPyPendingCall_ConsumeDBusPendingCall(DBusPendingCall *,
Packit 130fc8
                                                          PyObject *);
Packit 130fc8
extern dbus_bool_t dbus_py_init_pending_call(void);
Packit 130fc8
extern dbus_bool_t dbus_py_insert_pending_call(PyObject *this_module);
Packit 130fc8
Packit 130fc8
/* mainloop.c */
Packit 130fc8
extern dbus_bool_t dbus_py_set_up_connection(PyObject *conn,
Packit 130fc8
                                             PyObject *mainloop);
Packit 130fc8
extern dbus_bool_t dbus_py_set_up_server(PyObject *server,
Packit 130fc8
                                         PyObject *mainloop);
Packit 130fc8
extern PyObject *dbus_py_get_default_main_loop(void);
Packit 130fc8
extern dbus_bool_t dbus_py_check_mainloop_sanity(PyObject *);
Packit 130fc8
extern dbus_bool_t dbus_py_init_mainloop(void);
Packit 130fc8
extern dbus_bool_t dbus_py_insert_mainloop_types(PyObject *);
Packit 130fc8
Packit 130fc8
/* server.c */
Packit 130fc8
extern PyTypeObject DBusPyServer_Type;
Packit 130fc8
DEFINE_CHECK(DBusPyServer)
Packit 130fc8
extern dbus_bool_t dbus_py_init_server_types(void);
Packit 130fc8
extern dbus_bool_t dbus_py_insert_server_types(PyObject *this_module);
Packit 130fc8
extern DBusServer *DBusPyServer_BorrowDBusServer(PyObject *self);
Packit 130fc8
Packit 130fc8
/* validation.c */
Packit 130fc8
dbus_bool_t dbus_py_validate_bus_name(const char *name,
Packit 130fc8
                                      dbus_bool_t may_be_unique,
Packit 130fc8
                                      dbus_bool_t may_be_not_unique);
Packit 130fc8
dbus_bool_t dbus_py_validate_member_name(const char *name);
Packit 130fc8
dbus_bool_t dbus_py_validate_interface_name(const char *name);
Packit 130fc8
dbus_bool_t dbus_py_validate_object_path(const char *path);
Packit 130fc8
#define dbus_py_validate_error_name dbus_py_validate_interface_name
Packit 130fc8
Packit 130fc8
/* debugging support */
Packit 130fc8
void _dbus_py_assertion_failed(const char *) NORETURN;
Packit 130fc8
#define DBUS_PY_RAISE_VIA_NULL_IF_FAIL(assertion) \
Packit 130fc8
    do { if (!(assertion)) { \
Packit 130fc8
            _dbus_py_assertion_failed(#assertion); \
Packit 130fc8
            return NULL; \
Packit 130fc8
        } \
Packit 130fc8
    } while (0)
Packit 130fc8
Packit 130fc8
#define DBUS_PY_RAISE_VIA_GOTO_IF_FAIL(assertion, label) \
Packit 130fc8
    do { if (!(assertion)) { \
Packit 130fc8
            _dbus_py_assertion_failed(#assertion); \
Packit 130fc8
            goto label; \
Packit 130fc8
        } \
Packit 130fc8
    } while (0)
Packit 130fc8
Packit 130fc8
#define DBUS_PY_RAISE_VIA_RETURN_IF_FAIL(assertion, value) \
Packit 130fc8
    do { if (!(assertion)) { \
Packit 130fc8
            _dbus_py_assertion_failed(#assertion); \
Packit 130fc8
            return value; \
Packit 130fc8
        } \
Packit 130fc8
    } while (0)
Packit 130fc8
Packit 130fc8
/* verbose debugging support */
Packit 130fc8
#ifdef USING_DBG
Packit 130fc8
Packit 130fc8
#   include <sys/types.h>
Packit 130fc8
#   include <unistd.h>
Packit 130fc8
Packit 130fc8
void _dbus_py_dbg_exc(void);
Packit 130fc8
void _dbus_py_whereami(void);
Packit 130fc8
void _dbus_py_dbg_dump_message(DBusMessage *);
Packit 130fc8
Packit 130fc8
#   define TRACE(self) do { \
Packit 130fc8
    fprintf(stderr, "TRACE: <%s at %p> in %s, "                 \
Packit 130fc8
            "%d refs\n",                                        \
Packit 130fc8
            self ? Py_TYPE(self)->tp_name : NULL,               \
Packit 130fc8
            self, __func__,                                     \
Packit 130fc8
            self ? (int)Py_REFCNT(self) : 0);                   \
Packit 130fc8
    } while (0)
Packit 130fc8
#   define DBG(format, ...) fprintf(stderr, "DEBUG: " format "\n",\
Packit 130fc8
                                    __VA_ARGS__)
Packit 130fc8
#   define DBG_EXC(format, ...) do {DBG(format, __VA_ARGS__); \
Packit 130fc8
                                    _dbus_py_dbg_exc();} while (0)
Packit 130fc8
#   define DBG_DUMP_MESSAGE(x) _dbus_py_dbg_dump_message(x)
Packit 130fc8
#   define DBG_WHEREAMI _dbus_py_whereami()
Packit 130fc8
Packit 130fc8
#else /* !defined(USING_DBG) */
Packit 130fc8
Packit 130fc8
#   define TRACE(self) do {} while (0)
Packit 130fc8
#   define DBG(format, ...) do {} while (0)
Packit 130fc8
#   define DBG_EXC(format, ...) do {} while (0)
Packit 130fc8
#   define DBG_DUMP_MESSAGE(x) do {} while (0)
Packit 130fc8
#   define DBG_WHEREAMI do {} while (0)
Packit 130fc8
Packit 130fc8
#endif /* !defined(USING_DBG) */
Packit 130fc8
Packit 130fc8
/* General-purpose Python glue */
Packit 130fc8
Packit 130fc8
#define DEFERRED_ADDRESS(ADDR) 0
Packit 130fc8
Packit 130fc8
#endif