Commit | Line | Data |
---|---|---|
d57a3c85 TJB |
1 | /* Gdb/Python header for private use by Python module. |
2 | ||
0fb0cc75 | 3 | Copyright (C) 2008, 2009 Free Software Foundation, Inc. |
d57a3c85 TJB |
4 | |
5 | This file is part of GDB. | |
6 | ||
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. | |
11 | ||
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. | |
16 | ||
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/>. */ | |
19 | ||
20 | #ifndef GDB_PYTHON_INTERNAL_H | |
21 | #define GDB_PYTHON_INTERNAL_H | |
22 | ||
23 | /* Python 2.4 doesn't include stdint.h soon enough to get {u,}intptr_t | |
24 | needed by pyport.h. */ | |
25 | #include <stdint.h> | |
26 | ||
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 | |
33 | ||
34 | #if HAVE_LIBPYTHON2_4 | |
35 | #include "python2.4/Python.h" | |
5171e6b3 TT |
36 | /* Py_ssize_t is not defined until 2.5. |
37 | Logical type for Py_ssize_t is Py_intptr_t, but that fails in 64-bit | |
38 | compilation due to several apparent mistakes in python2.4 API, so we | |
39 | use 'int' instead. */ | |
40 | typedef int Py_ssize_t; | |
d57a3c85 TJB |
41 | #elif HAVE_LIBPYTHON2_5 |
42 | #include "python2.5/Python.h" | |
43 | #elif HAVE_LIBPYTHON2_6 | |
44 | #include "python2.6/Python.h" | |
45 | #else | |
46 | #error "Unable to find usable Python.h" | |
47 | #endif | |
48 | ||
ca30a762 TT |
49 | /* If Python.h does not define WITH_THREAD, then the various |
50 | GIL-related functions will not be defined. However, | |
51 | PyGILState_STATE will be. */ | |
52 | #ifndef WITH_THREAD | |
53 | #define PyGILState_Ensure() ((PyGILState_STATE) 0) | |
54 | #define PyGILState_Release(ARG) (ARG) | |
55 | #define PyEval_InitThreads() 0 | |
56 | #define PyThreadState_Swap(ARG) (ARG) | |
57 | #define PyEval_InitThreads() 0 | |
f2f35b75 | 58 | #define PyEval_ReleaseLock() 0 |
ca30a762 TT |
59 | #endif |
60 | ||
a08702d6 | 61 | struct value; |
d57a3c85 TJB |
62 | |
63 | extern PyObject *gdb_module; | |
a08702d6 TJB |
64 | extern PyTypeObject value_object_type; |
65 | ||
08c637de | 66 | PyObject *gdbpy_history (PyObject *self, PyObject *args); |
a08702d6 TJB |
67 | |
68 | PyObject *value_to_value_object (struct value *v); | |
69 | ||
70 | struct value *convert_value_from_python (PyObject *obj); | |
71 | ||
72 | void gdbpy_initialize_values (void); | |
d8906c6f | 73 | void gdbpy_initialize_commands (void); |
bc3b79fd | 74 | void gdbpy_initialize_functions (void); |
d57a3c85 TJB |
75 | |
76 | struct cleanup *make_cleanup_py_decref (PyObject *py); | |
ca30a762 | 77 | struct cleanup *make_cleanup_py_restore_gil (PyGILState_STATE *state); |
d57a3c85 TJB |
78 | |
79 | /* Use this after a TRY_EXCEPT to throw the appropriate Python | |
80 | exception. */ | |
81 | #define GDB_PY_HANDLE_EXCEPTION(Exception) \ | |
82 | do { \ | |
83 | if (Exception.reason < 0) \ | |
84 | return PyErr_Format (Exception.reason == RETURN_QUIT \ | |
85 | ? PyExc_KeyboardInterrupt : PyExc_RuntimeError, \ | |
86 | "%s", Exception.message); \ | |
87 | } while (0) | |
88 | ||
89 | ||
90 | void gdbpy_print_stack (void); | |
91 | ||
92 | PyObject *python_string_to_unicode (PyObject *obj); | |
93 | char *unicode_to_target_string (PyObject *unicode_str); | |
94 | char *python_string_to_target_string (PyObject *obj); | |
08c637de | 95 | char *python_string_to_host_string (PyObject *obj); |
b6cb8e7d | 96 | PyObject *target_string_to_unicode (const gdb_byte *str, int length); |
08c637de | 97 | int gdbpy_is_string (PyObject *obj); |
d57a3c85 | 98 | |
d8906c6f TJB |
99 | extern PyObject *gdbpy_doc_cst; |
100 | ||
d57a3c85 | 101 | #endif /* GDB_PYTHON_INTERNAL_H */ |