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 (current_gdbarch)->builtin_long
49 /* Python's float type corresponds to C's double type. */
50 #define builtin_type_pyfloat builtin_type (current_gdbarch)->builtin_double
52 /* Python's long type corresponds to C's long long type. */
53 #define builtin_type_pylong builtin_type (current_gdbarch)->builtin_long_long
55 #define builtin_type_pybool \
56 language_bool_type (current_language, current_gdbarch)
65 /* Called by the Python interpreter when deallocating a value object. */
67 valpy_dealloc (PyObject
*obj
)
69 value_object
*self
= (value_object
*) obj
;
71 value_remove_from_list (&values_in_python
, self
->value
);
73 value_free (self
->value
);
76 /* Use braces to appease gcc warning. *sigh* */
78 Py_DECREF (self
->address
);
83 Py_DECREF (self
->type
);
86 self
->ob_type
->tp_free (self
);
89 /* Called when a new gdb.Value object needs to be allocated. */
91 valpy_new (PyTypeObject
*subtype
, PyObject
*args
, PyObject
*keywords
)
93 struct value
*value
= NULL
; /* Initialize to appease gcc warning. */
94 value_object
*value_obj
;
96 if (PyTuple_Size (args
) != 1)
98 PyErr_SetString (PyExc_TypeError
, _("Value object creation takes only "
103 value_obj
= (value_object
*) subtype
->tp_alloc (subtype
, 1);
104 if (value_obj
== NULL
)
106 PyErr_SetString (PyExc_MemoryError
, _("Could not allocate memory to "
107 "create Value object."));
111 value
= convert_value_from_python (PyTuple_GetItem (args
, 0));
114 subtype
->tp_free (value_obj
);
118 value_obj
->value
= value
;
119 value_obj
->address
= NULL
;
120 value_obj
->type
= NULL
;
121 release_value (value
);
122 value_prepend_to_list (&values_in_python
, value
);
124 return (PyObject
*) value_obj
;
127 /* Given a value of a pointer type, apply the C unary * operator to it. */
129 valpy_dereference (PyObject
*self
, PyObject
*args
)
131 struct value
*res_val
= NULL
; /* Initialize to appease gcc warning. */
132 volatile struct gdb_exception except
;
134 TRY_CATCH (except
, RETURN_MASK_ALL
)
136 res_val
= value_ind (((value_object
*) self
)->value
);
138 GDB_PY_HANDLE_EXCEPTION (except
);
140 return value_to_value_object (res_val
);
143 /* Return "&value". */
145 valpy_get_address (PyObject
*self
, void *closure
)
147 struct value
*res_val
= NULL
; /* Initialize to appease gcc warning. */
148 value_object
*val_obj
= (value_object
*) self
;
149 volatile struct gdb_exception except
;
151 if (!val_obj
->address
)
153 TRY_CATCH (except
, RETURN_MASK_ALL
)
155 res_val
= value_addr (val_obj
->value
);
157 if (except
.reason
< 0)
159 val_obj
->address
= Py_None
;
163 val_obj
->address
= value_to_value_object (res_val
);
166 Py_INCREF (val_obj
->address
);
168 return val_obj
->address
;
171 /* Return type of the value. */
173 valpy_get_type (PyObject
*self
, void *closure
)
175 value_object
*obj
= (value_object
*) self
;
178 obj
->type
= type_to_type_object (value_type (obj
->value
));
182 Py_INCREF (obj
->type
);
185 Py_INCREF (obj
->type
);
189 /* Implementation of gdb.Value.string ([encoding] [, errors]) -> string
190 Return Unicode string with value contents. If ENCODING is not given,
191 the string is assumed to be encoded in the target's charset. */
193 valpy_string (PyObject
*self
, PyObject
*args
, PyObject
*kw
)
197 struct value
*value
= ((value_object
*) self
)->value
;
198 volatile struct gdb_exception except
;
200 const char *encoding
= NULL
;
201 const char *errors
= NULL
;
202 const char *user_encoding
= NULL
;
203 const char *la_encoding
= NULL
;
204 static char *keywords
[] = { "encoding", "errors" };
206 if (!PyArg_ParseTupleAndKeywords (args
, kw
, "|ss", keywords
,
207 &user_encoding
, &errors
))
210 TRY_CATCH (except
, RETURN_MASK_ALL
)
212 LA_GET_STRING (value
, &buffer
, &length
, &la_encoding
);
214 GDB_PY_HANDLE_EXCEPTION (except
);
216 encoding
= (user_encoding
&& *user_encoding
) ? user_encoding
: la_encoding
;
217 unicode
= PyUnicode_Decode (buffer
, length
, encoding
, errors
);
223 /* Cast a value to a given type. */
225 valpy_cast (PyObject
*self
, PyObject
*args
)
229 struct value
*res_val
= NULL
; /* Initialize to appease gcc warning. */
230 volatile struct gdb_exception except
;
232 if (! PyArg_ParseTuple (args
, "O", &type_obj
))
235 type
= type_object_to_type (type_obj
);
238 PyErr_SetString (PyExc_RuntimeError
, "argument must be a Type");
242 TRY_CATCH (except
, RETURN_MASK_ALL
)
244 res_val
= value_cast (type
, ((value_object
*) self
)->value
);
246 GDB_PY_HANDLE_EXCEPTION (except
);
248 return value_to_value_object (res_val
);
252 valpy_length (PyObject
*self
)
254 /* We don't support getting the number of elements in a struct / class. */
255 PyErr_SetString (PyExc_NotImplementedError
,
256 "Invalid operation on gdb.Value.");
260 /* Given string name of an element inside structure, return its value
263 valpy_getitem (PyObject
*self
, PyObject
*key
)
265 value_object
*self_value
= (value_object
*) self
;
267 struct value
*idx
= NULL
;
268 struct value
*res_val
= NULL
; /* Initialize to appease gcc warning. */
269 volatile struct gdb_exception except
;
271 if (gdbpy_is_string (key
))
273 field
= python_string_to_host_string (key
);
278 TRY_CATCH (except
, RETURN_MASK_ALL
)
280 struct value
*tmp
= self_value
->value
;
283 res_val
= value_struct_elt (&tmp
, NULL
, field
, 0, NULL
);
286 /* Assume we are attempting an array access, and let the
287 value code throw an exception if the index has an invalid
289 struct value
*idx
= convert_value_from_python (key
);
293 res_val
= value_subscript (tmp
, idx
);
298 GDB_PY_HANDLE_EXCEPTION (except
);
300 return value_to_value_object (res_val
);
304 valpy_setitem (PyObject
*self
, PyObject
*key
, PyObject
*value
)
306 PyErr_Format (PyExc_NotImplementedError
,
307 _("Setting of struct elements is not currently supported."));
311 /* Called by the Python interpreter to obtain string representation
314 valpy_str (PyObject
*self
)
319 struct cleanup
*old_chain
;
321 struct value_print_options opts
;
322 volatile struct gdb_exception except
;
324 get_user_print_options (&opts
);
327 stb
= mem_fileopen ();
328 old_chain
= make_cleanup_ui_file_delete (stb
);
330 TRY_CATCH (except
, RETURN_MASK_ALL
)
332 common_val_print (((value_object
*) self
)->value
, stb
, 0,
333 &opts
, current_language
);
334 s
= ui_file_xstrdup (stb
, &dummy
);
336 GDB_PY_HANDLE_EXCEPTION (except
);
338 do_cleanups (old_chain
);
340 result
= PyUnicode_Decode (s
, strlen (s
), host_charset (), NULL
);
346 /* Implements gdb.Value.is_optimized_out. */
348 valpy_get_is_optimized_out (PyObject
*self
, void *closure
)
350 struct value
*value
= ((value_object
*) self
)->value
;
352 if (value_optimized_out (value
))
373 /* If TYPE is a reference, return the target; otherwise return TYPE. */
374 #define STRIP_REFERENCE(TYPE) \
375 ((TYPE_CODE (TYPE) == TYPE_CODE_REF) ? (TYPE_TARGET_TYPE (TYPE)) : (TYPE))
377 /* Returns a value object which is the result of applying the operation
378 specified by OPCODE to the given arguments. */
380 valpy_binop (enum valpy_opcode opcode
, PyObject
*self
, PyObject
*other
)
382 struct value
*res_val
= NULL
; /* Initialize to appease gcc warning. */
383 volatile struct gdb_exception except
;
385 TRY_CATCH (except
, RETURN_MASK_ALL
)
387 struct value
*arg1
, *arg2
;
389 /* If the gdb.Value object is the second operand, then it will be passed
390 to us as the OTHER argument, and SELF will be an entirely different
391 kind of object, altogether. Because of this, we can't assume self is
392 a gdb.Value object and need to convert it from python as well. */
393 arg1
= convert_value_from_python (self
);
397 arg2
= convert_value_from_python (other
);
405 struct type
*ltype
= value_type (arg1
);
406 struct type
*rtype
= value_type (arg2
);
408 CHECK_TYPEDEF (ltype
);
409 ltype
= STRIP_REFERENCE (ltype
);
410 CHECK_TYPEDEF (rtype
);
411 rtype
= STRIP_REFERENCE (rtype
);
413 if (TYPE_CODE (ltype
) == TYPE_CODE_PTR
)
414 res_val
= value_ptradd (arg1
, arg2
);
415 else if (TYPE_CODE (rtype
) == TYPE_CODE_PTR
)
416 res_val
= value_ptradd (arg2
, arg1
);
418 res_val
= value_binop (arg1
, arg2
, BINOP_ADD
);
423 struct type
*ltype
= value_type (arg1
);
424 struct type
*rtype
= value_type (arg2
);
426 CHECK_TYPEDEF (ltype
);
427 ltype
= STRIP_REFERENCE (ltype
);
428 CHECK_TYPEDEF (rtype
);
429 rtype
= STRIP_REFERENCE (rtype
);
431 if (TYPE_CODE (ltype
) == TYPE_CODE_PTR
)
433 if (TYPE_CODE (rtype
) == TYPE_CODE_PTR
)
434 /* A ptrdiff_t for the target would be preferable
436 res_val
= value_from_longest (builtin_type_pyint
,
437 value_ptrdiff (arg1
, arg2
));
439 res_val
= value_ptrsub (arg1
, arg2
);
442 res_val
= value_binop (arg1
, arg2
, BINOP_SUB
);
446 res_val
= value_binop (arg1
, arg2
, BINOP_MUL
);
449 res_val
= value_binop (arg1
, arg2
, BINOP_DIV
);
452 res_val
= value_binop (arg1
, arg2
, BINOP_REM
);
455 res_val
= value_binop (arg1
, arg2
, BINOP_EXP
);
458 res_val
= value_binop (arg1
, arg2
, BINOP_LSH
);
461 res_val
= value_binop (arg1
, arg2
, BINOP_RSH
);
464 res_val
= value_binop (arg1
, arg2
, BINOP_BITWISE_AND
);
467 res_val
= value_binop (arg1
, arg2
, BINOP_BITWISE_IOR
);
470 res_val
= value_binop (arg1
, arg2
, BINOP_BITWISE_XOR
);
474 GDB_PY_HANDLE_EXCEPTION (except
);
476 return res_val
? value_to_value_object (res_val
) : NULL
;
480 valpy_add (PyObject
*self
, PyObject
*other
)
482 return valpy_binop (VALPY_ADD
, self
, other
);
486 valpy_subtract (PyObject
*self
, PyObject
*other
)
488 return valpy_binop (VALPY_SUB
, self
, other
);
492 valpy_multiply (PyObject
*self
, PyObject
*other
)
494 return valpy_binop (VALPY_MUL
, self
, other
);
498 valpy_divide (PyObject
*self
, PyObject
*other
)
500 return valpy_binop (VALPY_DIV
, self
, other
);
504 valpy_remainder (PyObject
*self
, PyObject
*other
)
506 return valpy_binop (VALPY_REM
, self
, other
);
510 valpy_power (PyObject
*self
, PyObject
*other
, PyObject
*unused
)
512 /* We don't support the ternary form of pow. I don't know how to express
513 that, so let's just throw NotImplementedError to at least do something
515 if (unused
!= Py_None
)
517 PyErr_SetString (PyExc_NotImplementedError
,
518 "Invalid operation on gdb.Value.");
522 return valpy_binop (VALPY_POW
, self
, other
);
526 valpy_negative (PyObject
*self
)
528 struct value
*val
= NULL
;
529 volatile struct gdb_exception except
;
531 TRY_CATCH (except
, RETURN_MASK_ALL
)
533 val
= value_neg (((value_object
*) self
)->value
);
535 GDB_PY_HANDLE_EXCEPTION (except
);
537 return value_to_value_object (val
);
541 valpy_positive (PyObject
*self
)
543 struct value
*copy
= value_copy (((value_object
*) self
)->value
);
545 return value_to_value_object (copy
);
549 valpy_absolute (PyObject
*self
)
551 if (value_less (((value_object
*) self
)->value
,
552 value_from_longest (builtin_type_int8
, 0)))
553 return valpy_negative (self
);
555 return valpy_positive (self
);
558 /* Implements boolean evaluation of gdb.Value. */
560 valpy_nonzero (PyObject
*self
)
562 value_object
*self_value
= (value_object
*) self
;
565 type
= check_typedef (value_type (self_value
->value
));
567 if (is_integral_type (type
) || TYPE_CODE (type
) == TYPE_CODE_PTR
)
568 return !!value_as_long (self_value
->value
);
569 else if (TYPE_CODE (type
) == TYPE_CODE_FLT
)
570 return value_as_double (self_value
->value
) != 0;
571 else if (TYPE_CODE (type
) == TYPE_CODE_DECFLOAT
)
572 return !decimal_is_zero (value_contents (self_value
->value
),
576 PyErr_SetString (PyExc_TypeError
, _("Attempted truth testing on invalid "
582 /* Implements ~ for value objects. */
584 valpy_invert (PyObject
*self
)
586 struct value
*val
= NULL
;
587 volatile struct gdb_exception except
;
589 TRY_CATCH (except
, RETURN_MASK_ALL
)
591 val
= value_complement (((value_object
*) self
)->value
);
593 GDB_PY_HANDLE_EXCEPTION (except
);
595 return value_to_value_object (val
);
598 /* Implements left shift for value objects. */
600 valpy_lsh (PyObject
*self
, PyObject
*other
)
602 return valpy_binop (VALPY_LSH
, self
, other
);
605 /* Implements right shift for value objects. */
607 valpy_rsh (PyObject
*self
, PyObject
*other
)
609 return valpy_binop (VALPY_RSH
, self
, other
);
612 /* Implements bitwise and for value objects. */
614 valpy_and (PyObject
*self
, PyObject
*other
)
616 return valpy_binop (VALPY_BITAND
, self
, other
);
619 /* Implements bitwise or for value objects. */
621 valpy_or (PyObject
*self
, PyObject
*other
)
623 return valpy_binop (VALPY_BITOR
, self
, other
);
626 /* Implements bitwise xor for value objects. */
628 valpy_xor (PyObject
*self
, PyObject
*other
)
630 return valpy_binop (VALPY_BITXOR
, self
, other
);
633 /* Implements comparison operations for value objects. */
635 valpy_richcompare (PyObject
*self
, PyObject
*other
, int op
)
638 struct value
*value_other
;
639 volatile struct gdb_exception except
;
641 if (other
== Py_None
)
642 /* Comparing with None is special. From what I can tell, in Python
643 None is smaller than anything else. */
655 PyErr_SetString (PyExc_NotImplementedError
,
656 "Invalid operation on gdb.Value.");
660 TRY_CATCH (except
, RETURN_MASK_ALL
)
662 value_other
= convert_value_from_python (other
);
663 if (value_other
== NULL
)
668 result
= value_less (((value_object
*) self
)->value
, value_other
);
671 result
= value_less (((value_object
*) self
)->value
, value_other
)
672 || value_equal (((value_object
*) self
)->value
, value_other
);
675 result
= value_equal (((value_object
*) self
)->value
, value_other
);
678 result
= !value_equal (((value_object
*) self
)->value
, value_other
);
681 result
= value_less (value_other
, ((value_object
*) self
)->value
);
684 result
= value_less (value_other
, ((value_object
*) self
)->value
)
685 || value_equal (((value_object
*) self
)->value
, value_other
);
689 PyErr_SetString (PyExc_NotImplementedError
,
690 "Invalid operation on gdb.Value.");
694 GDB_PY_HANDLE_EXCEPTION (except
);
702 /* Helper function to determine if a type is "int-like". */
704 is_intlike (struct type
*type
, int ptr_ok
)
706 CHECK_TYPEDEF (type
);
707 return (TYPE_CODE (type
) == TYPE_CODE_INT
708 || TYPE_CODE (type
) == TYPE_CODE_ENUM
709 || TYPE_CODE (type
) == TYPE_CODE_BOOL
710 || TYPE_CODE (type
) == TYPE_CODE_CHAR
711 || (ptr_ok
&& TYPE_CODE (type
) == TYPE_CODE_PTR
));
714 /* Implements conversion to int. */
716 valpy_int (PyObject
*self
)
718 struct value
*value
= ((value_object
*) self
)->value
;
719 struct type
*type
= value_type (value
);
721 volatile struct gdb_exception except
;
723 CHECK_TYPEDEF (type
);
724 if (!is_intlike (type
, 0))
726 PyErr_SetString (PyExc_RuntimeError
, "cannot convert value to int");
730 TRY_CATCH (except
, RETURN_MASK_ALL
)
732 l
= value_as_long (value
);
734 GDB_PY_HANDLE_EXCEPTION (except
);
736 return PyInt_FromLong (l
);
739 /* Implements conversion to long. */
741 valpy_long (PyObject
*self
)
743 struct value
*value
= ((value_object
*) self
)->value
;
744 struct type
*type
= value_type (value
);
746 volatile struct gdb_exception except
;
748 if (!is_intlike (type
, 1))
750 PyErr_SetString (PyExc_RuntimeError
, "cannot convert value to long");
754 TRY_CATCH (except
, RETURN_MASK_ALL
)
756 l
= value_as_long (value
);
758 GDB_PY_HANDLE_EXCEPTION (except
);
760 return PyLong_FromLong (l
);
763 /* Implements conversion to float. */
765 valpy_float (PyObject
*self
)
767 struct value
*value
= ((value_object
*) self
)->value
;
768 struct type
*type
= value_type (value
);
770 volatile struct gdb_exception except
;
772 CHECK_TYPEDEF (type
);
773 if (TYPE_CODE (type
) != TYPE_CODE_FLT
)
775 PyErr_SetString (PyExc_RuntimeError
, "cannot convert value to float");
779 TRY_CATCH (except
, RETURN_MASK_ALL
)
781 d
= value_as_double (value
);
783 GDB_PY_HANDLE_EXCEPTION (except
);
785 return PyFloat_FromDouble (d
);
788 /* Returns an object for a value which is released from the all_values chain,
789 so its lifetime is not bound to the execution of a command. */
791 value_to_value_object (struct value
*val
)
793 value_object
*val_obj
;
795 val_obj
= PyObject_New (value_object
, &value_object_type
);
798 val_obj
->value
= val
;
799 val_obj
->address
= NULL
;
800 val_obj
->type
= NULL
;
802 value_prepend_to_list (&values_in_python
, val
);
805 return (PyObject
*) val_obj
;
808 /* Returns value structure corresponding to the given value object. */
810 value_object_to_value (PyObject
*self
)
813 if (! PyObject_TypeCheck (self
, &value_object_type
))
815 real
= (value_object
*) self
;
819 /* Try to convert a Python value to a gdb value. If the value cannot
820 be converted, set a Python exception and return NULL. */
823 convert_value_from_python (PyObject
*obj
)
825 struct value
*value
= NULL
; /* -Wall */
826 PyObject
*target_str
, *unicode_str
;
828 volatile struct gdb_exception except
;
831 gdb_assert (obj
!= NULL
);
833 TRY_CATCH (except
, RETURN_MASK_ALL
)
835 if (PyBool_Check (obj
))
837 cmp
= PyObject_IsTrue (obj
);
839 value
= value_from_longest (builtin_type_pybool
, cmp
);
841 else if (PyInt_Check (obj
))
843 long l
= PyInt_AsLong (obj
);
845 if (! PyErr_Occurred ())
846 value
= value_from_longest (builtin_type_pyint
, l
);
848 else if (PyLong_Check (obj
))
850 LONGEST l
= PyLong_AsLongLong (obj
);
852 if (! PyErr_Occurred ())
853 value
= value_from_longest (builtin_type_pylong
, l
);
855 else if (PyFloat_Check (obj
))
857 double d
= PyFloat_AsDouble (obj
);
859 if (! PyErr_Occurred ())
860 value
= value_from_double (builtin_type_pyfloat
, d
);
862 else if (gdbpy_is_string (obj
))
866 s
= python_string_to_target_string (obj
);
869 old
= make_cleanup (xfree
, s
);
870 value
= value_from_string (s
);
874 else if (PyObject_TypeCheck (obj
, &value_object_type
))
875 value
= value_copy (((value_object
*) obj
)->value
);
877 PyErr_Format (PyExc_TypeError
, _("Could not convert Python object: %s"),
878 PyString_AsString (PyObject_Str (obj
)));
880 if (except
.reason
< 0)
882 PyErr_Format (except
.reason
== RETURN_QUIT
883 ? PyExc_KeyboardInterrupt
: PyExc_RuntimeError
,
884 "%s", except
.message
);
891 /* Returns value object in the ARGth position in GDB's history. */
893 gdbpy_history (PyObject
*self
, PyObject
*args
)
896 struct value
*res_val
= NULL
; /* Initialize to appease gcc warning. */
897 volatile struct gdb_exception except
;
899 if (!PyArg_ParseTuple (args
, "i", &i
))
902 TRY_CATCH (except
, RETURN_MASK_ALL
)
904 res_val
= access_value_history (i
);
906 GDB_PY_HANDLE_EXCEPTION (except
);
908 return value_to_value_object (res_val
);
912 gdbpy_initialize_values (void)
914 if (PyType_Ready (&value_object_type
) < 0)
917 Py_INCREF (&value_object_type
);
918 PyModule_AddObject (gdb_module
, "Value", (PyObject
*) &value_object_type
);
920 values_in_python
= NULL
;
925 static PyGetSetDef value_object_getset
[] = {
926 { "address", valpy_get_address
, NULL
, "The address of the value.",
928 { "is_optimized_out", valpy_get_is_optimized_out
, NULL
,
929 "Boolean telling whether the value is optimized out (i.e., not available).",
931 { "type", valpy_get_type
, NULL
, "Type of the value.", NULL
},
932 {NULL
} /* Sentinel */
935 static PyMethodDef value_object_methods
[] = {
936 { "cast", valpy_cast
, METH_VARARGS
, "Cast the value to the supplied type." },
937 { "dereference", valpy_dereference
, METH_NOARGS
, "Dereferences the value." },
938 { "string", (PyCFunction
) valpy_string
, METH_VARARGS
| METH_KEYWORDS
,
939 "string ([encoding] [, errors]) -> string\n\
940 Return Unicode string representation of the value." },
941 {NULL
} /* Sentinel */
944 static PyNumberMethods value_object_as_number
= {
950 NULL
, /* nb_divmod */
951 valpy_power
, /* nb_power */
952 valpy_negative
, /* nb_negative */
953 valpy_positive
, /* nb_positive */
954 valpy_absolute
, /* nb_absolute */
955 valpy_nonzero
, /* nb_nonzero */
956 valpy_invert
, /* nb_invert */
957 valpy_lsh
, /* nb_lshift */
958 valpy_rsh
, /* nb_rshift */
959 valpy_and
, /* nb_and */
960 valpy_xor
, /* nb_xor */
961 valpy_or
, /* nb_or */
962 NULL
, /* nb_coerce */
963 valpy_int
, /* nb_int */
964 valpy_long
, /* nb_long */
965 valpy_float
, /* nb_float */
970 static PyMappingMethods value_object_as_mapping
= {
976 PyTypeObject value_object_type
= {
977 PyObject_HEAD_INIT (NULL
)
979 "gdb.Value", /*tp_name*/
980 sizeof (value_object
), /*tp_basicsize*/
982 valpy_dealloc
, /*tp_dealloc*/
988 &value_object_as_number
, /*tp_as_number*/
989 0, /*tp_as_sequence*/
990 &value_object_as_mapping
, /*tp_as_mapping*/
993 valpy_str
, /*tp_str*/
997 Py_TPFLAGS_DEFAULT
| Py_TPFLAGS_CHECKTYPES
, /*tp_flags*/
998 "GDB value object", /* tp_doc */
1001 valpy_richcompare
, /* tp_richcompare */
1002 0, /* tp_weaklistoffset */
1004 0, /* tp_iternext */
1005 value_object_methods
, /* tp_methods */
1007 value_object_getset
, /* tp_getset */
1010 0, /* tp_descr_get */
1011 0, /* tp_descr_set */
1012 0, /* tp_dictoffset */
1015 valpy_new
/* tp_new */
1018 #endif /* HAVE_PYTHON */