From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 105289 invoked by alias); 18 May 2016 19:18:06 -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 105274 invoked by uid 89); 18 May 2016 19:18:06 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-1.9 required=5.0 tests=BAYES_00,SPF_PASS autolearn=ham version=3.3.2 spammy= X-HELO: usplmg21.ericsson.net Received: from usplmg21.ericsson.net (HELO usplmg21.ericsson.net) (198.24.6.65) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with (AES256-SHA encrypted) ESMTPS; Wed, 18 May 2016 19:18:03 +0000 Received: from EUSAAHC008.ericsson.se (Unknown_Domain [147.117.188.96]) by usplmg21.ericsson.net (Symantec Mail Security) with SMTP id 14.EF.03614.7BFBC375; Wed, 18 May 2016 21:17:11 +0200 (CEST) Received: from [142.133.110.144] (147.117.188.8) by smtp-am.internal.ericsson.com (147.117.188.98) with Microsoft SMTP Server id 14.3.248.2; Wed, 18 May 2016 15:18:01 -0400 Subject: Re: [PATCH v3 06/34] Introduce interpreter factories To: Pedro Alves , References: <1462538104-19109-1-git-send-email-palves@redhat.com> <1462538104-19109-7-git-send-email-palves@redhat.com> From: Simon Marchi Message-ID: <573CBFE8.6090603@ericsson.com> Date: Wed, 18 May 2016 19:18:00 -0000 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:38.0) Gecko/20100101 Thunderbird/38.6.0 MIME-Version: 1.0 In-Reply-To: <1462538104-19109-7-git-send-email-palves@redhat.com> Content-Type: text/plain; charset="windows-1252" Content-Transfer-Encoding: 7bit X-IsSubscribed: yes X-SW-Source: 2016-05/txt/msg00312.txt.bz2 On 16-05-06 08:34 AM, Pedro Alves wrote: > +/* See interps.h. */ > + > +struct interp * > +interp_lookup (const char *name) > +{ > + struct ui *ui = current_ui; > + struct interp_factory *factory; > + struct interp *interp; > + int ix; > + > + if (name == NULL || strlen (name) == 0) > + return NULL; > + > + /* Only create each interpreter once per top level. */ > + interp = interp_lookup_existing (name); > + if (interp != NULL) > + return interp; > + > + for (ix = 0; > + VEC_iterate (interp_factory_p, interpreter_factories, ix, factory); > + ++ix) > + if (strcmp (factory->name, name) == 0) > + { > + interp = factory->func (name, ui); > + interp_add (interp); > + return interp; > + } > + > + return NULL; > +} > + I think there are some opportunities to reduce the number of functions that directly access global state. For example, I think it would be clearer if interp_lookup took a struct ui* as argument instead of accessing current_ui. It would show that it's used to lookup an interpreter by name in a ui. Similarly, it calls interp_lookup_existing and interp_add, which both use get_current_interp_info(), which is essentially accessing current_ui. I believe it would be easier to follow if some caller provided the struct ui and it was passed down by parameters.