From patchwork Thu Aug 15 16:46:01 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Terekhov, Mikhail via Gdb-patches" X-Patchwork-Id: 34121 Received: (qmail 11889 invoked by alias); 15 Aug 2019 16:46:08 -0000 Mailing-List: contact gdb-patches-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sourceware.org Delivered-To: mailing list gdb-patches@sourceware.org Received: (qmail 11879 invoked by uid 89); 15 Aug 2019 16:46:08 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-22.6 required=5.0 tests=AWL, BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, RCVD_IN_DNSWL_NONE, SPF_PASS autolearn=ham version=3.3.1 spammy=H*MI:google X-HELO: mail-qt1-f201.google.com Received: from mail-qt1-f201.google.com (HELO mail-qt1-f201.google.com) (209.85.160.201) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Thu, 15 Aug 2019 16:46:05 +0000 Received: by mail-qt1-f201.google.com with SMTP id 91so1759536qtf.13 for ; Thu, 15 Aug 2019 09:46:05 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=date:message-id:mime-version:subject:from:to:cc; bh=3dQ7PkbP4wcs0F1i3ctiMPeUyUvuhzFS3YB8n5c1m2Q=; b=Gbso65o8/6zXh1pjGD+7XIS+GYl/J1KKW8YWFS+AyODz2wUrGrOCMRITnseNLx8tr/ irjTSgRZXr0uyeJKQkeov/yi4QLunWvmQT+dFvBLjj+44nZ4IYJ7evUJsLLfOOksSd1E vzTYc+bgZTaD+VdHDNKOPLtiO6VgkwaWC1JZ3fZGgEjkaU7i8TaW4lRs+W+5K0Fptlpb DAsfx9k8jOO84b39UV2IBPF66uQBixwchN1XjgPRKeQiOrKzpNsgr2rFw+XcpSxmG8X5 uuXey5oRepmr8flqpKuF+7qO2/UBGAe3+/nCGOHrCIhSR8LZFWkcvKfD9/AG4amsYKu/ LkSA== Date: Thu, 15 Aug 2019 11:46:01 -0500 Message-Id: <20190815164601.114915-1-cbiesinger@google.com> Mime-Version: 1.0 Subject: [PATCH] Rename internal Python functions to start with an underscore X-Patchwork-Original-From: "Christian Biesinger via gdb-patches" From: "Terekhov, Mikhail via Gdb-patches" Reply-To: Christian Biesinger To: gdb-patches@sourceware.org Cc: Christian Biesinger X-IsSubscribed: yes I could not tell if GdbSetPythonDirectory is internal or not because I could not find any references to it, so I left it as-is. Tested by running the testsuite on gdb.python/*.exp; everything still passes. 2019-08-15 Christian Biesinger * python/lib/gdb/__init__.py (GdbOutputFile): Rename to have a leading underscore. (GdbOutputErrorFile): Likewise. (global scope): Adjust constructor calls to GdbOutput{,Error}File accordingly. (execute_unwinders): Rename to have a leading underscore. (auto_load_packages): Likewise. (global scope): Adjust call to auto_load_packages accordingly. (GdbSetPythonDirectory): Likewise. * python/py-unwind.c (pyuw_sniffer): Call _execute_unwinders instead of execute_unwinders. gdb/testsuite/ChangeLog: 2019-08-15 Christian Biesinger * gdb.python/python.exp: Expect a leading underscore on GdbOutput{,Error}File. --- gdb/python/lib/gdb/__init__.py | 16 ++++++++-------- gdb/python/py-unwind.c | 6 +++--- gdb/testsuite/gdb.python/python.exp | 4 ++-- 3 files changed, 13 insertions(+), 13 deletions(-) diff --git a/gdb/python/lib/gdb/__init__.py b/gdb/python/lib/gdb/__init__.py index af74df80c8..8af9e47117 100644 --- a/gdb/python/lib/gdb/__init__.py +++ b/gdb/python/lib/gdb/__init__.py @@ -43,17 +43,17 @@ class _GdbFile (object): def flush(self): flush() -class GdbOutputFile (_GdbFile): +class _GdbOutputFile (_GdbFile): def write(self, s): write(s, stream=STDOUT) -sys.stdout = GdbOutputFile() +sys.stdout = _GdbOutputFile() -class GdbOutputErrorFile (_GdbFile): +class _GdbOutputErrorFile (_GdbFile): def write(self, s): write(s, stream=STDERR) -sys.stderr = GdbOutputErrorFile() +sys.stderr = _GdbOutputErrorFile() # Default prompt hook does nothing. prompt_hook = None @@ -74,7 +74,7 @@ frame_filters = {} # Initial frame unwinders. frame_unwinders = [] -def execute_unwinders(pending_frame): +def _execute_unwinders(pending_frame): """Internal function called from GDB to execute all unwinders. Runs each currently enabled unwinder until it finds the one that @@ -124,7 +124,7 @@ packages = [ # manually iterate the list, collating the Python files in each module # path. Construct the module name, and import. -def auto_load_packages(): +def _auto_load_packages(): for package in packages: location = os.path.join(os.path.dirname(__file__), package) if os.path.exists(location): @@ -144,7 +144,7 @@ def auto_load_packages(): except: sys.stderr.write (traceback.format_exc() + "\n") -auto_load_packages() +_auto_load_packages() def GdbSetPythonDirectory(dir): """Update sys.path, reload gdb and auto-load packages.""" @@ -161,7 +161,7 @@ def GdbSetPythonDirectory(dir): # note that reload overwrites the gdb module without deleting existing # attributes reload(__import__(__name__)) - auto_load_packages() + _auto_load_packages() def current_progspace(): "Return the current Progspace." diff --git a/gdb/python/py-unwind.c b/gdb/python/py-unwind.c index 08c3aff928..7cb9fa16a7 100644 --- a/gdb/python/py-unwind.c +++ b/gdb/python/py-unwind.c @@ -507,16 +507,16 @@ pyuw_sniffer (const struct frame_unwind *self, struct frame_info *this_frame, /* Run unwinders. */ if (gdb_python_module == NULL - || ! PyObject_HasAttrString (gdb_python_module, "execute_unwinders")) + || ! PyObject_HasAttrString (gdb_python_module, "_execute_unwinders")) { PyErr_SetString (PyExc_NameError, - "Installation error: gdb.execute_unwinders function " + "Installation error: gdb._execute_unwinders function " "is missing"); gdbpy_print_stack (); return 0; } gdbpy_ref<> pyo_execute (PyObject_GetAttrString (gdb_python_module, - "execute_unwinders")); + "_execute_unwinders")); if (pyo_execute == NULL) { gdbpy_print_stack (); diff --git a/gdb/testsuite/gdb.python/python.exp b/gdb/testsuite/gdb.python/python.exp index fe55234060..c795814a65 100644 --- a/gdb/testsuite/gdb.python/python.exp +++ b/gdb/testsuite/gdb.python/python.exp @@ -288,8 +288,8 @@ gdb_test "python print (symtab\[1\]\[0\].symtab)" "None" "test decode_line *0 fi gdb_test "python print (symtab\[1\]\[0\].pc)" "0" "test decode_line *0 pc" # gdb.write -gdb_test "python print (sys.stderr)" ".*gdb.GdbOutputErrorFile (instance|object) at.*" "test stderr location" -gdb_test "python print (sys.stdout)" ".*gdb.GdbOutputFile (instance|object) at.*" "test stdout location" +gdb_test "python print (sys.stderr)" ".*gdb._GdbOutputErrorFile (instance|object) at.*" "test stderr location" +gdb_test "python print (sys.stdout)" ".*gdb._GdbOutputFile (instance|object) at.*" "test stdout location" gdb_test "python gdb.write(\"Foo\\n\")" "Foo" "test default write" gdb_test "python gdb.write(\"Error stream\\n\", stream=gdb.STDERR)" "Error stream" "test stderr write" gdb_test "python gdb.write(\"Normal stream\\n\", stream=gdb.STDOUT)" "Normal stream" "test stdout write"