OLD | NEW |
1 /* General utility routines for GDB/Python. | 1 /* General utility routines for GDB/Python. |
2 | 2 |
3 Copyright (C) 2008-2012 Free Software Foundation, Inc. | 3 Copyright (C) 2008-2012 Free Software Foundation, Inc. |
4 | 4 |
5 This file is part of GDB. | 5 This file is part of GDB. |
6 | 6 |
7 This program is free software; you can redistribute it and/or modify | 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 | 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 | 9 the Free Software Foundation; either version 3 of the License, or |
10 (at your option) any later version. | 10 (at your option) any later version. |
(...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
132 unicode_to_target_string (PyObject *unicode_str) | 132 unicode_to_target_string (PyObject *unicode_str) |
133 { | 133 { |
134 return unicode_to_encoded_string (unicode_str, | 134 return unicode_to_encoded_string (unicode_str, |
135 target_charset (python_gdbarch)); | 135 target_charset (python_gdbarch)); |
136 } | 136 } |
137 | 137 |
138 /* Returns a PyObject with the contents of the given unicode string | 138 /* Returns a PyObject with the contents of the given unicode string |
139 object converted to the target's charset. If an error occurs | 139 object converted to the target's charset. If an error occurs |
140 during the conversion, NULL will be returned and a python exception | 140 during the conversion, NULL will be returned and a python exception |
141 will be set. */ | 141 will be set. */ |
142 PyObject * | 142 static PyObject * |
143 unicode_to_target_python_string (PyObject *unicode_str) | 143 unicode_to_target_python_string (PyObject *unicode_str) |
144 { | 144 { |
145 return unicode_to_encoded_python_string (unicode_str, | 145 return unicode_to_encoded_python_string (unicode_str, |
146 target_charset (python_gdbarch)); | 146 target_charset (python_gdbarch)); |
147 } | 147 } |
148 | 148 |
149 /* Converts a python string (8-bit or unicode) to a target string in | 149 /* Converts a python string (8-bit or unicode) to a target string in |
150 the target's charset. Returns NULL on error, with a python exception set. | 150 the target's charset. Returns NULL on error, with a python exception set. |
151 | 151 |
152 The caller is responsible for xfree'ing the string. */ | 152 The caller is responsible for xfree'ing the string. */ |
(...skipping 213 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
366 | 366 |
367 /* Like PyInt_AsLong, but returns 0 on failure, 1 on success, and puts | 367 /* Like PyInt_AsLong, but returns 0 on failure, 1 on success, and puts |
368 the value into an out parameter. */ | 368 the value into an out parameter. */ |
369 | 369 |
370 int | 370 int |
371 gdb_py_int_as_long (PyObject *obj, long *result) | 371 gdb_py_int_as_long (PyObject *obj, long *result) |
372 { | 372 { |
373 *result = PyInt_AsLong (obj); | 373 *result = PyInt_AsLong (obj); |
374 return ! (*result == -1 && PyErr_Occurred ()); | 374 return ! (*result == -1 && PyErr_Occurred ()); |
375 } | 375 } |
| 376 |
| 377 |
| 378 |
| 379 /* Generic implementation of the __dict__ attribute for objects that |
| 380 have a dictionary. The CLOSURE argument should be the type object. |
| 381 This only handles positive values for tp_dictoffset. */ |
| 382 |
| 383 PyObject * |
| 384 gdb_py_generic_dict (PyObject *self, void *closure) |
| 385 { |
| 386 PyObject *result; |
| 387 PyTypeObject *type_obj = closure; |
| 388 char *raw_ptr; |
| 389 |
| 390 raw_ptr = (char *) self + type_obj->tp_dictoffset; |
| 391 result = * (PyObject **) raw_ptr; |
| 392 |
| 393 Py_INCREF (result); |
| 394 return result; |
| 395 } |
OLD | NEW |