1 /* Python interface to values.
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/>. */
21 #include "gdb_assert.h"
24 #include "exceptions.h"
29 /* List of all values which are currently exposed to Python. It is
30 maintained so that when an objfile is discarded, preserve_values
31 can copy the values' types if needed. This is declared
32 unconditionally to reduce the number of uses of HAVE_PYTHON in the
34 /* This variable is unnecessarily initialized to NULL in order to
35 work around a linker bug on MacOS. */
36 struct value
*values_in_python
= NULL
;
40 #include "python-internal.h"
42 /* Even though Python scalar types directly map to host types, we use
43 target types here to remain consistent with the the values system in
44 GDB (which uses target arithmetic). */
46 /* Python's integer type corresponds to C's long type. */
47 #define builtin_type_pyint builtin_type (python_gdbarch)->builtin_long
49 /* Python's float type corresponds to C's double type. */
50 #define builtin_type_pyfloat builtin_type (python_gdbarch)->builtin_double
52 /* Python's long type corresponds to C's long long type. */
53 #define builtin_type_pylong builtin_type (python_gdbarch)->builtin_long_long
55 #define builtin_type_pybool \
56 language_bool_type (python_language, python_gdbarch)
58 #define builtin_type_pychar \
59 language_string_char_type (python_language, python_gdbarch)
68 /* Called by the Python interpreter when deallocating a value object. */
70 valpy_dealloc (PyObject
*obj
)
72 value_object
*self
= (value_object
*) obj
;
74 value_remove_from_list (&values_in_python
, self
->value
);
76 value_free (self
->value
);
79 /* Use braces to appease gcc warning. *sigh* */
81 Py_DECREF (self
->address
);
86 Py_DECREF (self
->type
);
89 self
->ob_type
->tp_free (self
);
92 /* Called when a new gdb.Value object needs to be allocated. */
94 valpy_new (PyTypeObject
*subtype
, PyObject
*args
, PyObject
*keywords
)
96 struct value
*value
= NULL
; /* Initialize to appease gcc warning. */
97 value_object
*value_obj
;
99 if (PyTuple_Size (args
) != 1)
101 PyErr_SetString (PyExc_TypeError
, _("Value object creation takes only "
106 value_obj
= (value_object
*) subtype
->tp_alloc (subtype
, 1);
107 if (value_obj
== NULL
)
109 PyErr_SetString (PyExc_MemoryError
, _("Could not allocate memory to "
110 "create Value object."));
114 value
= convert_value_from_python (PyTuple_GetItem (args
, 0));
117 subtype
->tp_free (value_obj
);
121 value_obj
->value
= value
;
122 value_obj
->address
= NULL
;
123 value_obj
->type
= NULL
;
124 release_value (value
);
125 value_prepend_to_list (&values_in_python
, value
);
127 return (PyObject
*) value_obj
;
130 /* Given a value of a pointer type, apply the C unary * operator to it. */
132 valpy_dereference (PyObject
*self
, PyObject
*args
)
134 struct value
*res_val
= NULL
; /* Initialize to appease gcc warning. */
135 volatile struct gdb_exception except
;
137 TRY_CATCH (except
, RETURN_MASK_ALL
)
139 res_val
= value_ind (((value_object
*) self
)->value
);
141 GDB_PY_HANDLE_EXCEPTION (except
);
143 return value_to_value_object (res_val
);
146 /* Return "&value". */
148 valpy_get_address (PyObject
*self
, void *closure
)
150 struct value
*res_val
= NULL
; /* Initialize to appease gcc warning. */
151 value_object
*val_obj
= (value_object
*) self
;
152 volatile struct gdb_exception except
;
154 if (!val_obj
->address
)
156 TRY_CATCH (except
, RETURN_MASK_ALL
)
158 res_val
= value_addr (val_obj
->value
);
160 if (except
.reason
< 0)
162 val_obj
->address
= Py_None
;
166 val_obj
->address
= value_to_value_object (res_val
);
169 Py_INCREF (val_obj
->address
);
171 return val_obj
->address
;
174 /* Return type of the value. */
176 valpy_get_type (PyObject
*self
, void *closure
)
178 value_object
*obj
= (value_object
*) self
;
181 obj
->type
= type_to_type_object (value_type (obj
->value
));
185 Py_INCREF (obj
->type
);
188 Py_INCREF (obj
->type
);
192 /* Implementation of gdb.Value.string ([encoding] [, errors]) -> string
193 Return Unicode string with value contents. If ENCODING is not given,
194 the string is assumed to be encoded in the target's charset. */
196 valpy_string (PyObject
*self
, PyObject
*args
, PyObject
*kw
)
200 struct value
*value
= ((value_object
*) self
)->value
;
201 volatile struct gdb_exception except
;
203 const char *encoding
= NULL
;
204 const char *errors
= NULL
;
205 const char *user_encoding
= NULL
;
206 const char *la_encoding
= NULL
;
207 static char *keywords
[] = { "encoding", "errors" };
209 if (!PyArg_ParseTupleAndKeywords (args
, kw
, "|ss", keywords
,
210 &user_encoding
, &errors
))
213 TRY_CATCH (except
, RETURN_MASK_ALL
)
215 LA_GET_STRING (value
, &buffer
, &length
, &la_encoding
);
217 GDB_PY_HANDLE_EXCEPTION (except
);
219 encoding
= (user_encoding
&& *user_encoding
) ? user_encoding
: la_encoding
;
220 unicode
= PyUnicode_Decode (buffer
, length
, encoding
, errors
);
226 /* Cast a value to a given type. */
228 valpy_cast (PyObject
*self
, PyObject
*args
)
232 struct value
*res_val
= NULL
; /* Initialize to appease gcc warning. */
233 volatile struct gdb_exception except
;
235 if (! PyArg_ParseTuple (args
, "O", &type_obj
))
238 type
= type_object_to_type (type_obj
);
241 PyErr_SetString (PyExc_RuntimeError
, "argument must be a Type");
245 TRY_CATCH (except
, RETURN_MASK_ALL
)
247 res_val
= value_cast (type
, ((value_object
*) self
)->value
);
249 GDB_PY_HANDLE_EXCEPTION (except
);
251 return value_to_value_object (res_val
);
255 valpy_length (PyObject
*self
)
257 /* We don't support getting the number of elements in a struct / class. */
258 PyErr_SetString (PyExc_NotImplementedError
,
259 "Invalid operation on gdb.Value.");
263 /* Given string name of an element inside structure, return its value
266 valpy_getitem (PyObject
*self
, PyObject
*key
)
268 value_object
*self_value
= (value_object
*) self
;
270 struct value
*idx
= NULL
;
271 struct value
*res_val
= NULL
; /* Initialize to appease gcc warning. */
272 volatile struct gdb_exception except
;
274 if (gdbpy_is_string (key
))
276 field
= python_string_to_host_string (key
);
281 TRY_CATCH (except
, RETURN_MASK_ALL
)
283 struct value
*tmp
= self_value
->value
;
286 res_val
= value_struct_elt (&tmp
, NULL
, field
, 0, NULL
);
289 /* Assume we are attempting an array access, and let the
290 value code throw an exception if the index has an invalid
292 struct value
*idx
= convert_value_from_python (key
);
296 res_val
= value_subscript (tmp
, value_as_long (idx
));
301 GDB_PY_HANDLE_EXCEPTION (except
);
303 return value_to_value_object (res_val
);
307 valpy_setitem (PyObject
*self
, PyObject
*key
, PyObject
*value
)
309 PyErr_Format (PyExc_NotImplementedError
,
310 _("Setting of struct elements is not currently supported."));
314 /* Called by the Python interpreter to obtain string representation
317 valpy_str (PyObject
*self
)
322 struct cleanup
*old_chain
;
324 struct value_print_options opts
;
325 volatile struct gdb_exception except
;
327 get_user_print_options (&opts
);
330 stb
= mem_fileopen ();
331 old_chain
= make_cleanup_ui_file_delete (stb
);
333 TRY_CATCH (except
, RETURN_MASK_ALL
)
335 common_val_print (((value_object
*) self
)->value
, stb
, 0,
336 &opts
, python_language
);
337 s
= ui_file_xstrdup (stb
, &dummy
);
339 GDB_PY_HANDLE_EXCEPTION (except
);
341 do_cleanups (old_chain
);
343 result
= PyUnicode_Decode (s
, strlen (s
), host_charset (), NULL
);
349 /* Implements gdb.Value.is_optimized_out. */
351 valpy_get_is_optimized_out (PyObject
*self
, void *closure
)
353 struct value
*value
= ((value_object
*) self
)->value
;
355 if (value_optimized_out (value
))
376 /* If TYPE is a reference, return the target; otherwise return TYPE. */
377 #define STRIP_REFERENCE(TYPE) \
378 ((TYPE_CODE (TYPE) == TYPE_CODE_REF) ? (TYPE_TARGET_TYPE (TYPE)) : (TYPE))
380 /* Returns a value object which is the result of applying the operation
381 specified by OPCODE to the given arguments. */
383 valpy_binop (enum valpy_opcode opcode
, PyObject
*self
, PyObject
*other
)
385 struct value
*res_val
= NULL
; /* Initialize to appease gcc warning. */
386 volatile struct gdb_exception except
;
388 TRY_CATCH (except
, RETURN_MASK_ALL
)
390 struct value
*arg1
, *arg2
;
392 /* If the gdb.Value object is the second operand, then it will be passed
393 to us as the OTHER argument, and SELF will be an entirely different
394 kind of object, altogether. Because of this, we can't assume self is
395 a gdb.Value object and need to convert it from python as well. */
396 arg1
= convert_value_from_python (self
);
400 arg2
= convert_value_from_python (other
);
408 struct type
*ltype
= value_type (arg1
);
409 struct type
*rtype
= value_type (arg2
);
411 CHECK_TYPEDEF (ltype
);
412 ltype
= STRIP_REFERENCE (ltype
);
413 CHECK_TYPEDEF (rtype
);
414 rtype
= STRIP_REFERENCE (rtype
);
416 if (TYPE_CODE (ltype
) == TYPE_CODE_PTR
417 && is_integral_type (rtype
))
418 res_val
= value_ptradd (arg1
, value_as_long (arg2
));
419 else if (TYPE_CODE (rtype
) == TYPE_CODE_PTR
420 && is_integral_type (ltype
))
421 res_val
= value_ptradd (arg2
, value_as_long (arg1
));
423 res_val
= value_binop (arg1
, arg2
, BINOP_ADD
);
428 struct type
*ltype
= value_type (arg1
);
429 struct type
*rtype
= value_type (arg2
);
431 CHECK_TYPEDEF (ltype
);
432 ltype
= STRIP_REFERENCE (ltype
);
433 CHECK_TYPEDEF (rtype
);
434 rtype
= STRIP_REFERENCE (rtype
);
436 if (TYPE_CODE (ltype
) == TYPE_CODE_PTR
437 && TYPE_CODE (rtype
) == TYPE_CODE_PTR
)
438 /* A ptrdiff_t for the target would be preferable here. */
439 res_val
= value_from_longest (builtin_type_pyint
,
440 value_ptrdiff (arg1
, arg2
));
441 else if (TYPE_CODE (ltype
) == TYPE_CODE_PTR
442 && is_integral_type (rtype
))
443 res_val
= value_ptradd (arg1
, - value_as_long (arg2
));
445 res_val
= value_binop (arg1
, arg2
, BINOP_SUB
);
449 res_val
= value_binop (arg1
, arg2
, BINOP_MUL
);
452 res_val
= value_binop (arg1
, arg2
, BINOP_DIV
);
455 res_val
= value_binop (arg1
, arg2
, BINOP_REM
);
458 res_val
= value_binop (arg1
, arg2
, BINOP_EXP
);
461 res_val
= value_binop (arg1
, arg2
, BINOP_LSH
);
464 res_val
= value_binop (arg1
, arg2
, BINOP_RSH
);
467 res_val
= value_binop (arg1
, arg2
, BINOP_BITWISE_AND
);
470 res_val
= value_binop (arg1
, arg2
, BINOP_BITWISE_IOR
);
473 res_val
= value_binop (arg1
, arg2
, BINOP_BITWISE_XOR
);
477 GDB_PY_HANDLE_EXCEPTION (except
);
479 return res_val
? value_to_value_object (res_val
) : NULL
;
483 valpy_add (PyObject
*self
, PyObject
*other
)
485 return valpy_binop (VALPY_ADD
, self
, other
);
489 valpy_subtract (PyObject
*self
, PyObject
*other
)
491 return valpy_binop (VALPY_SUB
, self
, other
);
495 valpy_multiply (PyObject
*self
, PyObject
*other
)
497 return valpy_binop (VALPY_MUL
, self
, other
);
501 valpy_divide (PyObject
*self
, PyObject
*other
)
503 return valpy_binop (VALPY_DIV
, self
, other
);
507 valpy_remainder (PyObject
*self
, PyObject
*other
)
509 return valpy_binop (VALPY_REM
, self
, other
);
513 valpy_power (PyObject
*self
, PyObject
*other
, PyObject
*unused
)
515 /* We don't support the ternary form of pow. I don't know how to express
516 that, so let's just throw NotImplementedError to at least do something
518 if (unused
!= Py_None
)
520 PyErr_SetString (PyExc_NotImplementedError
,
521 "Invalid operation on gdb.Value.");
525 return valpy_binop (VALPY_POW
, self
, other
);
529 valpy_negative (PyObject
*self
)
531 struct value
*val
= NULL
;
532 volatile struct gdb_exception except
;
534 TRY_CATCH (except
, RETURN_MASK_ALL
)
536 val
= value_neg (((value_object
*) self
)->value
);
538 GDB_PY_HANDLE_EXCEPTION (except
);
540 return value_to_value_object (val
);
544 valpy_positive (PyObject
*self
)
546 struct value
*copy
= value_copy (((value_object
*) self
)->value
);
548 return value_to_value_object (copy
);
552 valpy_absolute (PyObject
*self
)
554 struct value
*value
= ((value_object
*) self
)->value
;
555 if (value_less (value
, value_zero (value_type (value
), not_lval
)))
556 return valpy_negative (self
);
558 return valpy_positive (self
);
561 /* Implements boolean evaluation of gdb.Value. */
563 valpy_nonzero (PyObject
*self
)
565 value_object
*self_value
= (value_object
*) self
;
568 type
= check_typedef (value_type (self_value
->value
));
570 if (is_integral_type (type
) || TYPE_CODE (type
) == TYPE_CODE_PTR
)
571 return !!value_as_long (self_value
->value
);
572 else if (TYPE_CODE (type
) == TYPE_CODE_FLT
)
573 return value_as_double (self_value
->value
) != 0;
574 else if (TYPE_CODE (type
) == TYPE_CODE_DECFLOAT
)
575 return !decimal_is_zero (value_contents (self_value
->value
),
577 gdbarch_byte_order (get_type_arch (type
)));
580 PyErr_SetString (PyExc_TypeError
, _("Attempted truth testing on invalid "
586 /* Implements ~ for value objects. */
588 valpy_invert (PyObject
*self
)
590 struct value
*val
= NULL
;
591 volatile struct gdb_exception except
;
593 TRY_CATCH (except
, RETURN_MASK_ALL
)
595 val
= value_complement (((value_object
*) self
)->value
);
597 GDB_PY_HANDLE_EXCEPTION (except
);
599 return value_to_value_object (val
);
602 /* Implements left shift for value objects. */
604 valpy_lsh (PyObject
*self
, PyObject
*other
)
606 return valpy_binop (VALPY_LSH
, self
, other
);
609 /* Implements right shift for value objects. */
611 valpy_rsh (PyObject
*self
, PyObject
*other
)
613 return valpy_binop (VALPY_RSH
, self
, other
);
616 /* Implements bitwise and for value objects. */
618 valpy_and (PyObject
*self
, PyObject
*other
)
620 return valpy_binop (VALPY_BITAND
, self
, other
);
623 /* Implements bitwise or for value objects. */
625 valpy_or (PyObject
*self
, PyObject
*other
)
627 return valpy_binop (VALPY_BITOR
, self
, other
);
630 /* Implements bitwise xor for value objects. */
632 valpy_xor (PyObject
*self
, PyObject
*other
)
634 return valpy_binop (VALPY_BITXOR
, self
, other
);
637 /* Implements comparison operations for value objects. */
639 valpy_richcompare (PyObject
*self
, PyObject
*other
, int op
)
642 struct value
*value_other
;
643 volatile struct gdb_exception except
;
645 if (other
== Py_None
)
646 /* Comparing with None is special. From what I can tell, in Python
647 None is smaller than anything else. */
659 PyErr_SetString (PyExc_NotImplementedError
,
660 "Invalid operation on gdb.Value.");
664 TRY_CATCH (except
, RETURN_MASK_ALL
)
666 value_other
= convert_value_from_python (other
);
667 if (value_other
== NULL
)
672 result
= value_less (((value_object
*) self
)->value
, value_other
);
675 result
= value_less (((value_object
*) self
)->value
, value_other
)
676 || value_equal (((value_object
*) self
)->value
, value_other
);
679 result
= value_equal (((value_object
*) self
)->value
, value_other
);
682 result
= !value_equal (((value_object
*) self
)->value
, value_other
);
685 result
= value_less (value_other
, ((value_object
*) self
)->value
);
688 result
= value_less (value_other
, ((value_object
*) self
)->value
)
689 || value_equal (((value_object
*) self
)->value
, value_other
);
693 PyErr_SetString (PyExc_NotImplementedError
,
694 "Invalid operation on gdb.Value.");
698 GDB_PY_HANDLE_EXCEPTION (except
);
706 /* Helper function to determine if a type is "int-like". */
708 is_intlike (struct type
*type
, int ptr_ok
)
710 CHECK_TYPEDEF (type
);
711 return (TYPE_CODE (type
) == TYPE_CODE_INT
712 || TYPE_CODE (type
) == TYPE_CODE_ENUM
713 || TYPE_CODE (type
) == TYPE_CODE_BOOL
714 || TYPE_CODE (type
) == TYPE_CODE_CHAR
715 || (ptr_ok
&& TYPE_CODE (type
) == TYPE_CODE_PTR
));
718 /* Implements conversion to int. */
720 valpy_int (PyObject
*self
)
722 struct value
*value
= ((value_object
*) self
)->value
;
723 struct type
*type
= value_type (value
);
725 volatile struct gdb_exception except
;
727 CHECK_TYPEDEF (type
);
728 if (!is_intlike (type
, 0))
730 PyErr_SetString (PyExc_RuntimeError
, "cannot convert value to int");
734 TRY_CATCH (except
, RETURN_MASK_ALL
)
736 l
= value_as_long (value
);
738 GDB_PY_HANDLE_EXCEPTION (except
);
740 return PyInt_FromLong (l
);
743 /* Implements conversion to long. */
745 valpy_long (PyObject
*self
)
747 struct value
*value
= ((value_object
*) self
)->value
;
748 struct type
*type
= value_type (value
);
750 volatile struct gdb_exception except
;
752 if (!is_intlike (type
, 1))
754 PyErr_SetString (PyExc_RuntimeError
, "cannot convert value to long");
758 TRY_CATCH (except
, RETURN_MASK_ALL
)
760 l
= value_as_long (value
);
762 GDB_PY_HANDLE_EXCEPTION (except
);
764 return PyLong_FromLong (l
);
767 /* Implements conversion to float. */
769 valpy_float (PyObject
*self
)
771 struct value
*value
= ((value_object
*) self
)->value
;
772 struct type
*type
= value_type (value
);
774 volatile struct gdb_exception except
;
776 CHECK_TYPEDEF (type
);
777 if (TYPE_CODE (type
) != TYPE_CODE_FLT
)
779 PyErr_SetString (PyExc_RuntimeError
, "cannot convert value to float");
783 TRY_CATCH (except
, RETURN_MASK_ALL
)
785 d
= value_as_double (value
);
787 GDB_PY_HANDLE_EXCEPTION (except
);
789 return PyFloat_FromDouble (d
);
792 /* Returns an object for a value which is released from the all_values chain,
793 so its lifetime is not bound to the execution of a command. */
795 value_to_value_object (struct value
*val
)
797 value_object
*val_obj
;
799 val_obj
= PyObject_New (value_object
, &value_object_type
);
802 val_obj
->value
= val
;
803 val_obj
->address
= NULL
;
804 val_obj
->type
= NULL
;
806 value_prepend_to_list (&values_in_python
, val
);
809 return (PyObject
*) val_obj
;
812 /* Returns value structure corresponding to the given value object. */
814 value_object_to_value (PyObject
*self
)
817 if (! PyObject_TypeCheck (self
, &value_object_type
))
819 real
= (value_object
*) self
;
823 /* Try to convert a Python value to a gdb value. If the value cannot
824 be converted, set a Python exception and return NULL. */
827 convert_value_from_python (PyObject
*obj
)
829 struct value
*value
= NULL
; /* -Wall */
830 PyObject
*target_str
, *unicode_str
;
832 volatile struct gdb_exception except
;
835 gdb_assert (obj
!= NULL
);
837 TRY_CATCH (except
, RETURN_MASK_ALL
)
839 if (PyBool_Check (obj
))
841 cmp
= PyObject_IsTrue (obj
);
843 value
= value_from_longest (builtin_type_pybool
, cmp
);
845 else if (PyInt_Check (obj
))
847 long l
= PyInt_AsLong (obj
);
849 if (! PyErr_Occurred ())
850 value
= value_from_longest (builtin_type_pyint
, l
);
852 else if (PyLong_Check (obj
))
854 LONGEST l
= PyLong_AsLongLong (obj
);
856 if (! PyErr_Occurred ())
857 value
= value_from_longest (builtin_type_pylong
, l
);
859 else if (PyFloat_Check (obj
))
861 double d
= PyFloat_AsDouble (obj
);
863 if (! PyErr_Occurred ())
864 value
= value_from_double (builtin_type_pyfloat
, d
);
866 else if (gdbpy_is_string (obj
))
870 s
= python_string_to_target_string (obj
);
873 old
= make_cleanup (xfree
, s
);
874 value
= value_cstring (s
, strlen (s
), builtin_type_pychar
);
878 else if (PyObject_TypeCheck (obj
, &value_object_type
))
879 value
= value_copy (((value_object
*) obj
)->value
);
881 PyErr_Format (PyExc_TypeError
, _("Could not convert Python object: %s"),
882 PyString_AsString (PyObject_Str (obj
)));
884 if (except
.reason
< 0)
886 PyErr_Format (except
.reason
== RETURN_QUIT
887 ? PyExc_KeyboardInterrupt
: PyExc_RuntimeError
,
888 "%s", except
.message
);
895 /* Returns value object in the ARGth position in GDB's history. */
897 gdbpy_history (PyObject
*self
, PyObject
*args
)
900 struct value
*res_val
= NULL
; /* Initialize to appease gcc warning. */
901 volatile struct gdb_exception except
;
903 if (!PyArg_ParseTuple (args
, "i", &i
))
906 TRY_CATCH (except
, RETURN_MASK_ALL
)
908 res_val
= access_value_history (i
);
910 GDB_PY_HANDLE_EXCEPTION (except
);
912 return value_to_value_object (res_val
);
916 gdbpy_initialize_values (void)
918 if (PyType_Ready (&value_object_type
) < 0)
921 Py_INCREF (&value_object_type
);
922 PyModule_AddObject (gdb_module
, "Value", (PyObject
*) &value_object_type
);
924 values_in_python
= NULL
;
929 static PyGetSetDef value_object_getset
[] = {
930 { "address", valpy_get_address
, NULL
, "The address of the value.",
932 { "is_optimized_out", valpy_get_is_optimized_out
, NULL
,
933 "Boolean telling whether the value is optimized out (i.e., not available).",
935 { "type", valpy_get_type
, NULL
, "Type of the value.", NULL
},
936 {NULL
} /* Sentinel */
939 static PyMethodDef value_object_methods
[] = {
940 { "cast", valpy_cast
, METH_VARARGS
, "Cast the value to the supplied type." },
941 { "dereference", valpy_dereference
, METH_NOARGS
, "Dereferences the value." },
942 { "string", (PyCFunction
) valpy_string
, METH_VARARGS
| METH_KEYWORDS
,
943 "string ([encoding] [, errors]) -> string\n\
944 Return Unicode string representation of the value." },
945 {NULL
} /* Sentinel */
948 static PyNumberMethods value_object_as_number
= {
954 NULL
, /* nb_divmod */
955 valpy_power
, /* nb_power */
956 valpy_negative
, /* nb_negative */
957 valpy_positive
, /* nb_positive */
958 valpy_absolute
, /* nb_absolute */
959 valpy_nonzero
, /* nb_nonzero */
960 valpy_invert
, /* nb_invert */
961 valpy_lsh
, /* nb_lshift */
962 valpy_rsh
, /* nb_rshift */
963 valpy_and
, /* nb_and */
964 valpy_xor
, /* nb_xor */
965 valpy_or
, /* nb_or */
966 NULL
, /* nb_coerce */
967 valpy_int
, /* nb_int */
968 valpy_long
, /* nb_long */
969 valpy_float
, /* nb_float */
974 static PyMappingMethods value_object_as_mapping
= {
980 PyTypeObject value_object_type
= {
981 PyObject_HEAD_INIT (NULL
)
983 "gdb.Value", /*tp_name*/
984 sizeof (value_object
), /*tp_basicsize*/
986 valpy_dealloc
, /*tp_dealloc*/
992 &value_object_as_number
, /*tp_as_number*/
993 0, /*tp_as_sequence*/
994 &value_object_as_mapping
, /*tp_as_mapping*/
997 valpy_str
, /*tp_str*/
1001 Py_TPFLAGS_DEFAULT
| Py_TPFLAGS_CHECKTYPES
, /*tp_flags*/
1002 "GDB value object", /* tp_doc */
1003 0, /* tp_traverse */
1005 valpy_richcompare
, /* tp_richcompare */
1006 0, /* tp_weaklistoffset */
1008 0, /* tp_iternext */
1009 value_object_methods
, /* tp_methods */
1011 value_object_getset
, /* tp_getset */
1014 0, /* tp_descr_get */
1015 0, /* tp_descr_set */
1016 0, /* tp_dictoffset */
1019 valpy_new
/* tp_new */
1022 #endif /* HAVE_PYTHON */