Sign Up
Log In
Log In
or
Sign Up
Places
All Projects
Status Monitor
Collapse sidebar
home:tabraham1:branches:home:jeff_mahoney:crash-python:devel
gdb
0015-py-type-make-tp_richcompare-lighterweight....
Overview
Repositories
Revisions
Requests
Users
Attributes
Meta
File 0015-py-type-make-tp_richcompare-lighterweight.patch of Package gdb
From e94a44c45cbf9a008ceccb7e0efb48e2c2e9f2d1 Mon Sep 17 00:00:00 2001 From: Jeff Mahoney <jeffm@suse.com> Date: Wed, 10 Aug 2022 12:08:34 -0400 Subject: [PATCH 15/17] py-type: make tp_richcompare lighterweight Type's richcompare method uses types_deeply_equal which exhaustively compares the type, including through pointers. For projects with large, linked structures this can make the comparison time consuming. Looking at the GDB code, types_equal is called more frequently than types_deeply_equal, so this commit changes the regular tp_richcompare ==/!= comparison to use types_equal and adds a new is_deeply_equal method to gdb.Type. --- gdb/python/py-type.c | 42 ++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 40 insertions(+), 2 deletions(-) diff --git a/gdb/python/py-type.c b/gdb/python/py-type.c index 58d53f4429d..d9d534a5f85 100644 --- a/gdb/python/py-type.c +++ b/gdb/python/py-type.c @@ -1071,8 +1071,43 @@ typy_str (PyObject *self) host_charset (), NULL); } -/* Implement the richcompare method. */ +static PyObject * +typy_deeply_equal (PyObject *self, PyObject *other) +{ + bool result = false; + struct type *type1 = type_object_to_type (self); + struct type *type2 = type_object_to_type (other); + + /* We can only compare ourselves to another Type object, and only + for equality or inequality. */ + if (type2 == NULL) + { + PyErr_Format (PyExc_TypeError, "Argument must be a gdb.Type object"); + return NULL; + } + if (type1 == type2) + result = true; + else + { + try + { + result = types_deeply_equal (type1, type2); + } + catch (const gdb_exception &except) + { + /* If there is a GDB exception, a comparison is not capable + (or trusted), so exit. */ + GDB_PY_HANDLE_EXCEPTION (except); + } + } + + if (result) + Py_RETURN_TRUE; + Py_RETURN_FALSE; +} + +/* Implement the richcompare method. */ static PyObject * typy_richcompare (PyObject *self, PyObject *other, int op) { @@ -1094,7 +1129,7 @@ typy_richcompare (PyObject *self, PyObject *other, int op) { try { - result = types_deeply_equal (type1, type2); + result = types_equal (type1, type2); } catch (const gdb_exception &except) { @@ -1603,6 +1638,9 @@ Each field is a gdb.Field object." }, { "volatile", typy_volatile, METH_NOARGS, "volatile () -> Type\n\ Return a volatile variant of this type" }, + { "is_deeply_equal", typy_deeply_equal, METH_VARARGS, + "is_deeply_equal (Type) -> bool\n\ +Deeply compare another Type including member structures and pointer types" }, { NULL } }; -- 2.37.2
Locations
Projects
Search
Status Monitor
Help
OpenBuildService.org
Documentation
API Documentation
Code of Conduct
Contact
Support
@OBShq
Terms
openSUSE Build Service is sponsored by
The Open Build Service is an
openSUSE project
.
Sign Up
Log In
Places
Places
All Projects
Status Monitor