From patchwork Thu Jan 3 13:00:33 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: =?utf-8?b?0JTQuNC70Y/QvSDQn9Cw0LvQsNGD0LfQvtCy?= X-Patchwork-Id: 30952 Received: (qmail 29357 invoked by alias); 3 Jan 2019 13:00:41 -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 28629 invoked by uid 89); 3 Jan 2019 13:00:41 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-26.9 required=5.0 tests=BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, RCVD_IN_DNSWL_NONE, SPF_HELO_PASS autolearn=ham version=3.3.2 spammy=Gold, sk:master_, printer, OTHER X-HELO: mail.aegee.org Received: from mail.aegee.org (HELO mail.aegee.org) (144.76.142.78) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Thu, 03 Jan 2019 13:00:37 +0000 Authentication-Results: mail.aegee.org/x03D0Xqt023140; auth=pass (PLAIN) smtp.auth=didopalauzov DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=aegee.org; s=k4096; t=1546520434; i=dkim+MSA-tls@aegee.org; r=y; bh=y8Mjx4WLCSzxUOZ4Z98QshSSpyAJfslekNJN4jeDi3U=; h=Subject:From:To:Date; b=Hx1mWJos0LJ2W9gTHRp0xop8qRXXi18HQkOoeAe1U7RbPe5497zfQxBm1D0S3lMg9 21g4IIpwZZcKLkK8cBOt2z56M8XBXIfBAELR3BcOuWhbcgzwEI3lSuYiybBN/rNeLH j7BKabZXttMMnqMJ2WxcW8atHOgJAyKPyKtADh55iB0YqZwUak12oxKiaOUFMNsfs7 oFLSl8yxceUwghUX90JCUqbSEtLCH6QKztJRLTzTqIYL/q05H9wXu1pmAbx1Q58cKW jvaQqIBZrG78sxqoWYDmuHP56L7qY2eLu8HhIawlqWkgt8bHRAXOPGmKsgEajmcEHw mpkVi+Q5zfIsqvc9nBRIQSQZkYSK+YCV1z+aHYc4UY3xDEogOdHYADFDjlVmKsMxER aV96Uch2Nx6csYgbr4u9Y+Wmv1tsgMhKimmUdIVVrCw21b6GNYSd2KFA24f4j6xw+7 HHggvmIeVGDRXrWOooiuQoRPNSqDtWpmLowGYxwFaG9HJO4/JXTizrJNfYFXdGP4yp MeR+ZybAXKsukhnUD7OTxZ3hN0OKIsKtoGocn4nSSOx+V2zLGzDry8lsdM3q2xyIuf PV9IUvG0RFRQC+LI2BlNsLMbgWIsy8FcLqdTCeyMEJGOaSj2IH0UrY8qz4Cq3iF6wF pT/nUceZtXLE/R/0pQgca4Ug= Authentication-Results: mail.aegee.org/x03D0Xqt023140; dkim=none Received: from Tylan (adsl-84-227-98-226.adslplus.ch [84.227.98.226]) (authenticated bits=0) by mail.aegee.org (8.15.2/8.15.2) with ESMTPSA id x03D0Xqt023140 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NO) for ; Thu, 3 Jan 2019 13:00:34 GMT Message-ID: <6a013734fc3ce97e061fa74f0f25d7926422bba2.camel@aegee.org> Subject: compress python code From: =?UTF-8?Q?=D0=94=D0=B8=D0=BB=D1=8F=D0=BD_?= =?UTF-8?Q?=D0=9F=D0=B0=D0=BB=D0=B0=D1=83=D0=B7=D0=BE=D0=B2?= To: gdb-patches@sourceware.org Date: Thu, 03 Jan 2019 13:00:33 +0000 User-Agent: Evolution 3.31.4 Mime-Version: 1.0 X-IsSubscribed: yes Some rewritings on python code, that make it shorter diff --git a/etc/update-copyright.py b/etc/update-copyright.py index 4579fcd8b1..6546c963b3 100755 --- a/etc/update-copyright.py +++ b/etc/update-copyright.py @@ -162,9 +162,7 @@ class GenericFilter: if filename in self.fossilised_files: return True # Only touch current current ChangeLogs. - if filename != 'ChangeLog' and filename.find ('ChangeLog') >= 0: - return True - return False + return filename != 'ChangeLog' and filename.find ('ChangeLog') >= 0: def by_package_author (self, dir, filename): return filename in self.own_files diff --git a/gdb/contrib/cleanup_check.py b/gdb/contrib/cleanup_check.py index be6babbe94..89ed5b9b33 100644 --- a/gdb/contrib/cleanup_check.py +++ b/gdb/contrib/cleanup_check.py @@ -34,9 +34,7 @@ def is_cleanup_type(return_type): return False if not isinstance(return_type.dereference, gcc.RecordType): return False - if str(return_type.dereference.name) == 'cleanup': - return True - return False + return str(return_type.dereference.name) == 'cleanup' def is_constructor(decl): "Return True if the function DECL is a cleanup constructor; False otherwise" @@ -130,7 +128,7 @@ class MasterCleanup(object): return True # If SELF is empty but OTHER has some cleanups, then consider # that a change as well. - if len(self.cleanups) == 0 and len(other.cleanups) > 0: + if not self.cleanups and other.cleanups: log('merging non-empty other', 4) self.cleanups = other.cleanups[:] return True @@ -183,7 +181,7 @@ class MasterCleanup(object): # Check whether SELF is empty. def isempty(self): log('isempty: len = %d' % len(self.cleanups), 4) - return len(self.cleanups) == 0 + return not self.cleanups # Emit informational warnings about the cleanup stack. def inform(self): @@ -240,12 +238,11 @@ class CleanupChecker: if not master_cleanup.verify(curloc, stmt.retval): gcc.permerror(curloc, 'constructor does not return master cleanup') - elif not self.is_special_constructor: - if not master_cleanup.isempty(): - if curloc not in self.bad_returns: - gcc.permerror(curloc, 'cleanup stack is not empty at return') - self.bad_returns.add(curloc) - master_cleanup.inform() + elif not self.is_special_constructor and not master_cleanup.isempty(): + if curloc not in self.bad_returns: + gcc.permerror(curloc, 'cleanup stack is not empty at return') + self.bad_returns.add(curloc) + master_cleanup.inform() # Traverse a basic block, updating the master cleanup information # and propagating to other blocks. diff --git a/gdb/contrib/test_pubnames_and_indexes.py b/gdb/contrib/test_pubnames_and_indexes.py index 095fedd748..792e1724ee 100644 --- a/gdb/contrib/test_pubnames_and_indexes.py +++ b/gdb/contrib/test_pubnames_and_indexes.py @@ -64,7 +64,7 @@ def get_pub_info(filename, readelf_option): and fields[1].strip() == 'Name'): in_list = True # Either a blank-line or a new Length field terminates the current section. - elif (len(fields) == 0 or fields[0] == 'Length:'): + elif not fields or fields[0] == 'Length:': in_list = False; elif (in_list): pubnames.append(fields[1].strip()) @@ -95,11 +95,11 @@ def get_gdb_index(filename): def CheckSets(list0, list1, name0, name1): """Report any setwise differences between the two lists""" - if len(list0) == 0 or len(list1) == 0: + if not list0 or not list1: return False difference0 = set(list0) - set(list1) - if len(difference0) != 0: + if difference0: print "Elements in " + name0 + " but not " + name1 + ": (", print len(difference0), print ")" @@ -107,14 +107,14 @@ def CheckSets(list0, list1, name0, name1): print " " + element difference1 = set(list1) - set(list0) - if len(difference1) != 0: + if difference1: print "Elements in " + name1 + " but not " + name0 + ": (", print len(difference1), print ")" for element in difference1: print " " + element - if (len(difference0) != 0 or len(difference1) != 0): + if not difference0 or not difference1: return True print name0 + " and " + name1 + " are identical." @@ -182,15 +182,15 @@ def main(argv): pubs_list.sort() # Find the differences between the various indices. - if len(gold_index) == 0: + if not gold_index: print "Gold index is empty" failed |= True - if len(gdb_index) == 0: + if not gdb_index: print "Gdb index is empty" failed |= True - if len(pubs_list) == 0: + if not pubs_list: print "Pubs list is empty" failed |= True diff --git a/gdb/python/lib/gdb/FrameDecorator.py b/gdb/python/lib/gdb/FrameDecorator.py index 4eba088126..d386f6a88e 100644 --- a/gdb/python/lib/gdb/FrameDecorator.py +++ b/gdb/python/lib/gdb/FrameDecorator.py @@ -66,13 +66,9 @@ class FrameDecorator(object): limited.""" sal = frame.find_sal() - if (not sal.symtab or not sal.symtab.filename + return (not sal.symtab or not sal.symtab.filename or frame.type() == gdb.DUMMY_FRAME - or frame.type() == gdb.SIGTRAMP_FRAME): - - return True - - return False + or frame.type() == gdb.SIGTRAMP_FRAME) def elided(self): """Return any elided frames that this class might be diff --git a/gdb/python/lib/gdb/command/explore.py b/gdb/python/lib/gdb/command/explore.py index f782a9712b..f724f58b59 100644 --- a/gdb/python/lib/gdb/command/explore.py +++ b/gdb/python/lib/gdb/command/explore.py @@ -521,7 +521,7 @@ class CompoundExplorer(object): CompoundExplorer._print_fields(print_list) print ("") - if len(choice_to_compound_field_map) > 0: + if choice_to_compound_field_map: choice = raw_input("Enter the field number of choice: ") if choice in choice_to_compound_field_map: if is_child: @@ -598,10 +598,9 @@ class ExploreUtils(object): Raises: gdb.GdbError if adequate arguments are not passed. """ - if len(arg_str) < 1: + if not arg_str: raise gdb.GdbError("ERROR: '%s' requires an argument." % name) - return False else: return True diff --git a/gdb/python/lib/gdb/command/frame_filters.py b/gdb/python/lib/gdb/command/frame_filters.py index 9d28f845b7..91cd0af73d 100644 --- a/gdb/python/lib/gdb/command/frame_filters.py +++ b/gdb/python/lib/gdb/command/frame_filters.py @@ -60,7 +60,7 @@ Usage: info frame-filters""" key=lambda i: gdb.frames.get_priority(i[1]), reverse=True) - if len(sorted_frame_filters) == 0: + if not sorted_frame_filters: return 0 print(title) diff --git a/gdb/python/lib/gdb/command/pretty_printers.py b/gdb/python/lib/gdb/command/pretty_printers.py index c1bdf68fe0..de704cb6c1 100644 --- a/gdb/python/lib/gdb/command/pretty_printers.py +++ b/gdb/python/lib/gdb/command/pretty_printers.py @@ -75,10 +75,7 @@ def parse_printer_regexps(arg): def printer_enabled_p(printer): """Internal utility to see if printer (or subprinter) is enabled.""" - if hasattr(printer, "enabled"): - return printer.enabled - else: - return True + return getattr(printer, "enabled", True) class InfoPrettyPrinter(gdb.Command): diff --git a/gdb/python/lib/gdb/frames.py b/gdb/python/lib/gdb/frames.py index d8e4be8d36..189da7e41a 100644 --- a/gdb/python/lib/gdb/frames.py +++ b/gdb/python/lib/gdb/frames.py @@ -179,7 +179,7 @@ def execute_frame_filters(frame, frame_low, frame_high): # Check to see if there are any frame-filters. If not, just # return None and let default backtrace printing occur. - if len(sorted_list) == 0: + if not sorted_list: return None frame_iterator = FrameIterator(frame) diff --git a/gdb/system-gdbinit/elinos.py b/gdb/system-gdbinit/elinos.py index b303342c39..cbe4ab5143 100644 --- a/gdb/system-gdbinit/elinos.py +++ b/gdb/system-gdbinit/elinos.py @@ -83,7 +83,7 @@ def elinos_init(): solib_dirs += ["%s/%s" % (dir, "xenomai-build/usr/realtime/lib")] - if len(solib_dirs) != 0: + if solib_dirs: gdb.execute("set solib-search-path %s" % ":".join(solib_dirs)) diff --git a/gdb/testsuite/analyze-racy-logs.py b/gdb/testsuite/analyze-racy-logs.py index 9036c9b789..843e544718 100755 --- a/gdb/testsuite/analyze-racy-logs.py +++ b/gdb/testsuite/analyze-racy-logs.py @@ -72,8 +72,7 @@ dictionary referenced by DIC.""" # Remove tail parentheses. These are likely to be '(timeout)' # and other extra information that will only confuse us. test_name = re.sub ('(\s+)?\(.*$', '', test_name) - if result not in dic.keys (): - dic[result] = set () + dic.setdefault(result, set ()) if test_name in dic[result]: # If the line is already present in the dictionary, then # we include a unique identifier in the end of it, in the diff --git a/gdb/testsuite/gdb.perf/lib/perftest/reporter.py b/gdb/testsuite/gdb.perf/lib/perftest/reporter.py index 4fa242ebc5..edf494c0fb 100644 --- a/gdb/testsuite/gdb.perf/lib/perftest/reporter.py +++ b/gdb/testsuite/gdb.perf/lib/perftest/reporter.py @@ -62,7 +62,7 @@ class TextReporter(Reporter): self.txt_log = None def report(self, test_name, measurement_name, data_points): - if len(data_points) == 0: + if not data_points: self.txt_sum.write("%s %s *no data recorded*\n" % ( test_name, measurement_name)) return