diff --git a/CMakeLists.txt b/CMakeLists.txt new file mode 100644 index 0000000..4d17898 --- /dev/null +++ b/CMakeLists.txt @@ -0,0 +1,86 @@ +project(dbus_python CXX C) +cmake_minimum_required(VERSION 2.8) + +set(CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/cmake") + +set(PACKAGE "dbus-python") +set(PACKAGE_BUGREPORT "http://bugs.freedesktop.org/enter_bug.cgi?product=dbus&component=python") +set(PACKAGE_NAME "dbus-python") +set(PACKAGE_URL "") +set(PACKAGE_VERSION "1.1.0") +set(PACKAGE_STRING "${PACKAGE_NAME} ${PACKAGE_VERSION}") +set(PACKAGE_TARNAME "${PACKAGE_NAME}") + +include (CheckTypeSize) + +#DBUS +find_package(DBUS REQUIRED) +set(CMAKE_REQUIRED_INCLUDES ${DBUS_INCLUDES}) +set(CMAKE_EXTRA_INCLUDE_FILES dbus/dbus.h) +check_type_size(DBusBasicValue DBUSBASICVALUE) + +configure_file(${CMAKE_CURRENT_SOURCE_DIR}/config.h.cmake ${CMAKE_CURRENT_BINARY_DIR}/config.h) +include_directories(${CMAKE_CURRENT_BINARY_DIR}) + +#GLIB +find_package(GLIB REQUIRED) + +# Find Python executable +find_package(PythonInterp REQUIRED) +find_package(PythonLibs REQUIRED) + +if(NOT PYTHONLIBS_FOUND OR NOT PYTHON_EXECUTABLE) + message(SEND_ERROR "You need Python to build the dbus python bindings") +endif(NOT PYTHONLIBS_FOUND OR NOT PYTHON_EXECUTABLE) + +# The code below prints the Python extension for the current system +set(get_python_suffix "import imp ; print(list(filter(lambda s : s[1] == 'rb' and s[0][0] == '.', imp.get_suffixes()))[0][0])") + +find_file(stdint stdint.h) +if(NOT stdint) + message(SEND_ERROR "You need a C99 compliant stdint.h for windows, use e.g. http://msinttypes.googlecode.com/svn/trunk/stdint.h") +endif(NOT stdint) + +execute_process( + COMMAND ${PYTHON_EXECUTABLE} -c "${get_python_suffix}" + OUTPUT_VARIABLE _modsuffix +) +string(REPLACE "\n" "" _modsuffix ${_modsuffix}) +message(STATUS "Python module suffix is: ${_modsuffix}") + +# The code below returns the site-packages directory for the current system +set(get_site_package_dir "from distutils.sysconfig import get_python_lib; print(get_python_lib())") +execute_process( + COMMAND ${PYTHON_EXECUTABLE} -c "${get_site_package_dir}" + OUTPUT_VARIABLE site_pkg +) +string(REPLACE "\n" "" site_pkg ${site_pkg}) +message(STATUS "Python module path is: ${site_pkg}") + +include_directories(include/ ${PYTHON_INCLUDE_DIRS}) +include_directories(_dbus_bindings/) +file(GLOB dbus_binding_sources _dbus_bindings/*.c) +add_library(_dbus_bindings SHARED ${dbus_binding_sources}) +target_link_libraries(_dbus_bindings ${PYTHON_LIBRARIES} ${DBUS_LIBRARY}) + +include_directories(_dbus_glib_bindings/ ${GLIB_INCLUDE_DIR} ${GLIB_CONFIG_INCLUDE_DIR} ${DBUS_INCLUDES}) +file(GLOB dbus_glib_binding_sources _dbus_glib_bindings/*.c) +add_library(_dbus_glib_bindings SHARED ${dbus_glib_binding_sources}) +target_link_libraries(_dbus_glib_bindings ${PYTHON_LIBRARIES} ${DBUS_LIBRARY} ${DBUS_GLIB_LIBRARY} ${GLIB_LIBRARIES}) + +file(GLOB dbus_py_test_sources test/*.c) +add_library(dbus_py_test SHARED ${dbus_py_test_sources}) +target_link_libraries(dbus_py_test ${PYTHON_LIBRARIES} ${DBUS_LIBRARY}) + +set_target_properties(_dbus_bindings _dbus_glib_bindings dbus_py_test + PROPERTIES + PREFIX "" # There is no prefix even on UNIXes + SUFFIX "${_modsuffix}" # The extension got from Python libraries +) + +set(PYTHON ${PYTHON_EXECUTABLE}) +set(abs_top_srcdir ${CMAKE_CURRENT_SOURCE_DIR}) +set(abs_top_builddir ${CMAKE_CURRENT_BINARY_DIR}) + +configure_file(${CMAKE_CURRENT_SOURCE_DIR}/test/tmp-session-bus.conf.in ${CMAKE_CURRENT_BINARY_DIR}/test/tmp-session-bus.conf) +configure_file(${CMAKE_CURRENT_SOURCE_DIR}/test/TestSuitePythonService.service.in ${CMAKE_CURRENT_BINARY_DIR}/test/TestSuitePythonService.service) diff --git a/_dbus_bindings/dbus_bindings-internal.h b/_dbus_bindings/dbus_bindings-internal.h index 4b831e8..e8490d6 100644 --- a/_dbus_bindings/dbus_bindings-internal.h +++ b/_dbus_bindings/dbus_bindings-internal.h @@ -41,6 +41,10 @@ # define USING_DBG 1 #endif +#ifdef _MSC_VER +# define inline __inline +#endif + #define DEFINE_CHECK(type) \ static inline int type##_Check (PyObject *o) \ { \ diff --git a/_dbus_bindings/message-append.c b/_dbus_bindings/message-append.c index f4f843b..a8e1f3f 100644 --- a/_dbus_bindings/message-append.c +++ b/_dbus_bindings/message-append.c @@ -934,7 +934,7 @@ _message_iter_append_variant(DBusMessageIter *appender, PyObject *obj) dbus_signature_iter_init(&obj_sig_iter, obj_sig_str); { /* scope for variant_iters */ - DBusMessageIter variant_iters[variant_level]; + DBusMessageIter* variant_iters = malloc(sizeof(DBusMessageIter) * variant_level); long i; for (i = 0; i < variant_level; i++) { @@ -984,7 +984,7 @@ _message_iter_append_variant(DBusMessageIter *appender, PyObject *obj) goto out; } } - + free(variant_iters); } out: diff --git a/_dbus_bindings/server.c b/_dbus_bindings/server.c index cb489f6..0236cb6 100644 --- a/_dbus_bindings/server.c +++ b/_dbus_bindings/server.c @@ -99,7 +99,7 @@ DBusPyServer_set_auth_mechanisms(Server *self, /* scope for list */ { - const char *list[length + 1]; + char *list = malloc(sizeof(char) * (length + 1)); if (!(references = PyTuple_New(length))) goto error; @@ -131,6 +131,7 @@ DBusPyServer_set_auth_mechanisms(Server *self, Py_BEGIN_ALLOW_THREADS dbus_server_set_auth_mechanisms(self->server, list); Py_END_ALLOW_THREADS + free(list); } Py_CLEAR(fast_seq); diff --git a/cmake/FindDBUS.cmake b/cmake/FindDBUS.cmake new file mode 100644 index 0000000..eabb70b --- /dev/null +++ b/cmake/FindDBUS.cmake @@ -0,0 +1,32 @@ +FIND_PATH( DBUS_INCLUDE_DIR dbus/dbus.h PATHS ${CMAKE_INCLUDE_PATH}/dbus-1.0 /usr/include/dbus-1.0) +FIND_PATH( DBUS_INCLUDE_LIB_DIR dbus/dbus-arch-deps.h PATHS ${CMAKE_LIBRARY_PATH}/dbus-1.0/include /usr/lib/dbus-1.0/include /usr/lib64/dbus-1.0/include) +FIND_PATH( DBUS_GLIB_INCLUDE_DIR dbus/dbus-glib.h PATHS ${CMAKE_INCLUDE_PATH}) + +FIND_LIBRARY(DBUS_LIBRARY NAME dbus-1 PATHS /lib) +FIND_LIBRARY(DBUS_GLIB_LIBRARY NAME dbus-glib PATHS /lib) + +IF(NOT DBUS_GLIB_INCLUDE_DIR) + MESSAGE(ERROR "Could not find dbus/dbus-glib.h") +ENDIF(NOT DBUS_GLIB_INCLUDE_DIR) + +IF(NOT DBUS_GLIB_LIBRARY) + MESSAGE(ERROR "Could not find lib dbus-glib-1") +ENDIF(NOT DBUS_GLIB_LIBRARY) + +IF( DBUS_INCLUDE_DIR AND DBUS_INCLUDE_LIB_DIR AND DBUS_GLIB_INCLUDE_DIR AND DBUS_LIBRARY AND DBUS_GLIB_LIBRARY ) +SET( DBUS_FOUND TRUE ) +ENDIF( DBUS_INCLUDE_DIR AND DBUS_INCLUDE_LIB_DIR AND DBUS_GLIB_INCLUDE_DIR AND DBUS_LIBRARY AND DBUS_GLIB_LIBRARY ) + +IF( DBUS_INCLUDE_DIR AND DBUS_INCLUDE_LIB_DIR AND DBUS_GLIB_INCLUDE_DIR) +SET( DBUS_INCLUDES ${DBUS_INCLUDE_DIR} ${DBUS_INCLUDE_LIB_DIR} ${DBUS_GLIB_INCLUDE_DIR}) +ENDIF( DBUS_INCLUDE_DIR AND DBUS_INCLUDE_LIB_DIR AND DBUS_GLIB_INCLUDE_DIR) + +IF( DBUS_FOUND ) + MESSAGE( STATUS "Found dbus: ${DBUS_LIBRARY}" ) + ELSE( DBUS_FOUND ) + IF( DBUS_FIND_REQUIRED ) + MESSAGE( FATAL_ERROR "Could not find dbus" ) + ENDIF( DBUS_FIND_REQUIRED ) +ENDIF( DBUS_FOUND ) + + diff --git a/cmake/FindGLIB.cmake b/cmake/FindGLIB.cmake new file mode 100644 index 0000000..67cd1cb --- /dev/null +++ b/cmake/FindGLIB.cmake @@ -0,0 +1,45 @@ +find_package(PkgConfig) +if (PKG_CONFIG_FOUND) + pkg_check_modules(GLIB_PKG glib-2.0) +endif (PKG_CONFIG_FOUND) + +if (GLIB_PKG_FOUND) + find_path(GLIB_INCLUDE_DIR NAMES glib.h PATH_SUFFIXES glib-2.0 + PATHS + ${GLIB_PKG_INCLUDE_DIRS} + /usr/include/glib-2.0 + /usr/include + /usr/local/include + ) + find_path(GLIB_CONFIG_INCLUDE_DIR NAMES glibconfig.h PATHS ${GLIB_PKG_LIBDIR} PATH_SUFFIXES glib-2.0/include) + + find_library(GLIB_LIBRARIES NAMES glib-2.0 + PATHS + ${GLIB_PKG_LIBRARY_DIRS} + /usr/lib + /usr/local/lib + ) + +else (GLIB_PKG_FOUND) + # Find Glib even if pkg-config is not working (eg. cross compiling to Windows) + find_library(GLIB_LIBRARIES NAMES glib-2.0) + string (REGEX REPLACE "/[^/]*$" "" GLIB_LIBRARIES_DIR ${GLIB_LIBRARIES}) + + find_path(GLIB_INCLUDE_DIR NAMES glib.h PATH_SUFFIXES glib-2.0) + find_path(GLIB_CONFIG_INCLUDE_DIR NAMES glibconfig.h PATHS ${GLIB_LIBRARIES_DIR} PATH_SUFFIXES glib-2.0/include) + +endif (GLIB_PKG_FOUND) + +if (GLIB_INCLUDE_DIR AND GLIB_CONFIG_INCLUDE_DIR AND GLIB_LIBRARIES) + set(GLIB_INCLUDE_DIRS ${GLIB_INCLUDE_DIR} ${GLIB_CONFIG_INCLUDE_DIR}) +endif (GLIB_INCLUDE_DIR AND GLIB_CONFIG_INCLUDE_DIR AND GLIB_LIBRARIES) + +if(GLIB_INCLUDE_DIRS AND GLIB_LIBRARIES) + set(GLIB_FOUND TRUE CACHE INTERNAL "glib-2.0 found") + message(STATUS "Found glib-2.0: ${GLIB_INCLUDE_DIR}, ${GLIB_LIBRARIES}") +else(GLIB_INCLUDE_DIRS AND GLIB_LIBRARIES) + set(GLIB_FOUND FALSE CACHE INTERNAL "glib-2.0 found") + message(STATUS "glib-2.0 not found.") +endif(GLIB_INCLUDE_DIRS AND GLIB_LIBRARIES) + +mark_as_advanced(GLIB_INCLUDE_DIR GLIB_CONFIG_INCLUDE_DIR GLIB_INCLUDE_DIRS GLIB_LIBRARIES) diff --git a/config.h.cmake b/config.h.cmake new file mode 100644 index 0000000..ebb33c2 --- /dev/null +++ b/config.h.cmake @@ -0,0 +1,77 @@ +/* config.h.in. Generated from configure.ac by autoheader. */ + +/* dbus-python major version */ +#cmakedefine DBUS_PYTHON_MAJOR_VERSION + +/* dbus-python micro version */ +#cmakedefine DBUS_PYTHON_MICRO_VERSION + +/* dbus-python minor version */ +#cmakedefine DBUS_PYTHON_MINOR_VERSION + +/* Define to 1 if you have the header file. */ +#cmakedefine HAVE_DLFCN_H + +/* Define to 1 if you have the header file. */ +#cmakedefine HAVE_INTTYPES_H + +/* Define to 1 if you have the header file. */ +#cmakedefine HAVE_MEMORY_H + +/* Define to 1 if you have the header file. */ +#cmakedefine HAVE_STDINT_H + +/* Define to 1 if you have the header file. */ +#cmakedefine HAVE_STDLIB_H + +/* Define to 1 if you have the header file. */ +#cmakedefine HAVE_STRINGS_H + +/* Define to 1 if you have the header file. */ +#cmakedefine HAVE_STRING_H + +/* Define to 1 if you have the header file. */ +#cmakedefine HAVE_SYS_STAT_H + +/* Define to 1 if you have the header file. */ +#cmakedefine HAVE_SYS_TYPES_H + +/* Define to 1 if you have the header file. */ +#cmakedefine HAVE_UNISTD_H + +/* Define to the sub-directory in which libtool stores uninstalled libraries. + */ +#cmakedefine LT_OBJDIR + +/* Define to 1 if your C compiler doesn't accept -c and -o together. */ +#cmakedefine NO_MINUS_C_MINUS_O + +/* Name of package */ +#cmakedefine PACKAGE "@PACKAGE@" + +/* Define to the address where bug reports for this package should be sent. */ +#cmakedefine PACKAGE_BUGREPORT "@PACKAGE_BUGREPORT@" + +/* Define to the full name of this package. */ +#cmakedefine PACKAGE_NAME "@PACKAGE_NAME@" + +/* Define to the full name and version of this package. */ +#cmakedefine PACKAGE_STRING "@PACKAGE_STRING@" + +/* Define to the one symbol short name of this package. */ +#cmakedefine PACKAGE_TARNAME "@PACKAGE_TARNAME@" + +/* Define to the home page for this package. */ +#cmakedefine PACKAGE_URL "@PACKAGE_URL@" + +/* Define to the version of this package. */ +#cmakedefine PACKAGE_VERSION "@PACKAGE_VERSION@" + +/* Define to 1 if you have the ANSI C header files. */ +#cmakedefine STDC_HEADERS 1 + +/* Version number of package */ +#cmakedefine VERSION "@VERSION@" + +/* Do we have DBusBasicValue? */ +#cmakedefine HAVE_DBUSBASICVALUE diff --git a/test/run-test.sh b/test/run-test.sh index 79efaff..fdb7bc9 100755 --- a/test/run-test.sh +++ b/test/run-test.sh @@ -87,10 +87,12 @@ $PYTHON "$DBUS_TOP_SRCDIR"/test/test-unusable-main-loop.py || die "... failed" # die "example-signal-recipient failed!" echo "running cross-test (for better diagnostics use mjj29's dbus-test)" +$PYTHON "$DBUS_TOP_SRCDIR"/test/cross-test-server.py > "$DBUS_TOP_BUILDDIR"/test/cross-server.log& -${MAKE:-make} -s cross-test-server > "$DBUS_TOP_BUILDDIR"/test/cross-server.log& +#${MAKE:-make} -s cross-test-server > "$DBUS_TOP_BUILDDIR"/test/cross-server.log& sleep 1 -${MAKE:-make} -s cross-test-client > "$DBUS_TOP_BUILDDIR"/test/cross-client.log +#${MAKE:-make} -s cross-test-client > "$DBUS_TOP_BUILDDIR"/test/cross-client.log +$PYTHON "$DBUS_TOP_SRCDIR"/test/cross-test-client.py > "$DBUS_TOP_BUILDDIR"/test/cross-client.log if grep . "$DBUS_TOP_BUILDDIR"/test/cross-client.log >/dev/null; then : # OK