| File: | build/temp.linux-x86_64-3.8/../../test/dbus_py_test.c | 
| Warning: | line 102, column 18 PyObject ownership leak with reference count of 1  | 
Press '?' to see keyboard shortcuts
Keyboard shortcuts:
| 1 | /* Test fixtures for dbus-python, based on _dbus_glib_bindings. | |||
| 2 | * | |||
| 3 | * Copyright (C) 2007 Collabora Ltd. <http://www.collabora.co.uk/> | |||
| 4 | * | |||
| 5 | * SPDX-License-Identifier: MIT | |||
| 6 | * | |||
| 7 | * Permission is hereby granted, free of charge, to any person | |||
| 8 | * obtaining a copy of this software and associated documentation | |||
| 9 | * files (the "Software"), to deal in the Software without | |||
| 10 | * restriction, including without limitation the rights to use, copy, | |||
| 11 | * modify, merge, publish, distribute, sublicense, and/or sell copies | |||
| 12 | * of the Software, and to permit persons to whom the Software is | |||
| 13 | * furnished to do so, subject to the following conditions: | |||
| 14 | * | |||
| 15 | * The above copyright notice and this permission notice shall be | |||
| 16 | * included in all copies or substantial portions of the Software. | |||
| 17 | * | |||
| 18 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, | |||
| 19 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF | |||
| 20 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND | |||
| 21 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT | |||
| 22 | * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, | |||
| 23 | * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | |||
| 24 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER | |||
| 25 | * DEALINGS IN THE SOFTWARE. | |||
| 26 | */ | |||
| 27 | ||||
| 28 | #include <Python.h> | |||
| 29 | #include <dbus/dbus-python.h> | |||
| 30 | ||||
| 31 | PyMODINIT_FUNCPyObject* PyInit_dbus_py_test(void); | |||
| 32 | ||||
| 33 | #if defined(__GNUC__4) | |||
| 34 | # if __GNUC__4 >= 3 | |||
| 35 | # define UNUSED__attribute__((__unused__)) __attribute__((__unused__)) | |||
| 36 | # else | |||
| 37 | # define UNUSED__attribute__((__unused__)) /*nothing*/ | |||
| 38 | # endif | |||
| 39 | #else | |||
| 40 | # define UNUSED__attribute__((__unused__)) /*nothing*/ | |||
| 41 | #endif | |||
| 42 | ||||
| 43 | static dbus_bool_t | |||
| 44 | dbus_py_test_set_up_conn(DBusConnection *conn UNUSED__attribute__((__unused__)), void *data UNUSED__attribute__((__unused__))) | |||
| 45 | { | |||
| 46 | PyErr_SetString(PyExc_ValueError, "Dummy error from UnusableMainLoop"); | |||
| 47 | return 0; | |||
| 48 | } | |||
| 49 | ||||
| 50 | static dbus_bool_t | |||
| 51 | dbus_py_test_set_up_srv(DBusServer *srv UNUSED__attribute__((__unused__)), void *data UNUSED__attribute__((__unused__))) | |||
| 52 | { | |||
| 53 | PyErr_SetString(PyExc_ValueError, "Dummy error from UnusableMainLoop"); | |||
| 54 | return 0; | |||
| 55 | } | |||
| 56 | ||||
| 57 | static void | |||
| 58 | dbus_py_test_free(void *data UNUSED__attribute__((__unused__))) | |||
| 59 | { | |||
| 60 | } | |||
| 61 | ||||
| 62 | static PyObject * | |||
| 63 | dbus_test_native_mainloop(void) | |||
| 64 | { | |||
| 65 |     PyObject *loop = DBusPyNativeMainLoop_New4((PyObject *(*)(_dbus_py_conn_setup_func, _dbus_py_srv_setup_func , _dbus_py_free_func, void *))dbus_bindings_API[2])(dbus_py_test_set_up_conn,  | |||
| 66 | dbus_py_test_set_up_srv, | |||
| 67 | dbus_py_test_free, | |||
| 68 | NULL((void*)0)); | |||
| 69 | return loop; | |||
| 70 | } | |||
| 71 | ||||
| 72 | static PyObject * | |||
| 73 | UnusableMainLoop (PyObject *always_null UNUSED__attribute__((__unused__)), PyObject *args, PyObject *kwargs) | |||
| 74 | { | |||
| 75 | PyObject *mainloop, *function, *result; | |||
| 76 | int set_as_default = 0; | |||
| 77 | static char *argnames[] = {"set_as_default", NULL((void*)0)}; | |||
| 78 | ||||
| 79 | if (PyTuple_Size(args) != 0) { | |||
  | ||||
| 80 | PyErr_SetString(PyExc_TypeError, "UnusableMainLoop() takes no " | |||
| 81 | "positional arguments"); | |||
| 82 | return NULL((void*)0); | |||
| 83 | } | |||
| 84 | if (!PyArg_ParseTupleAndKeywords(args, kwargs, "|i", argnames, | |||
| 85 | &set_as_default)) { | |||
| 86 | return NULL((void*)0); | |||
| 87 | } | |||
| 88 | ||||
| 89 | mainloop = dbus_test_native_mainloop(); | |||
| 90 | if (mainloop && set_as_default) { | |||
| 91 | if (!_dbus_bindings_module) { | |||
| 92 | PyErr_SetString(PyExc_ImportError, "_dbus_bindings not imported"); | |||
| 93 |             Py_CLEAR(mainloop)do { PyObject *_py_tmp = ((PyObject*)(mainloop)); if (_py_tmp != ((void*)0)) { (mainloop) = ((void*)0); _Py_DECREF(((PyObject *)(_py_tmp))); } } while (0);  | |||
| 94 | return NULL((void*)0); | |||
| 95 | } | |||
| 96 | function = PyObject_GetAttrString(_dbus_bindings_module, | |||
| 97 | "set_default_main_loop"); | |||
| 98 | if (!function) { | |||
| 99 |             Py_CLEAR(mainloop)do { PyObject *_py_tmp = ((PyObject*)(mainloop)); if (_py_tmp != ((void*)0)) { (mainloop) = ((void*)0); _Py_DECREF(((PyObject *)(_py_tmp))); } } while (0);  | |||
| 100 | return NULL((void*)0); | |||
| 101 | } | |||
| 102 | result = PyObject_CallFunctionObjArgs(function, mainloop, NULL((void*)0)); | |||
  | ||||
| 103 |         Py_CLEAR(function)do { PyObject *_py_tmp = ((PyObject*)(function)); if (_py_tmp != ((void*)0)) { (function) = ((void*)0); _Py_DECREF(((PyObject *)(_py_tmp))); } } while (0);  | |||
| 104 | if (!result) { | |||
| 105 |             Py_CLEAR(mainloop)do { PyObject *_py_tmp = ((PyObject*)(mainloop)); if (_py_tmp != ((void*)0)) { (mainloop) = ((void*)0); _Py_DECREF(((PyObject *)(_py_tmp))); } } while (0);  | |||
| 106 | return NULL((void*)0); | |||
| 107 | } | |||
| 108 | } | |||
| 109 | return mainloop; | |||
| 110 | } | |||
| 111 | ||||
| 112 | static PyMethodDef module_functions[] = { | |||
| 113 | {"UnusableMainLoop", (PyCFunction) (void (*)(void))UnusableMainLoop, | |||
| 114 | METH_VARARGS0x0001|METH_KEYWORDS0x0002, "Return a main loop that fails to attach"}, | |||
| 115 | {NULL((void*)0), NULL((void*)0), 0, NULL((void*)0)} | |||
| 116 | }; | |||
| 117 | ||||
| 118 | PyMODINIT_FUNCPyObject* | |||
| 119 | PyInit_dbus_py_test(void) | |||
| 120 | { | |||
| 121 | static struct PyModuleDef moduledef = { | |||
| 122 | PyModuleDef_HEAD_INIT{ { 1, ((void*)0) }, ((void*)0), 0, ((void*)0), }, | |||
| 123 | "dbus_py_test", /* m_name */ | |||
| 124 | NULL((void*)0), /* m_doc */ | |||
| 125 | -1, /* m_size */ | |||
| 126 | module_functions, /* m_methods */ | |||
| 127 | NULL((void*)0), /* m_reload */ | |||
| 128 | NULL((void*)0), /* m_traverse */ | |||
| 129 | NULL((void*)0), /* m_clear */ | |||
| 130 | NULL((void*)0) /* m_free */ | |||
| 131 | }; | |||
| 132 | if (import_dbus_bindings("dbus_py_test") < 0) | |||
| 133 | return NULL((void*)0); | |||
| 134 | ||||
| 135 | return PyModule_Create(&moduledef)PyModule_Create2(&moduledef, 1013); | |||
| 136 | } | |||
| 137 | ||||
| 138 | /* vim:set ft=c cino< sw=4 sts=4 et: */ | 
| 1 | #ifndef PyObject_CallFunctionObjArgs | 
| 2 | struct _object; | 
| 3 | typedef struct _object PyObject; | 
| 4 | PyObject* clang_analyzer_PyObject_New_Reference(); | 
| 5 | PyObject* PyObject_CallFunctionObjArgs(PyObject *callable, ...) { | 
| 6 | return clang_analyzer_PyObject_New_Reference(); | 
| 7 | } | 
| 8 | #else | 
| 9 | #warning "API PyObject_CallFunctionObjArgs is defined as a macro." | 
| 10 | #endif |