From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 12224 invoked by alias); 30 Aug 2013 14:40:23 -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 12212 invoked by uid 89); 30 Aug 2013 14:40:22 -0000 Received: from mga11.intel.com (HELO mga11.intel.com) (192.55.52.93) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Fri, 30 Aug 2013 14:40:22 +0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-2.8 required=5.0 tests=AWL,BAYES_00,KHOP_THREADED,RDNS_NONE,TO_NO_BRKTS_NORDNS autolearn=no version=3.3.2 X-HELO: mga11.intel.com Received: from fmsmga001.fm.intel.com ([10.253.24.23]) by fmsmga102.fm.intel.com with ESMTP; 30 Aug 2013 07:40:20 -0700 X-ExtLoop1: 1 Received: from irvmail001.ir.intel.com ([163.33.26.43]) by fmsmga001.fm.intel.com with ESMTP; 30 Aug 2013 07:40:19 -0700 Received: from ulliclel004.iul.intel.com (ulliclel004.iul.intel.com [172.28.50.125]) by irvmail001.ir.intel.com (8.14.3/8.13.6/MailSET/Hub) with ESMTP id r7UEeH28004959; Fri, 30 Aug 2013 15:40:18 +0100 Received: from ulliclel004.iul.intel.com (ulliclel004.iul.intel.com [127.0.0.1]) by ulliclel004.iul.intel.com (8.13.8/8.12.8/MailSET/client) with ESMTP id r7UEeGgf015564; Fri, 30 Aug 2013 16:40:16 +0200 Received: (from sagovic@localhost) by ulliclel004.iul.intel.com (8.13.8/8.13.1/Submit) id r7UEeAmt015563; Fri, 30 Aug 2013 16:40:10 +0200 From: Sanimir Agovic To: gdb-patches@sourceware.org Cc: pmuldoon@redhat.com Subject: [PATCH 1/2] python: disallow python code to instanciate certain types Date: Fri, 30 Aug 2013 14:40:00 -0000 Message-Id: <1377873604-15519-2-git-send-email-sanimir.agovic@intel.com> In-Reply-To: <1377873604-15519-1-git-send-email-sanimir.agovic@intel.com> References: <1377873604-15519-1-git-send-email-sanimir.agovic@intel.com> X-SW-Source: 2013-08/txt/msg00916.txt.bz2 I simply followed the pattern used for gdb.Type and assign NULL to tp_new thus the type cannot be created from python code. before> (gdb) python gdb.Frame() (gdb) after> (gdb) python gdb.Frame() Traceback (most recent call last): File "", line 1, in TypeError: cannot create 'gdb.Frame' instances Error while executing Python code. 2013-08-30 Sanimir Agovic python/ * py-arch.c (gdbpy_initialize_arch): Set tp_new implicitly to NULL. * py-block.c (gdbpy_initialize_blocks): Set tp_new implicitly to NULL. * py-frame.c (gdbpy_initialize_frames): Set tp_new implicitly to NULL. * py-objfile.c (objfpy_new): Remove function. (objfile_object_type): Set tp_new to NULL. * py-progspace.c (pspy_new): Remove function. (pspace_object_type): Set tp_new to NULL * py-symtab.c (gdbpy_initialize_symtabs): Set tp_new implicitly to NULL. Change-Id: Ie9ced3d27f4a0660d160f651391a97ed7af4d1ce --- gdb/python/py-arch.c | 1 - gdb/python/py-block.c | 1 - gdb/python/py-frame.c | 1 - gdb/python/py-objfile.c | 35 +---------------------------------- gdb/python/py-progspace.c | 35 +---------------------------------- gdb/python/py-symtab.c | 2 -- 6 files changed, 2 insertions(+), 73 deletions(-) diff --git a/gdb/python/py-arch.c b/gdb/python/py-arch.c index 7098a8a..464ffb3 100644 --- a/gdb/python/py-arch.c +++ b/gdb/python/py-arch.c @@ -235,7 +235,6 @@ int gdbpy_initialize_arch (void) { arch_object_data = gdbarch_data_register_post_init (arch_object_data_init); - arch_object_type.tp_new = PyType_GenericNew; if (PyType_Ready (&arch_object_type) < 0) return -1; diff --git a/gdb/python/py-block.c b/gdb/python/py-block.c index c74ac2c..b7a7264 100644 --- a/gdb/python/py-block.c +++ b/gdb/python/py-block.c @@ -428,7 +428,6 @@ del_objfile_blocks (struct objfile *objfile, void *datum) int gdbpy_initialize_blocks (void) { - block_object_type.tp_new = PyType_GenericNew; if (PyType_Ready (&block_object_type) < 0) return -1; diff --git a/gdb/python/py-frame.c b/gdb/python/py-frame.c index f960b08..5fd099e 100644 --- a/gdb/python/py-frame.c +++ b/gdb/python/py-frame.c @@ -620,7 +620,6 @@ frapy_richcompare (PyObject *self, PyObject *other, int op) int gdbpy_initialize_frames (void) { - frame_object_type.tp_new = PyType_GenericNew; if (PyType_Ready (&frame_object_type) < 0) return -1; diff --git a/gdb/python/py-objfile.c b/gdb/python/py-objfile.c index a954c9d..ddd6b79 100644 --- a/gdb/python/py-objfile.c +++ b/gdb/python/py-objfile.c @@ -69,39 +69,6 @@ objfpy_dealloc (PyObject *o) Py_TYPE (self)->tp_free (self); } -static PyObject * -objfpy_new (PyTypeObject *type, PyObject *args, PyObject *keywords) -{ - objfile_object *self = (objfile_object *) type->tp_alloc (type, 0); - - 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; - } - } - return (PyObject *) self; -} - PyObject * objfpy_get_printers (PyObject *o, void *ignore) { @@ -374,5 +341,5 @@ static PyTypeObject objfile_object_type = 0, /* tp_dictoffset */ 0, /* tp_init */ 0, /* tp_alloc */ - objfpy_new, /* tp_new */ + 0, /* tp_new */ }; diff --git a/gdb/python/py-progspace.c b/gdb/python/py-progspace.c index 98eeecc..6634aae 100644 --- a/gdb/python/py-progspace.c +++ b/gdb/python/py-progspace.c @@ -77,39 +77,6 @@ pspy_dealloc (PyObject *self) Py_TYPE (self)->tp_free (self); } -static PyObject * -pspy_new (PyTypeObject *type, PyObject *args, PyObject *keywords) -{ - pspace_object *self = (pspace_object *) type->tp_alloc (type, 0); - - 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; - } - } - return (PyObject *) self; -} - PyObject * pspy_get_printers (PyObject *o, void *ignore) { @@ -361,5 +328,5 @@ static PyTypeObject pspace_object_type = 0, /* tp_dictoffset */ 0, /* tp_init */ 0, /* tp_alloc */ - pspy_new, /* tp_new */ + 0, /* tp_new */ }; diff --git a/gdb/python/py-symtab.c b/gdb/python/py-symtab.c index 006946c..269feb8 100644 --- a/gdb/python/py-symtab.c +++ b/gdb/python/py-symtab.c @@ -484,11 +484,9 @@ del_objfile_sal (struct objfile *objfile, void *datum) int gdbpy_initialize_symtabs (void) { - symtab_object_type.tp_new = PyType_GenericNew; if (PyType_Ready (&symtab_object_type) < 0) return -1; - sal_object_type.tp_new = PyType_GenericNew; if (PyType_Ready (&sal_object_type) < 0) return -1; -- 1.7.1.1