1 /* Gdb/Python header for private use by Python module.
3 Copyright (C) 2008, 2009 Free Software Foundation, Inc.
5 This file is part of GDB.
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 3 of the License, or
10 (at your option) any later version.
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with this program. If not, see <http://www.gnu.org/licenses/>. */
20 #ifndef GDB_PYTHON_INTERNAL_H
21 #define GDB_PYTHON_INTERNAL_H
23 /* Python 2.4 doesn't include stdint.h soon enough to get {u,}intptr_t
24 needed by pyport.h. */
27 /* /usr/include/features.h on linux systems will define _POSIX_C_SOURCE
28 if it sees _GNU_SOURCE (which config.h will define).
29 pyconfig.h defines _POSIX_C_SOURCE to a different value than
30 /usr/include/features.h does causing compilation to fail.
31 To work around this, undef _POSIX_C_SOURCE before we include Python.h. */
32 #undef _POSIX_C_SOURCE
35 #include "python2.4/Python.h"
36 /* Py_ssize_t is not defined until 2.5. */
37 typedef Py_intptr_t Py_ssize_t
;
38 #elif HAVE_LIBPYTHON2_5
39 #include "python2.5/Python.h"
40 #elif HAVE_LIBPYTHON2_6
41 #include "python2.6/Python.h"
43 #error "Unable to find usable Python.h"
46 /* If Python.h does not define WITH_THREAD, then the various
47 GIL-related functions will not be defined. However,
48 PyGILState_STATE will be. */
50 #define PyGILState_Ensure() ((PyGILState_STATE) 0)
51 #define PyGILState_Release(ARG) (ARG)
52 #define PyEval_InitThreads() 0
53 #define PyThreadState_Swap(ARG) (ARG)
54 #define PyEval_InitThreads() 0
55 #define PyEval_ReleaseLock() 0
60 extern PyObject
*gdb_module
;
61 extern PyTypeObject value_object_type
;
63 PyObject
*gdbpy_get_value_from_history (PyObject
*self
, PyObject
*args
);
65 PyObject
*value_to_value_object (struct value
*v
);
67 struct value
*convert_value_from_python (PyObject
*obj
);
69 void gdbpy_initialize_values (void);
71 struct cleanup
*make_cleanup_py_decref (PyObject
*py
);
72 struct cleanup
*make_cleanup_py_restore_gil (PyGILState_STATE
*state
);
74 /* Use this after a TRY_EXCEPT to throw the appropriate Python
76 #define GDB_PY_HANDLE_EXCEPTION(Exception) \
78 if (Exception.reason < 0) \
79 return PyErr_Format (Exception.reason == RETURN_QUIT \
80 ? PyExc_KeyboardInterrupt : PyExc_RuntimeError, \
81 "%s", Exception.message); \
85 void gdbpy_print_stack (void);
87 PyObject
*python_string_to_unicode (PyObject
*obj
);
88 char *unicode_to_target_string (PyObject
*unicode_str
);
89 char *python_string_to_target_string (PyObject
*obj
);
91 #endif /* GDB_PYTHON_INTERNAL_H */