From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 17363 invoked by alias); 9 Oct 2014 15:54:33 -0000 Mailing-List: contact gdb-patches-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sourceware.org Received: (qmail 17353 invoked by uid 89); 9 Oct 2014 15:54:32 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-3.1 required=5.0 tests=AWL,BAYES_00,RCVD_IN_DNSWL_LOW,SPF_PASS,T_RP_MATCHES_RCVD autolearn=ham version=3.3.2 X-HELO: mail-ig0-f201.google.com Received: from mail-ig0-f201.google.com (HELO mail-ig0-f201.google.com) (209.85.213.201) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with (AES128-SHA encrypted) ESMTPS; Thu, 09 Oct 2014 15:54:31 +0000 Received: by mail-ig0-f201.google.com with SMTP id h15so712689igd.2 for ; Thu, 09 Oct 2014 08:54:29 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:subject:date:message-id:mime-version :content-type; bh=4r6EBiTcjUyJ0AWAqE35A7ySQKzfJbMTD6VkmHLWA9M=; b=CSpNReeBcEyYiFwZK8N5t1jWsQiAzhm9U+W5oN3X7s6kHUhIAkxIkhfMtChtKZpcbT +jHbqOEqXuwEl2BLxDzSQGzVdM77PhzG7vaml61W6CHO3SHxnKeRQvLdVZ59ZeBsXhmz E6LvVs2Niw/xHHiT2uqU3cgQeVNv1UbYsDtZsYHAQIDlNwAR6IHxFhDtZxkyAcDbzB/e fBVlOVBdYUSP+40OpCgKwxljThvSJ9LXJdLyPoyMug7iZ0jxIV53kdNjTqw5BHKLQbp4 3+MQ4ZG1mov8fJMiacrldbwv1dBwqBAnx7udfuDJCyEgdQq5sVq1labHiSeKLzGULBhv cZHg== X-Gm-Message-State: ALoCoQnJAJeWGgmIhbiRiVsJm1oh4d4JLA3bVw9nQWNJj4TCcG+U6Kujq+p5gDtOqD7OflsBs/QlIClMzWkHTXMZ/FLBv+QlG9a4eEgoUUmbMoBwc/CQfBnRJZqY/vB4w8trV6vGryh4QsiaiRz1aV/eWCxxH9neThoNULDv3uzsWi0ZhPdCtBY= X-Received: by 10.42.105.201 with SMTP id w9mr4494610ico.19.1412870068933; Thu, 09 Oct 2014 08:54:28 -0700 (PDT) Received: from corpmail-nozzle1-2.hot.corp.google.com ([100.108.1.103]) by gmr-mx.google.com with ESMTPS id n22si183532yhd.1.2014.10.09.08.54.28 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 09 Oct 2014 08:54:28 -0700 (PDT) Received: from ruffy.mtv.corp.google.com ([172.17.128.44]) by corpmail-nozzle1-2.hot.corp.google.com with ESMTPS id RKqnKc5n.1; Thu, 09 Oct 2014 08:54:28 -0700 From: Doug Evans To: gdb-patches@sourceware.org Subject: [PATCH] Remove duplicate code to init python objfile/progspace objects Date: Thu, 09 Oct 2014 15:54:00 -0000 Message-ID: MIME-Version: 1.0 Content-Type: text/plain X-IsSubscribed: yes X-SW-Source: 2014-10/txt/msg00206.txt.bz2 Hi. This patch just removes some duplicate code. 2014-10-09 Doug Evans * py-objfile.c (objfpy_initialize): New function. (objfpy_new, objfile_to_objfile_object): Call it. * py-progspace.c (pspy_initialize): New function. (pspy_new, pspace_to_pspace_object): Call it. diff --git a/gdb/python/py-objfile.c b/gdb/python/py-objfile.c index 5d00d62..df29691 100644 --- a/gdb/python/py-objfile.c +++ b/gdb/python/py-objfile.c @@ -74,6 +74,33 @@ objfpy_dealloc (PyObject *o) Py_TYPE (self)->tp_free (self); } +/* Initialize an objfile_object. + The result is a boolean indicating success. */ + +static int +objfpy_initialize (objfile_object *self) +{ + self->objfile = NULL; + + self->printers = PyList_New (0); + if (self->printers == NULL) + return 0; + + self->frame_filters = PyDict_New (); + if (self->frame_filters == NULL) + return 0; + + self->type_printers = PyList_New (0); + if (self->type_printers == NULL) + return 0; + + self->xmethods = PyList_New (0); + if (self->xmethods == NULL) + return 0; + + return 1; +} + static PyObject * objfpy_new (PyTypeObject *type, PyObject *args, PyObject *keywords) { @@ -81,36 +108,13 @@ objfpy_new (PyTypeObject *type, PyObject *args, PyObject *keywords) if (self) { - self->objfile = NULL; - - self->printers = PyList_New (0); - if (!self->printers) - { - Py_DECREF (self); - return NULL; - } - - self->frame_filters = PyDict_New (); - if (!self->frame_filters) - { - Py_DECREF (self); - return NULL; - } - - self->type_printers = PyList_New (0); - if (!self->type_printers) - { - Py_DECREF (self); - return NULL; - } - - self->xmethods = PyList_New (0); - if (self->xmethods == NULL) + if (!objfpy_initialize (self)) { Py_DECREF (self); return NULL; } } + return (PyObject *) self; } @@ -280,6 +284,7 @@ py_free_objfile (struct objfile *objfile, void *datum) representing OBJFILE. If the object has already been created, return it. Otherwise, create it. Return NULL and set the Python error on failure. */ + PyObject * objfile_to_objfile_object (struct objfile *objfile) { @@ -291,36 +296,13 @@ objfile_to_objfile_object (struct objfile *objfile) object = PyObject_New (objfile_object, &objfile_object_type); if (object) { - object->objfile = objfile; - - object->printers = PyList_New (0); - if (!object->printers) - { - Py_DECREF (object); - return NULL; - } - - object->frame_filters = PyDict_New (); - if (!object->frame_filters) - { - Py_DECREF (object); - return NULL; - } - - object->type_printers = PyList_New (0); - if (!object->type_printers) - { - Py_DECREF (object); - return NULL; - } - - object->xmethods = PyList_New (0); - if (object->xmethods == NULL) + if (!objfpy_initialize (object)) { Py_DECREF (object); return NULL; } + object->objfile = objfile; set_objfile_data (objfile, objfpy_objfile_data_key, object); } } diff --git a/gdb/python/py-progspace.c b/gdb/python/py-progspace.c index b0092c5..4280032 100644 --- a/gdb/python/py-progspace.c +++ b/gdb/python/py-progspace.c @@ -82,6 +82,33 @@ pspy_dealloc (PyObject *self) Py_TYPE (self)->tp_free (self); } +/* Initialize a pspace_object. + The result is a boolean indicating success. */ + +static int +pspy_initialize (pspace_object *self) +{ + self->pspace = NULL; + + self->printers = PyList_New (0); + if (self->printers == NULL) + return 0; + + self->frame_filters = PyDict_New (); + if (self->frame_filters == NULL) + return 0; + + self->type_printers = PyList_New (0); + if (self->type_printers == NULL) + return 0; + + self->xmethods = PyList_New (0); + if (self->xmethods == NULL) + return 0; + + return 1; +} + static PyObject * pspy_new (PyTypeObject *type, PyObject *args, PyObject *keywords) { @@ -89,36 +116,13 @@ pspy_new (PyTypeObject *type, PyObject *args, PyObject *keywords) if (self) { - self->pspace = NULL; - - self->printers = PyList_New (0); - if (!self->printers) - { - Py_DECREF (self); - return NULL; - } - - self->frame_filters = PyDict_New (); - if (!self->frame_filters) - { - Py_DECREF (self); - return NULL; - } - - self->type_printers = PyList_New (0); - if (!self->type_printers) - { - Py_DECREF (self); - return NULL; - } - - self->xmethods = PyList_New (0); - if (self->xmethods == NULL) + if (!pspy_initialize (self)) { Py_DECREF (self); return NULL; } } + return (PyObject *) self; } @@ -296,36 +300,13 @@ pspace_to_pspace_object (struct program_space *pspace) object = PyObject_New (pspace_object, &pspace_object_type); if (object) { - object->pspace = pspace; - - object->printers = PyList_New (0); - if (!object->printers) - { - Py_DECREF (object); - return NULL; - } - - object->frame_filters = PyDict_New (); - if (!object->frame_filters) - { - Py_DECREF (object); - return NULL; - } - - object->type_printers = PyList_New (0); - if (!object->type_printers) - { - Py_DECREF (object); - return NULL; - } - - object->xmethods = PyList_New (0); - if (object->xmethods == NULL) + if (!pspy_initialize (object)) { Py_DECREF (object); return NULL; } + object->pspace = pspace; set_program_space_data (pspace, pspy_pspace_data_key, object); } }