Remove more uses of explicit reference counting in Python
[deliverable/binutils-gdb.git] / gdb / python / py-value.c
CommitLineData
7843261b
TJB
1/* Python interface to values.
2
42a4f53d 3 Copyright (C) 2008-2019 Free Software Foundation, Inc.
7843261b
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#include "defs.h"
21#include "charset.h"
22#include "value.h"
7843261b 23#include "language.h"
70100014 24#include "target-float.h"
79a45b7d 25#include "valprint.h"
5374244e 26#include "infcall.h"
f9ffd4bb 27#include "expression.h"
03f17ccf 28#include "cp-abi.h"
49a8461d 29#include "python.h"
7843261b 30
7843261b 31#include "python-internal.h"
53a0cca3 32#include "py-ref.h"
7843261b
TJB
33
34/* Even though Python scalar types directly map to host types, we use
b021a221 35 target types here to remain consistent with the values system in
7843261b
TJB
36 GDB (which uses target arithmetic). */
37
38/* Python's integer type corresponds to C's long type. */
d452c4bc 39#define builtin_type_pyint builtin_type (python_gdbarch)->builtin_long
7843261b
TJB
40
41/* Python's float type corresponds to C's double type. */
d452c4bc 42#define builtin_type_pyfloat builtin_type (python_gdbarch)->builtin_double
7843261b
TJB
43
44/* Python's long type corresponds to C's long long type. */
d452c4bc 45#define builtin_type_pylong builtin_type (python_gdbarch)->builtin_long_long
7843261b 46
595939de
PM
47/* Python's long type corresponds to C's long long type. Unsigned version. */
48#define builtin_type_upylong builtin_type \
49 (python_gdbarch)->builtin_unsigned_long_long
50
7843261b 51#define builtin_type_pybool \
d452c4bc 52 language_bool_type (python_language, python_gdbarch)
7843261b 53
3b7538c0 54#define builtin_type_pychar \
d452c4bc 55 language_string_char_type (python_language, python_gdbarch)
3b7538c0 56
4e7a5ef5 57typedef struct value_object {
7843261b 58 PyObject_HEAD
4e7a5ef5
TT
59 struct value_object *next;
60 struct value_object *prev;
7843261b 61 struct value *value;
c0c6f777 62 PyObject *address;
2c74e833 63 PyObject *type;
03f17ccf 64 PyObject *dynamic_type;
7843261b
TJB
65} value_object;
66
4e7a5ef5
TT
67/* List of all values which are currently exposed to Python. It is
68 maintained so that when an objfile is discarded, preserve_values
69 can copy the values' types if needed. */
70/* This variable is unnecessarily initialized to NULL in order to
71 work around a linker bug on MacOS. */
72static value_object *values_in_python = NULL;
73
7843261b
TJB
74/* Called by the Python interpreter when deallocating a value object. */
75static void
76valpy_dealloc (PyObject *obj)
77{
78 value_object *self = (value_object *) obj;
79
4e7a5ef5
TT
80 /* Remove SELF from the global list. */
81 if (self->prev)
82 self->prev->next = self->next;
83 else
84 {
85 gdb_assert (values_in_python == self);
86 values_in_python = self->next;
87 }
88 if (self->next)
89 self->next->prev = self->prev;
7843261b 90
22bc8444 91 value_decref (self->value);
c0c6f777 92
2a3c71d6
TT
93 Py_XDECREF (self->address);
94 Py_XDECREF (self->type);
03f17ccf
TT
95 Py_XDECREF (self->dynamic_type);
96
9a27f2c6 97 Py_TYPE (self)->tp_free (self);
7843261b
TJB
98}
99
4e7a5ef5
TT
100/* Helper to push a Value object on the global list. */
101static void
102note_value (value_object *value_obj)
103{
104 value_obj->next = values_in_python;
105 if (value_obj->next)
106 value_obj->next->prev = value_obj;
107 value_obj->prev = NULL;
108 values_in_python = value_obj;
109}
110
8dc78533
JK
111/* Called when a new gdb.Value object needs to be allocated. Returns NULL on
112 error, with a python exception set. */
7843261b
TJB
113static PyObject *
114valpy_new (PyTypeObject *subtype, PyObject *args, PyObject *keywords)
115{
116 struct value *value = NULL; /* Initialize to appease gcc warning. */
117 value_object *value_obj;
7843261b
TJB
118
119 if (PyTuple_Size (args) != 1)
120 {
121 PyErr_SetString (PyExc_TypeError, _("Value object creation takes only "
122 "1 argument"));
123 return NULL;
124 }
125
126 value_obj = (value_object *) subtype->tp_alloc (subtype, 1);
127 if (value_obj == NULL)
128 {
129 PyErr_SetString (PyExc_MemoryError, _("Could not allocate memory to "
130 "create Value object."));
131 return NULL;
132 }
133
08c637de
TJB
134 value = convert_value_from_python (PyTuple_GetItem (args, 0));
135 if (value == NULL)
7843261b
TJB
136 {
137 subtype->tp_free (value_obj);
08c637de 138 return NULL;
7843261b
TJB
139 }
140
22bc8444 141 value_obj->value = release_value (value).release ();
c0c6f777 142 value_obj->address = NULL;
2c74e833 143 value_obj->type = NULL;
03f17ccf 144 value_obj->dynamic_type = NULL;
4e7a5ef5 145 note_value (value_obj);
7843261b
TJB
146
147 return (PyObject *) value_obj;
148}
149
4e7a5ef5
TT
150/* Iterate over all the Value objects, calling preserve_one_value on
151 each. */
152void
6dddc817
DE
153gdbpy_preserve_values (const struct extension_language_defn *extlang,
154 struct objfile *objfile, htab_t copied_types)
4e7a5ef5
TT
155{
156 value_object *iter;
157
158 for (iter = values_in_python; iter; iter = iter->next)
159 preserve_one_value (iter->value, objfile, copied_types);
160}
161
7843261b
TJB
162/* Given a value of a pointer type, apply the C unary * operator to it. */
163static PyObject *
164valpy_dereference (PyObject *self, PyObject *args)
165{
888fe1e1 166 PyObject *result = NULL;
7843261b 167
492d29ea 168 TRY
7843261b 169 {
888fe1e1 170 struct value *res_val;
eb115069 171 scoped_value_mark free_values;
888fe1e1 172
7843261b 173 res_val = value_ind (((value_object *) self)->value);
888fe1e1 174 result = value_to_value_object (res_val);
7843261b 175 }
492d29ea
PA
176 CATCH (except, RETURN_MASK_ALL)
177 {
178 GDB_PY_HANDLE_EXCEPTION (except);
179 }
180 END_CATCH
7843261b 181
888fe1e1 182 return result;
7843261b
TJB
183}
184
7b282c5a
SCR
185/* Given a value of a pointer type or a reference type, return the value
186 referenced. The difference between this function and valpy_dereference is
187 that the latter applies * unary operator to a value, which need not always
188 result in the value referenced. For example, for a value which is a reference
189 to an 'int' pointer ('int *'), valpy_dereference will result in a value of
190 type 'int' while valpy_referenced_value will result in a value of type
191 'int *'. */
192
193static PyObject *
194valpy_referenced_value (PyObject *self, PyObject *args)
195{
7b282c5a
SCR
196 PyObject *result = NULL;
197
492d29ea 198 TRY
7b282c5a
SCR
199 {
200 struct value *self_val, *res_val;
eb115069 201 scoped_value_mark free_values;
7b282c5a
SCR
202
203 self_val = ((value_object *) self)->value;
204 switch (TYPE_CODE (check_typedef (value_type (self_val))))
205 {
206 case TYPE_CODE_PTR:
207 res_val = value_ind (self_val);
208 break;
209 case TYPE_CODE_REF:
aa006118 210 case TYPE_CODE_RVALUE_REF:
7b282c5a
SCR
211 res_val = coerce_ref (self_val);
212 break;
213 default:
214 error(_("Trying to get the referenced value from a value which is "
215 "neither a pointer nor a reference."));
216 }
217
218 result = value_to_value_object (res_val);
7b282c5a 219 }
492d29ea
PA
220 CATCH (except, RETURN_MASK_ALL)
221 {
222 GDB_PY_HANDLE_EXCEPTION (except);
223 }
224 END_CATCH
7b282c5a
SCR
225
226 return result;
227}
228
4c082a81
SC
229/* Return a value which is a reference to the value. */
230
231static PyObject *
3fcf899d 232valpy_reference_value (PyObject *self, PyObject *args, enum type_code refcode)
4c082a81
SC
233{
234 PyObject *result = NULL;
235
236 TRY
237 {
238 struct value *self_val;
eb115069 239 scoped_value_mark free_values;
4c082a81
SC
240
241 self_val = ((value_object *) self)->value;
3fcf899d 242 result = value_to_value_object (value_ref (self_val, refcode));
4c082a81
SC
243 }
244 CATCH (except, RETURN_MASK_ALL)
245 {
246 GDB_PY_HANDLE_EXCEPTION (except);
247 }
248 END_CATCH
249
250 return result;
251}
252
3fcf899d
AV
253static PyObject *
254valpy_lvalue_reference_value (PyObject *self, PyObject *args)
255{
256 return valpy_reference_value (self, args, TYPE_CODE_REF);
257}
258
259static PyObject *
260valpy_rvalue_reference_value (PyObject *self, PyObject *args)
261{
262 return valpy_reference_value (self, args, TYPE_CODE_RVALUE_REF);
263}
264
4c082a81
SC
265/* Return a "const" qualified version of the value. */
266
267static PyObject *
268valpy_const_value (PyObject *self, PyObject *args)
269{
270 PyObject *result = NULL;
271
272 TRY
273 {
274 struct value *self_val, *res_val;
eb115069 275 scoped_value_mark free_values;
4c082a81
SC
276
277 self_val = ((value_object *) self)->value;
278 res_val = make_cv_value (1, 0, self_val);
279 result = value_to_value_object (res_val);
4c082a81
SC
280 }
281 CATCH (except, RETURN_MASK_ALL)
282 {
283 GDB_PY_HANDLE_EXCEPTION (except);
284 }
285 END_CATCH
286
287 return result;
288}
289
08c637de
TJB
290/* Return "&value". */
291static PyObject *
c0c6f777 292valpy_get_address (PyObject *self, void *closure)
08c637de 293{
c0c6f777 294 value_object *val_obj = (value_object *) self;
08c637de 295
c0c6f777 296 if (!val_obj->address)
08c637de 297 {
492d29ea 298 TRY
c0c6f777 299 {
888fe1e1 300 struct value *res_val;
eb115069 301 scoped_value_mark free_values;
888fe1e1 302
c0c6f777 303 res_val = value_addr (val_obj->value);
888fe1e1 304 val_obj->address = value_to_value_object (res_val);
c0c6f777 305 }
492d29ea 306 CATCH (except, RETURN_MASK_ALL)
c0c6f777
TJB
307 {
308 val_obj->address = Py_None;
309 Py_INCREF (Py_None);
310 }
492d29ea 311 END_CATCH
08c637de 312 }
08c637de 313
3fcaed38 314 Py_XINCREF (val_obj->address);
c0c6f777
TJB
315
316 return val_obj->address;
08c637de
TJB
317}
318
2c74e833
TT
319/* Return type of the value. */
320static PyObject *
321valpy_get_type (PyObject *self, void *closure)
322{
323 value_object *obj = (value_object *) self;
d59b6f6c 324
2c74e833
TT
325 if (!obj->type)
326 {
327 obj->type = type_to_type_object (value_type (obj->value));
328 if (!obj->type)
03f17ccf 329 return NULL;
2c74e833
TT
330 }
331 Py_INCREF (obj->type);
332 return obj->type;
333}
334
03f17ccf
TT
335/* Return dynamic type of the value. */
336
337static PyObject *
338valpy_get_dynamic_type (PyObject *self, void *closure)
339{
340 value_object *obj = (value_object *) self;
03f17ccf
TT
341 struct type *type = NULL;
342
343 if (obj->dynamic_type != NULL)
344 {
345 Py_INCREF (obj->dynamic_type);
346 return obj->dynamic_type;
347 }
348
492d29ea 349 TRY
03f17ccf
TT
350 {
351 struct value *val = obj->value;
eb115069 352 scoped_value_mark free_values;
03f17ccf
TT
353
354 type = value_type (val);
f168693b 355 type = check_typedef (type);
03f17ccf 356
aa006118 357 if (((TYPE_CODE (type) == TYPE_CODE_PTR) || TYPE_IS_REFERENCE (type))
4753d33b 358 && (TYPE_CODE (TYPE_TARGET_TYPE (type)) == TYPE_CODE_STRUCT))
03f17ccf
TT
359 {
360 struct value *target;
361 int was_pointer = TYPE_CODE (type) == TYPE_CODE_PTR;
362
7af389b8
SC
363 if (was_pointer)
364 target = value_ind (val);
365 else
366 target = coerce_ref (val);
03f17ccf
TT
367 type = value_rtti_type (target, NULL, NULL, NULL);
368
369 if (type)
370 {
371 if (was_pointer)
372 type = lookup_pointer_type (type);
373 else
3b224330 374 type = lookup_lvalue_reference_type (type);
03f17ccf
TT
375 }
376 }
4753d33b 377 else if (TYPE_CODE (type) == TYPE_CODE_STRUCT)
03f17ccf
TT
378 type = value_rtti_type (val, NULL, NULL, NULL);
379 else
380 {
381 /* Re-use object's static type. */
382 type = NULL;
383 }
384 }
492d29ea
PA
385 CATCH (except, RETURN_MASK_ALL)
386 {
387 GDB_PY_HANDLE_EXCEPTION (except);
388 }
389 END_CATCH
03f17ccf
TT
390
391 if (type == NULL)
97b77b39 392 obj->dynamic_type = valpy_get_type (self, NULL);
03f17ccf
TT
393 else
394 obj->dynamic_type = type_to_type_object (type);
395
97b77b39 396 Py_XINCREF (obj->dynamic_type);
03f17ccf
TT
397 return obj->dynamic_type;
398}
399
be759fcf
PM
400/* Implementation of gdb.Value.lazy_string ([encoding] [, length]) ->
401 string. Return a PyObject representing a lazy_string_object type.
402 A lazy string is a pointer to a string with an optional encoding and
403 length. If ENCODING is not given, encoding is set to None. If an
404 ENCODING is provided the encoding parameter is set to ENCODING, but
34b43320
DE
405 the string is not encoded.
406 If LENGTH is provided then the length parameter is set to LENGTH.
407 Otherwise if the value is an array of known length then the array's length
408 is used. Otherwise the length will be set to -1 (meaning first null of
409 appropriate with).
410
411 Note: In order to not break any existing uses this allows creating
412 lazy strings from anything. PR 20769. E.g.,
413 gdb.parse_and_eval("my_int_variable").lazy_string().
414 "It's easier to relax restrictions than it is to impose them after the
415 fact." So we should be flagging any unintended uses as errors, but it's
416 perhaps too late for that. */
417
be759fcf
PM
418static PyObject *
419valpy_lazy_string (PyObject *self, PyObject *args, PyObject *kw)
420{
74aedc46 421 gdb_py_longest length = -1;
be759fcf
PM
422 struct value *value = ((value_object *) self)->value;
423 const char *user_encoding = NULL;
2adadf51 424 static const char *keywords[] = { "encoding", "length", NULL };
888fe1e1 425 PyObject *str_obj = NULL;
be759fcf 426
2adadf51
PA
427 if (!gdb_PyArg_ParseTupleAndKeywords (args, kw, "|s" GDB_PY_LL_ARG,
428 keywords, &user_encoding, &length))
be759fcf
PM
429 return NULL;
430
34b43320
DE
431 if (length < -1)
432 {
433 PyErr_SetString (PyExc_ValueError, _("Invalid length."));
434 return NULL;
435 }
436
492d29ea 437 TRY
f287c1f3 438 {
eb115069 439 scoped_value_mark free_values;
34b43320
DE
440 struct type *type, *realtype;
441 CORE_ADDR addr;
442
443 type = value_type (value);
444 realtype = check_typedef (type);
888fe1e1 445
34b43320
DE
446 switch (TYPE_CODE (realtype))
447 {
448 case TYPE_CODE_ARRAY:
449 {
450 LONGEST array_length = -1;
451 LONGEST low_bound, high_bound;
452
453 /* PR 20786: There's no way to specify an array of length zero.
454 Record a length of [0,-1] which is how Ada does it. Anything
455 we do is broken, but this one possible solution. */
456 if (get_array_bounds (realtype, &low_bound, &high_bound))
457 array_length = high_bound - low_bound + 1;
458 if (length == -1)
459 length = array_length;
460 else if (array_length == -1)
461 {
462 type = lookup_array_range_type (TYPE_TARGET_TYPE (realtype),
463 0, length - 1);
464 }
465 else if (length != array_length)
466 {
467 /* We need to create a new array type with the
468 specified length. */
469 if (length > array_length)
470 error (_("Length is larger than array size."));
471 type = lookup_array_range_type (TYPE_TARGET_TYPE (realtype),
472 low_bound,
473 low_bound + length - 1);
474 }
475 addr = value_address (value);
476 break;
477 }
478 case TYPE_CODE_PTR:
479 /* If a length is specified we defer creating an array of the
480 specified width until we need to. */
481 addr = value_as_address (value);
482 break;
483 default:
484 /* Should flag an error here. PR 20769. */
485 addr = value_address (value);
486 break;
487 }
888fe1e1 488
34b43320
DE
489 str_obj = gdbpy_create_lazy_string_object (addr, length, user_encoding,
490 type);
f287c1f3 491 }
492d29ea
PA
492 CATCH (except, RETURN_MASK_ALL)
493 {
494 GDB_PY_HANDLE_EXCEPTION (except);
495 }
496 END_CATCH
be759fcf 497
888fe1e1 498 return str_obj;
be759fcf
PM
499}
500
fbb8f299
PM
501/* Implementation of gdb.Value.string ([encoding] [, errors]
502 [, length]) -> string. Return Unicode string with value contents.
503 If ENCODING is not given, the string is assumed to be encoded in
504 the target's charset. If LENGTH is provided, only fetch string to
505 the length provided. */
506
b6cb8e7d 507static PyObject *
cc924cad 508valpy_string (PyObject *self, PyObject *args, PyObject *kw)
b6cb8e7d 509{
f92adf3c 510 int length = -1;
b4be9fad 511 gdb::unique_xmalloc_ptr<gdb_byte> buffer;
b6cb8e7d 512 struct value *value = ((value_object *) self)->value;
b6cb8e7d
TJB
513 const char *encoding = NULL;
514 const char *errors = NULL;
515 const char *user_encoding = NULL;
516 const char *la_encoding = NULL;
96c07c5b 517 struct type *char_type;
2adadf51 518 static const char *keywords[] = { "encoding", "errors", "length", NULL };
b6cb8e7d 519
2adadf51
PA
520 if (!gdb_PyArg_ParseTupleAndKeywords (args, kw, "|ssi", keywords,
521 &user_encoding, &errors, &length))
b6cb8e7d
TJB
522 return NULL;
523
492d29ea 524 TRY
b6cb8e7d 525 {
96c07c5b 526 LA_GET_STRING (value, &buffer, &length, &char_type, &la_encoding);
b6cb8e7d 527 }
492d29ea
PA
528 CATCH (except, RETURN_MASK_ALL)
529 {
530 GDB_PY_HANDLE_EXCEPTION (except);
531 }
532 END_CATCH
b6cb8e7d
TJB
533
534 encoding = (user_encoding && *user_encoding) ? user_encoding : la_encoding;
b4be9fad
TT
535 return PyUnicode_Decode ((const char *) buffer.get (),
536 length * TYPE_LENGTH (char_type),
537 encoding, errors);
b6cb8e7d
TJB
538}
539
f9ffd4bb
TT
540/* A helper function that implements the various cast operators. */
541
2c74e833 542static PyObject *
f9ffd4bb 543valpy_do_cast (PyObject *self, PyObject *args, enum exp_opcode op)
2c74e833 544{
888fe1e1 545 PyObject *type_obj, *result = NULL;
2c74e833 546 struct type *type;
2c74e833
TT
547
548 if (! PyArg_ParseTuple (args, "O", &type_obj))
549 return NULL;
550
551 type = type_object_to_type (type_obj);
552 if (! type)
553 {
256458bc 554 PyErr_SetString (PyExc_RuntimeError,
044c0f87 555 _("Argument must be a type."));
2c74e833
TT
556 return NULL;
557 }
558
492d29ea 559 TRY
2c74e833 560 {
f9ffd4bb 561 struct value *val = ((value_object *) self)->value;
888fe1e1 562 struct value *res_val;
eb115069 563 scoped_value_mark free_values;
f9ffd4bb
TT
564
565 if (op == UNOP_DYNAMIC_CAST)
566 res_val = value_dynamic_cast (type, val);
567 else if (op == UNOP_REINTERPRET_CAST)
568 res_val = value_reinterpret_cast (type, val);
569 else
570 {
571 gdb_assert (op == UNOP_CAST);
572 res_val = value_cast (type, val);
573 }
888fe1e1
TT
574
575 result = value_to_value_object (res_val);
2c74e833 576 }
492d29ea
PA
577 CATCH (except, RETURN_MASK_ALL)
578 {
579 GDB_PY_HANDLE_EXCEPTION (except);
580 }
581 END_CATCH
2c74e833 582
888fe1e1 583 return result;
2c74e833
TT
584}
585
f9ffd4bb
TT
586/* Implementation of the "cast" method. */
587
588static PyObject *
589valpy_cast (PyObject *self, PyObject *args)
590{
591 return valpy_do_cast (self, args, UNOP_CAST);
592}
593
594/* Implementation of the "dynamic_cast" method. */
595
596static PyObject *
597valpy_dynamic_cast (PyObject *self, PyObject *args)
598{
599 return valpy_do_cast (self, args, UNOP_DYNAMIC_CAST);
600}
601
602/* Implementation of the "reinterpret_cast" method. */
603
604static PyObject *
605valpy_reinterpret_cast (PyObject *self, PyObject *args)
606{
607 return valpy_do_cast (self, args, UNOP_REINTERPRET_CAST);
608}
609
7843261b
TJB
610static Py_ssize_t
611valpy_length (PyObject *self)
612{
613 /* We don't support getting the number of elements in a struct / class. */
614 PyErr_SetString (PyExc_NotImplementedError,
044c0f87 615 _("Invalid operation on gdb.Value."));
7843261b
TJB
616 return -1;
617}
618
a16b0e22
SC
619/* Return 1 if the gdb.Field object FIELD is present in the value V.
620 Returns 0 otherwise. If any Python error occurs, -1 is returned. */
621
622static int
623value_has_field (struct value *v, PyObject *field)
624{
625 struct type *parent_type, *val_type;
626 enum type_code type_code;
7780f186 627 gdbpy_ref<> type_object (PyObject_GetAttrString (field, "parent_type"));
a16b0e22
SC
628 int has_field = 0;
629
630 if (type_object == NULL)
631 return -1;
632
53a0cca3 633 parent_type = type_object_to_type (type_object.get ());
a16b0e22
SC
634 if (parent_type == NULL)
635 {
636 PyErr_SetString (PyExc_TypeError,
637 _("'parent_type' attribute of gdb.Field object is not a"
638 "gdb.Type object."));
639 return -1;
640 }
641
492d29ea 642 TRY
a16b0e22
SC
643 {
644 val_type = value_type (v);
645 val_type = check_typedef (val_type);
3fcf899d 646 if (TYPE_IS_REFERENCE (val_type) || TYPE_CODE (val_type) == TYPE_CODE_PTR)
a16b0e22
SC
647 val_type = check_typedef (TYPE_TARGET_TYPE (val_type));
648
649 type_code = TYPE_CODE (val_type);
650 if ((type_code == TYPE_CODE_STRUCT || type_code == TYPE_CODE_UNION)
651 && types_equal (val_type, parent_type))
652 has_field = 1;
653 else
654 has_field = 0;
655 }
492d29ea
PA
656 CATCH (except, RETURN_MASK_ALL)
657 {
658 GDB_PY_SET_HANDLE_EXCEPTION (except);
659 }
660 END_CATCH
a16b0e22
SC
661
662 return has_field;
663}
664
665/* Return the value of a flag FLAG_NAME in a gdb.Field object FIELD.
666 Returns 1 if the flag value is true, 0 if it is false, and -1 if
667 a Python error occurs. */
668
669static int
670get_field_flag (PyObject *field, const char *flag_name)
671{
7780f186 672 gdbpy_ref<> flag_object (PyObject_GetAttrString (field, flag_name));
a16b0e22
SC
673
674 if (flag_object == NULL)
675 return -1;
676
53a0cca3 677 return PyObject_IsTrue (flag_object.get ());
a16b0e22
SC
678}
679
b5b08fb4
SC
680/* Return the "type" attribute of a gdb.Field object.
681 Returns NULL on error, with a Python exception set. */
682
683static struct type *
684get_field_type (PyObject *field)
685{
7780f186 686 gdbpy_ref<> ftype_obj (PyObject_GetAttrString (field, "type"));
b5b08fb4
SC
687 struct type *ftype;
688
689 if (ftype_obj == NULL)
690 return NULL;
53a0cca3 691 ftype = type_object_to_type (ftype_obj.get ());
b5b08fb4 692 if (ftype == NULL)
bf7105a4
JB
693 PyErr_SetString (PyExc_TypeError,
694 _("'type' attribute of gdb.Field object is not a "
695 "gdb.Type object."));
b5b08fb4
SC
696
697 return ftype;
698}
699
a16b0e22
SC
700/* Given string name or a gdb.Field object corresponding to an element inside
701 a structure, return its value object. Returns NULL on error, with a python
702 exception set. */
703
7843261b
TJB
704static PyObject *
705valpy_getitem (PyObject *self, PyObject *key)
706{
492d29ea 707 struct gdb_exception except = exception_none;
7843261b 708 value_object *self_value = (value_object *) self;
9b972014 709 gdb::unique_xmalloc_ptr<char> field;
b5b08fb4
SC
710 struct type *base_class_type = NULL, *field_type = NULL;
711 long bitpos = -1;
888fe1e1 712 PyObject *result = NULL;
7843261b 713
08c637de 714 if (gdbpy_is_string (key))
256458bc 715 {
08c637de
TJB
716 field = python_string_to_host_string (key);
717 if (field == NULL)
718 return NULL;
719 }
a16b0e22
SC
720 else if (gdbpy_is_field (key))
721 {
722 int is_base_class, valid_field;
723
724 valid_field = value_has_field (self_value->value, key);
725 if (valid_field < 0)
726 return NULL;
727 else if (valid_field == 0)
728 {
729 PyErr_SetString (PyExc_TypeError,
730 _("Invalid lookup for a field not contained in "
731 "the value."));
732
733 return NULL;
734 }
735
736 is_base_class = get_field_flag (key, "is_base_class");
737 if (is_base_class < 0)
738 return NULL;
739 else if (is_base_class > 0)
740 {
b5b08fb4
SC
741 base_class_type = get_field_type (key);
742 if (base_class_type == NULL)
a16b0e22
SC
743 return NULL;
744 }
745 else
746 {
7780f186 747 gdbpy_ref<> name_obj (PyObject_GetAttrString (key, "name"));
a16b0e22
SC
748
749 if (name_obj == NULL)
750 return NULL;
751
b5b08fb4
SC
752 if (name_obj != Py_None)
753 {
53a0cca3 754 field = python_string_to_host_string (name_obj.get ());
b5b08fb4
SC
755 if (field == NULL)
756 return NULL;
757 }
758 else
759 {
b5b08fb4
SC
760 if (!PyObject_HasAttrString (key, "bitpos"))
761 {
762 PyErr_SetString (PyExc_AttributeError,
763 _("gdb.Field object has no name and no "
764 "'bitpos' attribute."));
765
766 return NULL;
767 }
7780f186 768 gdbpy_ref<> bitpos_obj (PyObject_GetAttrString (key, "bitpos"));
b5b08fb4
SC
769 if (bitpos_obj == NULL)
770 return NULL;
53a0cca3 771 if (!gdb_py_int_as_long (bitpos_obj.get (), &bitpos))
b5b08fb4
SC
772 return NULL;
773
774 field_type = get_field_type (key);
775 if (field_type == NULL)
776 return NULL;
777 }
a16b0e22
SC
778 }
779 }
7843261b 780
492d29ea 781 TRY
7843261b 782 {
3c0ed299 783 struct value *tmp = self_value->value;
888fe1e1 784 struct value *res_val = NULL;
eb115069 785 scoped_value_mark free_values;
08c637de
TJB
786
787 if (field)
9b972014 788 res_val = value_struct_elt (&tmp, NULL, field.get (), NULL,
5996220c 789 "struct/class/union");
b5b08fb4
SC
790 else if (bitpos >= 0)
791 res_val = value_struct_elt_bitpos (&tmp, bitpos, field_type,
792 "struct/class/union");
793 else if (base_class_type != NULL)
a16b0e22 794 {
b5b08fb4 795 struct type *val_type;
a16b0e22
SC
796
797 val_type = check_typedef (value_type (tmp));
798 if (TYPE_CODE (val_type) == TYPE_CODE_PTR)
799 res_val = value_cast (lookup_pointer_type (base_class_type), tmp);
800 else if (TYPE_CODE (val_type) == TYPE_CODE_REF)
3b224330
AV
801 res_val = value_cast (lookup_lvalue_reference_type (base_class_type),
802 tmp);
3fcf899d
AV
803 else if (TYPE_CODE (val_type) == TYPE_CODE_RVALUE_REF)
804 res_val = value_cast (lookup_rvalue_reference_type (base_class_type),
805 tmp);
a16b0e22
SC
806 else
807 res_val = value_cast (base_class_type, tmp);
808 }
08c637de
TJB
809 else
810 {
811 /* Assume we are attempting an array access, and let the
812 value code throw an exception if the index has an invalid
813 type. */
814 struct value *idx = convert_value_from_python (key);
d59b6f6c 815
570e2b1a 816 if (idx != NULL)
2e4d963f
PM
817 {
818 /* Check the value's type is something that can be accessed via
819 a subscript. */
820 struct type *type;
d59b6f6c 821
2e4d963f
PM
822 tmp = coerce_ref (tmp);
823 type = check_typedef (value_type (tmp));
824 if (TYPE_CODE (type) != TYPE_CODE_ARRAY
825 && TYPE_CODE (type) != TYPE_CODE_PTR)
e10abd8f 826 error (_("Cannot subscript requested type."));
2e4d963f
PM
827 else
828 res_val = value_subscript (tmp, value_as_long (idx));
829 }
08c637de 830 }
888fe1e1
TT
831
832 if (res_val)
833 result = value_to_value_object (res_val);
7843261b 834 }
492d29ea
PA
835 CATCH (ex, RETURN_MASK_ALL)
836 {
837 except = ex;
838 }
839 END_CATCH
570e2b1a 840
7843261b
TJB
841 GDB_PY_HANDLE_EXCEPTION (except);
842
888fe1e1 843 return result;
7843261b
TJB
844}
845
846static int
847valpy_setitem (PyObject *self, PyObject *key, PyObject *value)
848{
849 PyErr_Format (PyExc_NotImplementedError,
850 _("Setting of struct elements is not currently supported."));
851 return -1;
852}
853
5374244e 854/* Called by the Python interpreter to perform an inferior function
8dc78533 855 call on the value. Returns NULL on error, with a python exception set. */
5374244e
PM
856static PyObject *
857valpy_call (PyObject *self, PyObject *args, PyObject *keywords)
858{
5374244e 859 Py_ssize_t args_count;
5374244e
PM
860 struct value *function = ((value_object *) self)->value;
861 struct value **vargs = NULL;
749fd4ea 862 struct type *ftype = NULL;
888fe1e1 863 PyObject *result = NULL;
f287c1f3 864
492d29ea 865 TRY
f287c1f3
PM
866 {
867 ftype = check_typedef (value_type (function));
868 }
492d29ea
PA
869 CATCH (except, RETURN_MASK_ALL)
870 {
871 GDB_PY_HANDLE_EXCEPTION (except);
872 }
873 END_CATCH
5374244e
PM
874
875 if (TYPE_CODE (ftype) != TYPE_CODE_FUNC)
876 {
877 PyErr_SetString (PyExc_RuntimeError,
878 _("Value is not callable (not TYPE_CODE_FUNC)."));
879 return NULL;
880 }
881
f287c1f3
PM
882 if (! PyTuple_Check (args))
883 {
884 PyErr_SetString (PyExc_TypeError,
885 _("Inferior arguments must be provided in a tuple."));
886 return NULL;
887 }
888
5374244e
PM
889 args_count = PyTuple_Size (args);
890 if (args_count > 0)
891 {
892 int i;
893
8d749320 894 vargs = XALLOCAVEC (struct value *, args_count);
5374244e
PM
895 for (i = 0; i < args_count; i++)
896 {
897 PyObject *item = PyTuple_GetItem (args, i);
898
899 if (item == NULL)
900 return NULL;
901
902 vargs[i] = convert_value_from_python (item);
903 if (vargs[i] == NULL)
904 return NULL;
905 }
906 }
907
492d29ea 908 TRY
5374244e 909 {
eb115069 910 scoped_value_mark free_values;
888fe1e1 911
e71585ff
PA
912 value *return_value
913 = call_function_by_hand (function, NULL,
914 gdb::make_array_view (vargs, args_count));
888fe1e1 915 result = value_to_value_object (return_value);
5374244e 916 }
492d29ea
PA
917 CATCH (except, RETURN_MASK_ALL)
918 {
919 GDB_PY_HANDLE_EXCEPTION (except);
920 }
921 END_CATCH
5374244e 922
888fe1e1 923 return result;
5374244e
PM
924}
925
7843261b
TJB
926/* Called by the Python interpreter to obtain string representation
927 of the object. */
928static PyObject *
929valpy_str (PyObject *self)
930{
79a45b7d 931 struct value_print_options opts;
7843261b 932
79a45b7d
TT
933 get_user_print_options (&opts);
934 opts.deref_ref = 0;
935
d7e74731
PA
936 string_file stb;
937
492d29ea 938 TRY
7843261b 939 {
d7e74731 940 common_val_print (((value_object *) self)->value, &stb, 0,
d452c4bc 941 &opts, python_language);
7843261b 942 }
492d29ea
PA
943 CATCH (except, RETURN_MASK_ALL)
944 {
945 GDB_PY_HANDLE_EXCEPTION (except);
946 }
947 END_CATCH
7843261b 948
d7e74731 949 return PyUnicode_Decode (stb.c_str (), stb.size (), host_charset (), NULL);
7843261b
TJB
950}
951
def2b000
TJB
952/* Implements gdb.Value.is_optimized_out. */
953static PyObject *
954valpy_get_is_optimized_out (PyObject *self, void *closure)
955{
956 struct value *value = ((value_object *) self)->value;
f287c1f3 957 int opt = 0;
def2b000 958
492d29ea 959 TRY
f287c1f3
PM
960 {
961 opt = value_optimized_out (value);
962 }
492d29ea
PA
963 CATCH (except, RETURN_MASK_ALL)
964 {
965 GDB_PY_HANDLE_EXCEPTION (except);
966 }
967 END_CATCH
f287c1f3
PM
968
969 if (opt)
def2b000
TJB
970 Py_RETURN_TRUE;
971
972 Py_RETURN_FALSE;
973}
974
913460fc
PK
975/* Implements gdb.Value.is_lazy. */
976static PyObject *
977valpy_get_is_lazy (PyObject *self, void *closure)
978{
979 struct value *value = ((value_object *) self)->value;
980 int opt = 0;
913460fc 981
492d29ea 982 TRY
913460fc
PK
983 {
984 opt = value_lazy (value);
985 }
492d29ea
PA
986 CATCH (except, RETURN_MASK_ALL)
987 {
988 GDB_PY_HANDLE_EXCEPTION (except);
989 }
990 END_CATCH
913460fc
PK
991
992 if (opt)
993 Py_RETURN_TRUE;
994
995 Py_RETURN_FALSE;
996}
997
998/* Implements gdb.Value.fetch_lazy (). */
999static PyObject *
1000valpy_fetch_lazy (PyObject *self, PyObject *args)
1001{
1002 struct value *value = ((value_object *) self)->value;
913460fc 1003
492d29ea 1004 TRY
913460fc
PK
1005 {
1006 if (value_lazy (value))
1007 value_fetch_lazy (value);
1008 }
492d29ea
PA
1009 CATCH (except, RETURN_MASK_ALL)
1010 {
1011 GDB_PY_HANDLE_EXCEPTION (except);
1012 }
1013 END_CATCH
913460fc
PK
1014
1015 Py_RETURN_NONE;
1016}
1017
88d4aea7
PM
1018/* Calculate and return the address of the PyObject as the value of
1019 the builtin __hash__ call. */
881d5d5d 1020static Py_hash_t
88d4aea7
PM
1021valpy_hash (PyObject *self)
1022{
881d5d5d 1023 return (intptr_t) self;
88d4aea7
PM
1024}
1025
7843261b
TJB
1026enum valpy_opcode
1027{
1028 VALPY_ADD,
1029 VALPY_SUB,
1030 VALPY_MUL,
1031 VALPY_DIV,
1032 VALPY_REM,
08c637de
TJB
1033 VALPY_POW,
1034 VALPY_LSH,
1035 VALPY_RSH,
1036 VALPY_BITAND,
1037 VALPY_BITOR,
1038 VALPY_BITXOR
7843261b
TJB
1039};
1040
1041/* If TYPE is a reference, return the target; otherwise return TYPE. */
1042#define STRIP_REFERENCE(TYPE) \
aa006118 1043 (TYPE_IS_REFERENCE (TYPE) ? (TYPE_TARGET_TYPE (TYPE)) : (TYPE))
7843261b 1044
9c6595ab
PA
1045/* Helper for valpy_binop. Returns a value object which is the result
1046 of applying the operation specified by OPCODE to the given
1047 arguments. Throws a GDB exception on error. */
1048
7843261b 1049static PyObject *
9c6595ab 1050valpy_binop_throw (enum valpy_opcode opcode, PyObject *self, PyObject *other)
7843261b 1051{
888fe1e1 1052 PyObject *result = NULL;
7843261b 1053
9c6595ab 1054 struct value *arg1, *arg2;
9c6595ab
PA
1055 struct value *res_val = NULL;
1056 enum exp_opcode op = OP_NULL;
1057 int handled = 0;
1058
eb115069
TT
1059 scoped_value_mark free_values;
1060
9c6595ab
PA
1061 /* If the gdb.Value object is the second operand, then it will be
1062 passed to us as the OTHER argument, and SELF will be an entirely
1063 different kind of object, altogether. Because of this, we can't
1064 assume self is a gdb.Value object and need to convert it from
1065 python as well. */
1066 arg1 = convert_value_from_python (self);
1067 if (arg1 == NULL)
eb115069 1068 return NULL;
08c637de 1069
9c6595ab
PA
1070 arg2 = convert_value_from_python (other);
1071 if (arg2 == NULL)
eb115069 1072 return NULL;
7843261b 1073
9c6595ab
PA
1074 switch (opcode)
1075 {
1076 case VALPY_ADD:
1077 {
1078 struct type *ltype = value_type (arg1);
1079 struct type *rtype = value_type (arg2);
1080
1081 ltype = check_typedef (ltype);
1082 ltype = STRIP_REFERENCE (ltype);
1083 rtype = check_typedef (rtype);
1084 rtype = STRIP_REFERENCE (rtype);
1085
1086 handled = 1;
1087 if (TYPE_CODE (ltype) == TYPE_CODE_PTR
1088 && is_integral_type (rtype))
1089 res_val = value_ptradd (arg1, value_as_long (arg2));
1090 else if (TYPE_CODE (rtype) == TYPE_CODE_PTR
1091 && is_integral_type (ltype))
1092 res_val = value_ptradd (arg2, value_as_long (arg1));
1093 else
7843261b 1094 {
9c6595ab
PA
1095 handled = 0;
1096 op = BINOP_ADD;
7843261b 1097 }
9c6595ab
PA
1098 }
1099 break;
1100 case VALPY_SUB:
1101 {
1102 struct type *ltype = value_type (arg1);
1103 struct type *rtype = value_type (arg2);
1104
1105 ltype = check_typedef (ltype);
1106 ltype = STRIP_REFERENCE (ltype);
1107 rtype = check_typedef (rtype);
1108 rtype = STRIP_REFERENCE (rtype);
1109
1110 handled = 1;
1111 if (TYPE_CODE (ltype) == TYPE_CODE_PTR
1112 && TYPE_CODE (rtype) == TYPE_CODE_PTR)
1113 /* A ptrdiff_t for the target would be preferable here. */
1114 res_val = value_from_longest (builtin_type_pyint,
1115 value_ptrdiff (arg1, arg2));
1116 else if (TYPE_CODE (ltype) == TYPE_CODE_PTR
1117 && is_integral_type (rtype))
1118 res_val = value_ptradd (arg1, - value_as_long (arg2));
1119 else
7843261b 1120 {
9c6595ab
PA
1121 handled = 0;
1122 op = BINOP_SUB;
7843261b 1123 }
9c6595ab
PA
1124 }
1125 break;
1126 case VALPY_MUL:
1127 op = BINOP_MUL;
1128 break;
1129 case VALPY_DIV:
1130 op = BINOP_DIV;
1131 break;
1132 case VALPY_REM:
1133 op = BINOP_REM;
1134 break;
1135 case VALPY_POW:
1136 op = BINOP_EXP;
1137 break;
1138 case VALPY_LSH:
1139 op = BINOP_LSH;
1140 break;
1141 case VALPY_RSH:
1142 op = BINOP_RSH;
1143 break;
1144 case VALPY_BITAND:
1145 op = BINOP_BITWISE_AND;
1146 break;
1147 case VALPY_BITOR:
1148 op = BINOP_BITWISE_IOR;
1149 break;
1150 case VALPY_BITXOR:
1151 op = BINOP_BITWISE_XOR;
1152 break;
1153 }
888fe1e1 1154
9c6595ab
PA
1155 if (!handled)
1156 {
1157 if (binop_user_defined_p (op, arg1, arg2))
1158 res_val = value_x_binop (arg1, arg2, op, OP_NULL, EVAL_NORMAL);
1159 else
1160 res_val = value_binop (arg1, arg2, op);
1161 }
f7bd0f78 1162
9c6595ab
PA
1163 if (res_val)
1164 result = value_to_value_object (res_val);
888fe1e1 1165
9c6595ab
PA
1166 return result;
1167}
1168
1169/* Returns a value object which is the result of applying the operation
1170 specified by OPCODE to the given arguments. Returns NULL on error, with
1171 a python exception set. */
1172static PyObject *
1173valpy_binop (enum valpy_opcode opcode, PyObject *self, PyObject *other)
1174{
1175 PyObject *result = NULL;
1176
1177 TRY
1178 {
1179 result = valpy_binop_throw (opcode, self, other);
7843261b 1180 }
492d29ea
PA
1181 CATCH (except, RETURN_MASK_ALL)
1182 {
1183 GDB_PY_HANDLE_EXCEPTION (except);
1184 }
1185 END_CATCH
7843261b 1186
888fe1e1 1187 return result;
7843261b
TJB
1188}
1189
1190static PyObject *
1191valpy_add (PyObject *self, PyObject *other)
1192{
1193 return valpy_binop (VALPY_ADD, self, other);
1194}
1195
1196static PyObject *
1197valpy_subtract (PyObject *self, PyObject *other)
1198{
1199 return valpy_binop (VALPY_SUB, self, other);
1200}
1201
1202static PyObject *
1203valpy_multiply (PyObject *self, PyObject *other)
1204{
1205 return valpy_binop (VALPY_MUL, self, other);
1206}
1207
1208static PyObject *
1209valpy_divide (PyObject *self, PyObject *other)
1210{
1211 return valpy_binop (VALPY_DIV, self, other);
1212}
1213
1214static PyObject *
1215valpy_remainder (PyObject *self, PyObject *other)
1216{
1217 return valpy_binop (VALPY_REM, self, other);
1218}
1219
1220static PyObject *
1221valpy_power (PyObject *self, PyObject *other, PyObject *unused)
1222{
1223 /* We don't support the ternary form of pow. I don't know how to express
1224 that, so let's just throw NotImplementedError to at least do something
1225 about it. */
1226 if (unused != Py_None)
1227 {
1228 PyErr_SetString (PyExc_NotImplementedError,
1229 "Invalid operation on gdb.Value.");
1230 return NULL;
1231 }
1232
1233 return valpy_binop (VALPY_POW, self, other);
1234}
1235
1236static PyObject *
1237valpy_negative (PyObject *self)
1238{
888fe1e1 1239 PyObject *result = NULL;
7843261b 1240
492d29ea 1241 TRY
7843261b 1242 {
888fe1e1 1243 /* Perhaps overkill, but consistency has some virtue. */
eb115069 1244 scoped_value_mark free_values;
888fe1e1
TT
1245 struct value *val;
1246
7843261b 1247 val = value_neg (((value_object *) self)->value);
888fe1e1 1248 result = value_to_value_object (val);
7843261b 1249 }
492d29ea
PA
1250 CATCH (except, RETURN_MASK_ALL)
1251 {
1252 GDB_PY_HANDLE_EXCEPTION (except);
1253 }
1254 END_CATCH
7843261b 1255
888fe1e1 1256 return result;
7843261b
TJB
1257}
1258
1259static PyObject *
1260valpy_positive (PyObject *self)
1261{
4e7a5ef5 1262 return value_to_value_object (((value_object *) self)->value);
7843261b
TJB
1263}
1264
1265static PyObject *
1266valpy_absolute (PyObject *self)
1267{
22601c15 1268 struct value *value = ((value_object *) self)->value;
f287c1f3 1269 int isabs = 1;
d59b6f6c 1270
492d29ea 1271 TRY
f287c1f3 1272 {
eb115069 1273 scoped_value_mark free_values;
888fe1e1 1274
f287c1f3
PM
1275 if (value_less (value, value_zero (value_type (value), not_lval)))
1276 isabs = 0;
1277 }
492d29ea
PA
1278 CATCH (except, RETURN_MASK_ALL)
1279 {
1280 GDB_PY_HANDLE_EXCEPTION (except);
1281 }
1282 END_CATCH
f287c1f3
PM
1283
1284 if (isabs)
7843261b 1285 return valpy_positive (self);
f287c1f3
PM
1286 else
1287 return valpy_negative (self);
7843261b
TJB
1288}
1289
1290/* Implements boolean evaluation of gdb.Value. */
1291static int
1292valpy_nonzero (PyObject *self)
1293{
492d29ea 1294 struct gdb_exception except = exception_none;
7843261b
TJB
1295 value_object *self_value = (value_object *) self;
1296 struct type *type;
f287c1f3 1297 int nonzero = 0; /* Appease GCC warning. */
7843261b 1298
492d29ea 1299 TRY
f287c1f3 1300 {
5d9c5995
PM
1301 type = check_typedef (value_type (self_value->value));
1302
f287c1f3
PM
1303 if (is_integral_type (type) || TYPE_CODE (type) == TYPE_CODE_PTR)
1304 nonzero = !!value_as_long (self_value->value);
70100014
UW
1305 else if (is_floating_value (self_value->value))
1306 nonzero = !target_float_is_zero (value_contents (self_value->value),
1307 type);
f287c1f3
PM
1308 else
1309 /* All other values are True. */
1310 nonzero = 1;
1311 }
492d29ea
PA
1312 CATCH (ex, RETURN_MASK_ALL)
1313 {
1314 except = ex;
1315 }
1316 END_CATCH
1317
f287c1f3
PM
1318 /* This is not documented in the Python documentation, but if this
1319 function fails, return -1 as slot_nb_nonzero does (the default
1320 Python nonzero function). */
1321 GDB_PY_SET_HANDLE_EXCEPTION (except);
1322
1323 return nonzero;
7843261b
TJB
1324}
1325
08c637de 1326/* Implements ~ for value objects. */
7843261b 1327static PyObject *
08c637de 1328valpy_invert (PyObject *self)
7843261b 1329{
08c637de 1330 struct value *val = NULL;
7843261b 1331
492d29ea 1332 TRY
7843261b 1333 {
08c637de
TJB
1334 val = value_complement (((value_object *) self)->value);
1335 }
492d29ea
PA
1336 CATCH (except, RETURN_MASK_ALL)
1337 {
1338 GDB_PY_HANDLE_EXCEPTION (except);
1339 }
1340 END_CATCH
7843261b 1341
08c637de
TJB
1342 return value_to_value_object (val);
1343}
7843261b 1344
08c637de
TJB
1345/* Implements left shift for value objects. */
1346static PyObject *
1347valpy_lsh (PyObject *self, PyObject *other)
1348{
1349 return valpy_binop (VALPY_LSH, self, other);
1350}
7843261b 1351
08c637de
TJB
1352/* Implements right shift for value objects. */
1353static PyObject *
1354valpy_rsh (PyObject *self, PyObject *other)
1355{
1356 return valpy_binop (VALPY_RSH, self, other);
1357}
7843261b 1358
08c637de
TJB
1359/* Implements bitwise and for value objects. */
1360static PyObject *
1361valpy_and (PyObject *self, PyObject *other)
1362{
1363 return valpy_binop (VALPY_BITAND, self, other);
1364}
7843261b 1365
08c637de
TJB
1366/* Implements bitwise or for value objects. */
1367static PyObject *
1368valpy_or (PyObject *self, PyObject *other)
1369{
1370 return valpy_binop (VALPY_BITOR, self, other);
1371}
1372
1373/* Implements bitwise xor for value objects. */
1374static PyObject *
1375valpy_xor (PyObject *self, PyObject *other)
1376{
1377 return valpy_binop (VALPY_BITXOR, self, other);
1378}
1379
9c6595ab
PA
1380/* Helper for valpy_richcompare. Implements comparison operations for
1381 value objects. Returns true/false on success. Returns -1 with a
1382 Python exception set if a Python error is detected. Throws a GDB
1383 exception on other errors (memory error, etc.). */
1384
1385static int
1386valpy_richcompare_throw (PyObject *self, PyObject *other, int op)
1387{
1388 int result;
1389 struct value *value_other;
1390 struct value *value_self;
9c6595ab 1391
eb115069
TT
1392 scoped_value_mark free_values;
1393
9c6595ab
PA
1394 value_other = convert_value_from_python (other);
1395 if (value_other == NULL)
1396 return -1;
1397
9c6595ab
PA
1398 value_self = ((value_object *) self)->value;
1399
1400 switch (op)
1401 {
1402 case Py_LT:
1403 result = value_less (value_self, value_other);
1404 break;
1405 case Py_LE:
1406 result = value_less (value_self, value_other)
1407 || value_equal (value_self, value_other);
1408 break;
1409 case Py_EQ:
1410 result = value_equal (value_self, value_other);
1411 break;
1412 case Py_NE:
1413 result = !value_equal (value_self, value_other);
1414 break;
1415 case Py_GT:
1416 result = value_less (value_other, value_self);
1417 break;
1418 case Py_GE:
1419 result = (value_less (value_other, value_self)
1420 || value_equal (value_self, value_other));
1421 break;
1422 default:
1423 /* Can't happen. */
1424 PyErr_SetString (PyExc_NotImplementedError,
1425 _("Invalid operation on gdb.Value."));
1426 result = -1;
1427 break;
1428 }
1429
9c6595ab
PA
1430 return result;
1431}
1432
1433
8dc78533
JK
1434/* Implements comparison operations for value objects. Returns NULL on error,
1435 with a python exception set. */
08c637de
TJB
1436static PyObject *
1437valpy_richcompare (PyObject *self, PyObject *other, int op)
1438{
1439 int result = 0;
08c637de
TJB
1440
1441 if (other == Py_None)
7843261b
TJB
1442 /* Comparing with None is special. From what I can tell, in Python
1443 None is smaller than anything else. */
1444 switch (op) {
1445 case Py_LT:
1446 case Py_LE:
1447 case Py_EQ:
1448 Py_RETURN_FALSE;
1449 case Py_NE:
1450 case Py_GT:
1451 case Py_GE:
1452 Py_RETURN_TRUE;
1453 default:
1454 /* Can't happen. */
1455 PyErr_SetString (PyExc_NotImplementedError,
044c0f87 1456 _("Invalid operation on gdb.Value."));
7843261b
TJB
1457 return NULL;
1458 }
7843261b 1459
492d29ea 1460 TRY
7843261b 1461 {
9c6595ab 1462 result = valpy_richcompare_throw (self, other, op);
7843261b 1463 }
492d29ea
PA
1464 CATCH (except, RETURN_MASK_ALL)
1465 {
1466 GDB_PY_HANDLE_EXCEPTION (except);
1467 }
1468 END_CATCH
7843261b 1469
f02779d8
TT
1470 /* In this case, the Python exception has already been set. */
1471 if (result < 0)
1472 return NULL;
1473
7843261b
TJB
1474 if (result == 1)
1475 Py_RETURN_TRUE;
1476
1477 Py_RETURN_FALSE;
1478}
1479
9a27f2c6 1480#ifndef IS_PY3K
08c637de
TJB
1481/* Implements conversion to int. */
1482static PyObject *
1483valpy_int (PyObject *self)
1484{
1485 struct value *value = ((value_object *) self)->value;
1486 struct type *type = value_type (value);
1487 LONGEST l = 0;
08c637de 1488
492d29ea 1489 TRY
08c637de 1490 {
fb4fa946
TT
1491 if (is_floating_value (value))
1492 {
1493 type = builtin_type_pylong;
1494 value = value_cast (type, value);
1495 }
1496
f5769a2c
TT
1497 if (!is_integral_type (type)
1498 && TYPE_CODE (type) != TYPE_CODE_PTR)
f287c1f3
PM
1499 error (_("Cannot convert value to int."));
1500
08c637de
TJB
1501 l = value_as_long (value);
1502 }
492d29ea
PA
1503 CATCH (except, RETURN_MASK_ALL)
1504 {
1505 GDB_PY_HANDLE_EXCEPTION (except);
1506 }
1507 END_CATCH
08c637de 1508
1c1e54f6 1509 if (TYPE_UNSIGNED (type))
12dfa12a 1510 return gdb_py_object_from_ulongest (l).release ();
1c1e54f6 1511 else
12dfa12a 1512 return gdb_py_object_from_longest (l).release ();
08c637de 1513}
9a27f2c6 1514#endif
08c637de
TJB
1515
1516/* Implements conversion to long. */
1517static PyObject *
1518valpy_long (PyObject *self)
1519{
1520 struct value *value = ((value_object *) self)->value;
1521 struct type *type = value_type (value);
1522 LONGEST l = 0;
08c637de 1523
492d29ea 1524 TRY
08c637de 1525 {
fb4fa946
TT
1526 if (is_floating_value (value))
1527 {
1528 type = builtin_type_pylong;
1529 value = value_cast (type, value);
1530 }
1531
f168693b 1532 type = check_typedef (type);
f287c1f3 1533
7c245c24
JB
1534 if (!is_integral_type (type)
1535 && TYPE_CODE (type) != TYPE_CODE_PTR)
f287c1f3
PM
1536 error (_("Cannot convert value to long."));
1537
08c637de
TJB
1538 l = value_as_long (value);
1539 }
492d29ea
PA
1540 CATCH (except, RETURN_MASK_ALL)
1541 {
1542 GDB_PY_HANDLE_EXCEPTION (except);
1543 }
1544 END_CATCH
08c637de 1545
33fa2c6e
DE
1546 if (TYPE_UNSIGNED (type))
1547 return gdb_py_long_from_ulongest (l);
1548 else
1549 return gdb_py_long_from_longest (l);
08c637de
TJB
1550}
1551
1552/* Implements conversion to float. */
1553static PyObject *
1554valpy_float (PyObject *self)
1555{
1556 struct value *value = ((value_object *) self)->value;
1557 struct type *type = value_type (value);
1558 double d = 0;
08c637de 1559
492d29ea 1560 TRY
08c637de 1561 {
f168693b 1562 type = check_typedef (type);
f287c1f3 1563
fb4fa946
TT
1564 if (TYPE_CODE (type) == TYPE_CODE_FLT && is_floating_value (value))
1565 d = target_float_to_host_double (value_contents (value), type);
1566 else if (TYPE_CODE (type) == TYPE_CODE_INT)
1567 {
1568 /* Note that valpy_long accepts TYPE_CODE_PTR and some
1569 others here here -- but casting a pointer or bool to a
1570 float seems wrong. */
1571 d = value_as_long (value);
1572 }
1573 else
f287c1f3 1574 error (_("Cannot convert value to float."));
08c637de 1575 }
492d29ea
PA
1576 CATCH (except, RETURN_MASK_ALL)
1577 {
1578 GDB_PY_HANDLE_EXCEPTION (except);
1579 }
1580 END_CATCH
08c637de
TJB
1581
1582 return PyFloat_FromDouble (d);
1583}
1584
7843261b
TJB
1585/* Returns an object for a value which is released from the all_values chain,
1586 so its lifetime is not bound to the execution of a command. */
1587PyObject *
1588value_to_value_object (struct value *val)
1589{
1590 value_object *val_obj;
1591
1592 val_obj = PyObject_New (value_object, &value_object_type);
1593 if (val_obj != NULL)
1594 {
22bc8444 1595 val_obj->value = release_value (val).release ();
c0c6f777 1596 val_obj->address = NULL;
2c74e833 1597 val_obj->type = NULL;
03f17ccf 1598 val_obj->dynamic_type = NULL;
4e7a5ef5 1599 note_value (val_obj);
7843261b
TJB
1600 }
1601
1602 return (PyObject *) val_obj;
1603}
1604
4e7a5ef5
TT
1605/* Returns a borrowed reference to the struct value corresponding to
1606 the given value object. */
a6bac58e
TT
1607struct value *
1608value_object_to_value (PyObject *self)
1609{
1610 value_object *real;
d59b6f6c 1611
a6bac58e
TT
1612 if (! PyObject_TypeCheck (self, &value_object_type))
1613 return NULL;
1614 real = (value_object *) self;
1615 return real->value;
1616}
1617
7843261b 1618/* Try to convert a Python value to a gdb value. If the value cannot
4e7a5ef5
TT
1619 be converted, set a Python exception and return NULL. Returns a
1620 reference to a new value on the all_values chain. */
7843261b
TJB
1621
1622struct value *
1623convert_value_from_python (PyObject *obj)
1624{
1625 struct value *value = NULL; /* -Wall */
08c637de 1626 int cmp;
7843261b 1627
08c637de 1628 gdb_assert (obj != NULL);
7843261b 1629
492d29ea 1630 TRY
7843261b 1631 {
256458bc 1632 if (PyBool_Check (obj))
08c637de
TJB
1633 {
1634 cmp = PyObject_IsTrue (obj);
1635 if (cmp >= 0)
1636 value = value_from_longest (builtin_type_pybool, cmp);
1637 }
06ab7b19
PM
1638 /* Make a long logic check first. In Python 3.x, internally,
1639 all integers are represented as longs. In Python 2.x, there
1640 is still a differentiation internally between a PyInt and a
1641 PyLong. Explicitly do this long check conversion first. In
1642 GDB, for Python 3.x, we #ifdef PyInt = PyLong. This check has
1643 to be done first to ensure we do not lose information in the
1644 conversion process. */
08c637de
TJB
1645 else if (PyLong_Check (obj))
1646 {
1647 LONGEST l = PyLong_AsLongLong (obj);
7843261b 1648
595939de
PM
1649 if (PyErr_Occurred ())
1650 {
1651 /* If the error was an overflow, we can try converting to
1652 ULONGEST instead. */
1653 if (PyErr_ExceptionMatches (PyExc_OverflowError))
1654 {
5c329e6a 1655 gdbpy_err_fetch fetched_error;
7780f186 1656 gdbpy_ref<> zero (PyInt_FromLong (0));
595939de
PM
1657
1658 /* Check whether obj is positive. */
53a0cca3 1659 if (PyObject_RichCompareBool (obj, zero.get (), Py_GT) > 0)
595939de
PM
1660 {
1661 ULONGEST ul;
1662
1663 ul = PyLong_AsUnsignedLongLong (obj);
1664 if (! PyErr_Occurred ())
1665 value = value_from_ulongest (builtin_type_upylong, ul);
1666 }
1667 else
5c329e6a
TT
1668 {
1669 /* There's nothing we can do. */
1670 fetched_error.restore ();
1671 }
595939de
PM
1672 }
1673 }
1674 else
08c637de
TJB
1675 value = value_from_longest (builtin_type_pylong, l);
1676 }
12c58cd4 1677#if PY_MAJOR_VERSION == 2
06ab7b19
PM
1678 else if (PyInt_Check (obj))
1679 {
1680 long l = PyInt_AsLong (obj);
1681
1682 if (! PyErr_Occurred ())
1683 value = value_from_longest (builtin_type_pyint, l);
1684 }
12c58cd4 1685#endif
08c637de
TJB
1686 else if (PyFloat_Check (obj))
1687 {
1688 double d = PyFloat_AsDouble (obj);
7843261b 1689
08c637de 1690 if (! PyErr_Occurred ())
14ad9311
UW
1691 {
1692 value = allocate_value (builtin_type_pyfloat);
1693 target_float_from_host_double (value_contents_raw (value),
1694 value_type (value), d);
1695 }
08c637de
TJB
1696 }
1697 else if (gdbpy_is_string (obj))
1698 {
9b972014
TT
1699 gdb::unique_xmalloc_ptr<char> s
1700 = python_string_to_target_string (obj);
08c637de 1701 if (s != NULL)
9b972014
TT
1702 value = value_cstring (s.get (), strlen (s.get ()),
1703 builtin_type_pychar);
08c637de
TJB
1704 }
1705 else if (PyObject_TypeCheck (obj, &value_object_type))
cc924cad 1706 value = value_copy (((value_object *) obj)->value);
be759fcf
PM
1707 else if (gdbpy_is_lazy_string (obj))
1708 {
1709 PyObject *result;
d59b6f6c 1710
fb6a3ed3 1711 result = PyObject_CallMethodObjArgs (obj, gdbpy_value_cst, NULL);
be759fcf
PM
1712 value = value_copy (((value_object *) result)->value);
1713 }
08c637de 1714 else
9a27f2c6
PK
1715#ifdef IS_PY3K
1716 PyErr_Format (PyExc_TypeError,
1717 _("Could not convert Python object: %S."), obj);
1718#else
9a2b4c1b
MS
1719 PyErr_Format (PyExc_TypeError,
1720 _("Could not convert Python object: %s."),
08c637de 1721 PyString_AsString (PyObject_Str (obj)));
9a27f2c6 1722#endif
08c637de 1723 }
492d29ea 1724 CATCH (except, RETURN_MASK_ALL)
08c637de 1725 {
ec9c2750 1726 gdbpy_convert_exception (except);
08c637de
TJB
1727 return NULL;
1728 }
492d29ea 1729 END_CATCH
7843261b
TJB
1730
1731 return value;
1732}
1733
1734/* Returns value object in the ARGth position in GDB's history. */
1735PyObject *
08c637de 1736gdbpy_history (PyObject *self, PyObject *args)
7843261b
TJB
1737{
1738 int i;
1739 struct value *res_val = NULL; /* Initialize to appease gcc warning. */
7843261b
TJB
1740
1741 if (!PyArg_ParseTuple (args, "i", &i))
1742 return NULL;
1743
492d29ea 1744 TRY
7843261b
TJB
1745 {
1746 res_val = access_value_history (i);
1747 }
492d29ea
PA
1748 CATCH (except, RETURN_MASK_ALL)
1749 {
1750 GDB_PY_HANDLE_EXCEPTION (except);
1751 }
1752 END_CATCH
7843261b
TJB
1753
1754 return value_to_value_object (res_val);
1755}
1756
7729052b
TT
1757/* Return the value of a convenience variable. */
1758PyObject *
1759gdbpy_convenience_variable (PyObject *self, PyObject *args)
1760{
1761 const char *varname;
1762 struct value *res_val = NULL;
1763
1764 if (!PyArg_ParseTuple (args, "s", &varname))
1765 return NULL;
1766
1767 TRY
1768 {
1769 struct internalvar *var = lookup_only_internalvar (varname);
1770
1771 if (var != NULL)
1772 {
1773 res_val = value_of_internalvar (python_gdbarch, var);
1774 if (TYPE_CODE (value_type (res_val)) == TYPE_CODE_VOID)
1775 res_val = NULL;
1776 }
1777 }
1778 CATCH (except, RETURN_MASK_ALL)
1779 {
1780 GDB_PY_HANDLE_EXCEPTION (except);
1781 }
1782 END_CATCH
1783
1784 if (res_val == NULL)
1785 Py_RETURN_NONE;
1786
1787 return value_to_value_object (res_val);
1788}
1789
1790/* Set the value of a convenience variable. */
1791PyObject *
1792gdbpy_set_convenience_variable (PyObject *self, PyObject *args)
1793{
1794 const char *varname;
1795 PyObject *value_obj;
1796 struct value *value = NULL;
1797
1798 if (!PyArg_ParseTuple (args, "sO", &varname, &value_obj))
1799 return NULL;
1800
1801 /* None means to clear the variable. */
1802 if (value_obj != Py_None)
1803 {
1804 value = convert_value_from_python (value_obj);
1805 if (value == NULL)
1806 return NULL;
1807 }
1808
1809 TRY
1810 {
1811 if (value == NULL)
1812 {
1813 struct internalvar *var = lookup_only_internalvar (varname);
1814
1815 if (var != NULL)
1816 clear_internalvar (var);
1817 }
1818 else
1819 {
1820 struct internalvar *var = lookup_internalvar (varname);
1821
1822 set_internalvar (var, value);
1823 }
1824 }
1825 CATCH (except, RETURN_MASK_ALL)
1826 {
1827 GDB_PY_HANDLE_EXCEPTION (except);
1828 }
1829 END_CATCH
1830
1831 Py_RETURN_NONE;
1832}
1833
595939de
PM
1834/* Returns 1 in OBJ is a gdb.Value object, 0 otherwise. */
1835
1836int
1837gdbpy_is_value_object (PyObject *obj)
1838{
1839 return PyObject_TypeCheck (obj, &value_object_type);
1840}
1841
999633ed 1842int
7843261b
TJB
1843gdbpy_initialize_values (void)
1844{
7843261b 1845 if (PyType_Ready (&value_object_type) < 0)
999633ed 1846 return -1;
7843261b 1847
aa36459a
TT
1848 return gdb_pymodule_addobject (gdb_module, "Value",
1849 (PyObject *) &value_object_type);
7843261b
TJB
1850}
1851
2c74e833
TT
1852\f
1853
0d1f4ceb 1854static gdb_PyGetSetDef value_object_getset[] = {
c0c6f777
TJB
1855 { "address", valpy_get_address, NULL, "The address of the value.",
1856 NULL },
def2b000 1857 { "is_optimized_out", valpy_get_is_optimized_out, NULL,
9a2b4c1b
MS
1858 "Boolean telling whether the value is optimized "
1859 "out (i.e., not available).",
def2b000 1860 NULL },
2c74e833 1861 { "type", valpy_get_type, NULL, "Type of the value.", NULL },
03f17ccf
TT
1862 { "dynamic_type", valpy_get_dynamic_type, NULL,
1863 "Dynamic type of the value.", NULL },
913460fc
PK
1864 { "is_lazy", valpy_get_is_lazy, NULL,
1865 "Boolean telling whether the value is lazy (not fetched yet\n\
1866from the inferior). A lazy value is fetched when needed, or when\n\
1867the \"fetch_lazy()\" method is called.", NULL },
def2b000
TJB
1868 {NULL} /* Sentinel */
1869};
1870
f9176c46 1871static PyMethodDef value_object_methods[] = {
2c74e833 1872 { "cast", valpy_cast, METH_VARARGS, "Cast the value to the supplied type." },
f9ffd4bb
TT
1873 { "dynamic_cast", valpy_dynamic_cast, METH_VARARGS,
1874 "dynamic_cast (gdb.Type) -> gdb.Value\n\
1875Cast the value to the supplied type, as if by the C++ dynamic_cast operator."
1876 },
1877 { "reinterpret_cast", valpy_reinterpret_cast, METH_VARARGS,
1878 "reinterpret_cast (gdb.Type) -> gdb.Value\n\
1879Cast the value to the supplied type, as if by the C++\n\
1880reinterpret_cast operator."
1881 },
f9176c46 1882 { "dereference", valpy_dereference, METH_NOARGS, "Dereferences the value." },
7b282c5a
SCR
1883 { "referenced_value", valpy_referenced_value, METH_NOARGS,
1884 "Return the value referenced by a TYPE_CODE_REF or TYPE_CODE_PTR value." },
3fcf899d 1885 { "reference_value", valpy_lvalue_reference_value, METH_NOARGS,
4c082a81 1886 "Return a value of type TYPE_CODE_REF referencing this value." },
3fcf899d
AV
1887 { "rvalue_reference_value", valpy_rvalue_reference_value, METH_NOARGS,
1888 "Return a value of type TYPE_CODE_RVALUE_REF referencing this value." },
4c082a81
SC
1889 { "const_value", valpy_const_value, METH_NOARGS,
1890 "Return a 'const' qualied version of the same value." },
9a2b4c1b
MS
1891 { "lazy_string", (PyCFunction) valpy_lazy_string,
1892 METH_VARARGS | METH_KEYWORDS,
be759fcf
PM
1893 "lazy_string ([encoding] [, length]) -> lazy_string\n\
1894Return a lazy string representation of the value." },
cc924cad 1895 { "string", (PyCFunction) valpy_string, METH_VARARGS | METH_KEYWORDS,
fbb8f299 1896 "string ([encoding] [, errors] [, length]) -> string\n\
cc924cad 1897Return Unicode string representation of the value." },
256458bc 1898 { "fetch_lazy", valpy_fetch_lazy, METH_NOARGS,
913460fc 1899 "Fetches the value from the inferior, if it was lazy." },
f9176c46
PA
1900 {NULL} /* Sentinel */
1901};
1902
1903static PyNumberMethods value_object_as_number = {
1904 valpy_add,
1905 valpy_subtract,
1906 valpy_multiply,
9a27f2c6 1907#ifndef IS_PY3K
f9176c46 1908 valpy_divide,
9a27f2c6 1909#endif
f9176c46
PA
1910 valpy_remainder,
1911 NULL, /* nb_divmod */
1912 valpy_power, /* nb_power */
1913 valpy_negative, /* nb_negative */
1914 valpy_positive, /* nb_positive */
1915 valpy_absolute, /* nb_absolute */
08c637de
TJB
1916 valpy_nonzero, /* nb_nonzero */
1917 valpy_invert, /* nb_invert */
1918 valpy_lsh, /* nb_lshift */
1919 valpy_rsh, /* nb_rshift */
1920 valpy_and, /* nb_and */
1921 valpy_xor, /* nb_xor */
1922 valpy_or, /* nb_or */
9a27f2c6
PK
1923#ifdef IS_PY3K
1924 valpy_long, /* nb_int */
1925 NULL, /* reserved */
1926#else
08c637de
TJB
1927 NULL, /* nb_coerce */
1928 valpy_int, /* nb_int */
1929 valpy_long, /* nb_long */
9a27f2c6 1930#endif
08c637de 1931 valpy_float, /* nb_float */
9a27f2c6 1932#ifndef IS_PY3K
08c637de 1933 NULL, /* nb_oct */
9a27f2c6
PK
1934 NULL, /* nb_hex */
1935#endif
1936 NULL, /* nb_inplace_add */
1937 NULL, /* nb_inplace_subtract */
1938 NULL, /* nb_inplace_multiply */
e2b7f516
TT
1939#ifndef IS_PY3K
1940 NULL, /* nb_inplace_divide */
1941#endif
9a27f2c6
PK
1942 NULL, /* nb_inplace_remainder */
1943 NULL, /* nb_inplace_power */
1944 NULL, /* nb_inplace_lshift */
1945 NULL, /* nb_inplace_rshift */
1946 NULL, /* nb_inplace_and */
1947 NULL, /* nb_inplace_xor */
1948 NULL, /* nb_inplace_or */
1949 NULL, /* nb_floor_divide */
ddae9462
TT
1950 valpy_divide, /* nb_true_divide */
1951 NULL, /* nb_inplace_floor_divide */
1952 NULL, /* nb_inplace_true_divide */
7bd787e8 1953#ifndef HAVE_LIBPYTHON2_4
ddae9462
TT
1954 /* This was added in Python 2.5. */
1955 valpy_long, /* nb_index */
7bd787e8 1956#endif /* HAVE_LIBPYTHON2_4 */
f9176c46
PA
1957};
1958
1959static PyMappingMethods value_object_as_mapping = {
1960 valpy_length,
1961 valpy_getitem,
1962 valpy_setitem
1963};
1964
1965PyTypeObject value_object_type = {
9a27f2c6 1966 PyVarObject_HEAD_INIT (NULL, 0)
f9176c46
PA
1967 "gdb.Value", /*tp_name*/
1968 sizeof (value_object), /*tp_basicsize*/
1969 0, /*tp_itemsize*/
1970 valpy_dealloc, /*tp_dealloc*/
1971 0, /*tp_print*/
1972 0, /*tp_getattr*/
1973 0, /*tp_setattr*/
1974 0, /*tp_compare*/
1975 0, /*tp_repr*/
1976 &value_object_as_number, /*tp_as_number*/
1977 0, /*tp_as_sequence*/
1978 &value_object_as_mapping, /*tp_as_mapping*/
88d4aea7 1979 valpy_hash, /*tp_hash*/
5374244e 1980 valpy_call, /*tp_call*/
f9176c46
PA
1981 valpy_str, /*tp_str*/
1982 0, /*tp_getattro*/
1983 0, /*tp_setattro*/
1984 0, /*tp_as_buffer*/
9a2b4c1b
MS
1985 Py_TPFLAGS_DEFAULT | Py_TPFLAGS_CHECKTYPES
1986 | Py_TPFLAGS_BASETYPE, /*tp_flags*/
f9176c46
PA
1987 "GDB value object", /* tp_doc */
1988 0, /* tp_traverse */
1989 0, /* tp_clear */
1990 valpy_richcompare, /* tp_richcompare */
1991 0, /* tp_weaklistoffset */
1992 0, /* tp_iter */
1993 0, /* tp_iternext */
08c637de
TJB
1994 value_object_methods, /* tp_methods */
1995 0, /* tp_members */
def2b000 1996 value_object_getset, /* tp_getset */
08c637de
TJB
1997 0, /* tp_base */
1998 0, /* tp_dict */
1999 0, /* tp_descr_get */
2000 0, /* tp_descr_set */
2001 0, /* tp_dictoffset */
2002 0, /* tp_init */
2003 0, /* tp_alloc */
2004 valpy_new /* tp_new */
f9176c46 2005};
This page took 1.164032 seconds and 4 git commands to generate.