From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from [87.239.111.99] (localhost [127.0.0.1]) by dev.tarantool.org (Postfix) with ESMTP id DBD3D6ECE3; Thu, 14 Jul 2022 15:10:23 +0300 (MSK) DKIM-Filter: OpenDKIM Filter v2.11.0 dev.tarantool.org DBD3D6ECE3 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=tarantool.org; s=dev; t=1657800624; bh=+PPxd/N5kpzgDP259a4vSk3N1IXuv4NrLTIWWQtqDsc=; h=Date:To:References:In-Reply-To:Subject:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To:Cc: From; b=Bb2V/jGoEW1A9W0T8WIug1L3G+mvbd/XYQiQ2zoTQPo+/1MaJgoN8897qyIMdof51 ih0jtKectpARM+pcCJkXNHUx2zz3ZUmibsAaPUFzusgA7NTm5HVHGcg3Gca6D3Ufzb //MoR4VaxNv4KXHfxcfVayYNjAh8BXAJSFYJJdeo= Received: from smtp34.i.mail.ru (smtp34.i.mail.ru [94.100.177.94]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dev.tarantool.org (Postfix) with ESMTPS id 161376ECE3 for ; Thu, 14 Jul 2022 15:10:23 +0300 (MSK) DKIM-Filter: OpenDKIM Filter v2.11.0 dev.tarantool.org 161376ECE3 Received: by smtp34.i.mail.ru with esmtpa (envelope-from ) id 1oBxfi-00058a-4J; Thu, 14 Jul 2022 15:10:22 +0300 Date: Thu, 14 Jul 2022 15:08:01 +0300 To: Maxim Kokryashkin Message-ID: References: <7539a0ac196ba192636d5f6cfc1c03d9f50f7c4a.1654767443.git.skaplun@tarantool.org> <1656948283.336822639@f748.i.mail.ru> MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <1656948283.336822639@f748.i.mail.ru> X-Mailru-Src: smtp X-4EC0790: 10 X-7564579A: B8F34718100C35BD X-77F55803: 4F1203BC0FB41BD9E1E7861EDEC0DEA6ED2AA10F092298526DA0D1019ECEF98700894C459B0CD1B9E2F7D206ED951B50FF9ABD71DD4B5E2C598C17533927F280F4C996BC25162494 X-7FA49CB5: FF5795518A3D127A4AD6D5ED66289B5278DA827A17800CE7CA8E915ACC910FBDEA1F7E6F0F101C67BD4B6F7A4D31EC0BCC500DACC3FED6E28638F802B75D45FF8AA50765F7900637D08ED87D5614270A8638F802B75D45FF36EB9D2243A4F8B5A6FCA7DBDB1FC311F39EFFDF887939037866D6147AF826D890E4E581D49CD39F566ED90110695202117882F4460429724CE54428C33FAD305F5C1EE8F4F765FCDA09B7BF42873913A471835C12D1D9774AD6D5ED66289B52BA9C0B312567BB23117882F446042972877693876707352033AC447995A7AD18CB629EEF1311BF91D2E47CDBA5A96583BA9C0B312567BB2376E601842F6C81A19E625A9149C048EE38D4DC57D478E6881133410A2FE6C23AD8FC6C240DEA7642DBF02ECDB25306B2B78CF848AE20165D0A6AB1C7CE11FEE36FF1B927F95F3316C0837EA9F3D19764C4224003CC836476EA7A3FFF5B025636E2021AF6380DFAD1A18204E546F3947CB11811A4A51E3B096D1867E19FE1407959CC434672EE6371089D37D7C0E48F6C8AA50765F7900637BC468E7E89D8C5D6EFF80C71ABB335746BA297DBC24807EABDAD6C7F3747799A X-8FC586DF: 6EFBBC1D9D64D975 X-C1DE0DAB: 9604B64F49C60606AD91A466A1DEF99B296C473AB1E142185AC9E3593CE4B31AB1881A6453793CE9274300E5CE05BD44CFFBF5018520E398706633B3670C8A4FEEDD2DF4914E7A12E09434BB0DD26D8782ADBB6300E8D6439C2B6934AE262D3EE7EAB7254005DCED8DA55E71E02F9FC08E8E86DC7131B365E7726E8460B7C23C X-C8649E89: 4E36BF7865823D7055A7F0CF078B5EC49A30900B95165D34EB7BD66E9101C10081C4425234288FCB31DEBFDD76907147D1A2D3C206CF6031AE712BF9972D179B1D7E09C32AA3244CD0E34F654B16AE7AB6D1518524782F53B4DF56057A86259FFACE5A9C96DEB163 X-D57D3AED: 3ZO7eAau8CL7WIMRKs4sN3D3tLDjz0dLbV79QFUyzQ2Ujvy7cMT6pYYqY16iZVKkSc3dCLJ7zSJH7+u4VD18S7Vl4ZUrpaVfd2+vE6kuoey4m4VkSEu530nj6fImhcD4MUrOEAnl0W826KZ9Q+tr5ycPtXkTV4k65bRjmOUUP8cvGozZ33TWg5HZplvhhXbhDGzqmQDTd6OAevLeAnq3Ra9uf7zvY2zzsIhlcp/Y7m53TZgf2aB4JOg4gkr2biojpf3/rFe+bF+mOHV9d52g0w== X-Mailru-Sender: 11C2EC085EDE56FAC07928AF2646A76946A4AB7CAEB80FDF5429FA6CB5CB2781E8285F0AB37D98A7DEDBA653FF35249392D99EB8CC7091A70E183A470755BFD208F19895AA18418972D6B4FCE48DF648AE208404248635DF X-Mras: Ok Subject: Re: [Tarantool-patches] [PATCH luajit 1/2] gdb: introduce dumpers for GCobj X-BeenThere: tarantool-patches@dev.tarantool.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: Tarantool development patches List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , From: Sergey Kaplun via Tarantool-patches Reply-To: Sergey Kaplun Cc: tarantool-patches@dev.tarantool.org Errors-To: tarantool-patches-bounces@dev.tarantool.org Sender: "Tarantool-patches" Hi, Maxim! Thanks for the review! On 04.07.22, Maxim Kokryashkin wrote: > > Hi, Sergey! >   > Thanks for the patch! >   > LGTM, except for the single nit below. >   > > > > >+def dump_lj_tv_lightud(tv): > >+ return dump_lj_gco_lightud(gcval(tv['gcr'])) > >+ > >+def dump_lj_tv_str(tv): > >+ return dump_lj_gco_str(gcval(tv['gcr'])) > >+ > >+def dump_lj_tv_upval(tv): > >+ return dump_lj_gco_upval(gcval(tv['gcr'])) > >+ > >+def dump_lj_tv_thread(tv): > >+ return dump_lj_gco_thread(gcval(tv['gcr'])) > >+ > >+def dump_lj_tv_proto(tv): > >+ return dump_lj_gco_proto(gcval(tv['gcr'])) > >+ > >+def dump_lj_tv_func(tv): > >+ return dump_lj_gco_func(gcval(tv['gcr'])) > >+ > >+def dump_lj_tv_trace(tv): > >+ return dump_lj_gco_trace(gcval(tv['gcr'])) > >  > >-def dump_lj_tnumx(tv): > >+def dump_lj_tv_cdata(tv): > >+ return dump_lj_gco_cdata(gcval(tv['gcr'])) > >+ > >+def dump_lj_tv_tab(tv): > >+ return dump_lj_gco_tab(gcval(tv['gcr'])) > >+ > >+def dump_lj_tv_udata(tv): > >+ return dump_lj_gco_udata(gcval(tv['gcr'])) > >+ > I think we can replace that load of wrappers with something > that looks more or less like that: >   > 1 | gco_to_wrap = [func for func in globals().keys() if func.startswith('dump_lj_gco')] > 2 | > 3 | for func_name in gco_to_wrap: > 4 |    wrapped_func_name = func_name.replace('gco', 'tv') > 5 |    globals()[wrapped_func_name] = lambda tv: globals()[func_name](gcval(tv['gcr'])) >   > I am not really sure if it is harder to read for those who are not really familiar > with python, so feel free to ignore. I've liked the idea about generation of all necessary functions via lambda. I've modified your example, because `func_name` is taken as reference and all returned lambda functions use `dump_lj_gco_invalid()` as a result. Side note: as far as I'm not familiar with Python it was a real surprise for me. :) See the iterative patch below: =================================================================== diff --git a/src/luajit-gdb.py b/src/luajit-gdb.py index 779a25f8..4c443ce9 100644 --- a/src/luajit-gdb.py +++ b/src/luajit-gdb.py @@ -373,35 +373,15 @@ def dump_lj_tv_false(tv): def dump_lj_tv_true(tv): return 'true' -def dump_lj_tv_lightud(tv): - return dump_lj_gco_lightud(gcval(tv['gcr'])) - -def dump_lj_tv_str(tv): - return dump_lj_gco_str(gcval(tv['gcr'])) - -def dump_lj_tv_upval(tv): - return dump_lj_gco_upval(gcval(tv['gcr'])) - -def dump_lj_tv_thread(tv): - return dump_lj_gco_thread(gcval(tv['gcr'])) - -def dump_lj_tv_proto(tv): - return dump_lj_gco_proto(gcval(tv['gcr'])) - -def dump_lj_tv_func(tv): - return dump_lj_gco_func(gcval(tv['gcr'])) - -def dump_lj_tv_trace(tv): - return dump_lj_gco_trace(gcval(tv['gcr'])) - -def dump_lj_tv_cdata(tv): - return dump_lj_gco_cdata(gcval(tv['gcr'])) - -def dump_lj_tv_tab(tv): - return dump_lj_gco_tab(gcval(tv['gcr'])) - -def dump_lj_tv_udata(tv): - return dump_lj_gco_udata(gcval(tv['gcr'])) +# Generate wrappers for TValues containing GCobj. +gco_fn_dumpers = [fn for fn in globals().keys() if fn.startswith('dump_lj_gco')] +for fn_name in gco_fn_dumpers: + wrapped_fn_name = fn_name.replace('gco', 'tv') + # lambda takes `fn_name` as reference, so need the additional + # lambda to fixate the correct wrapper. + globals()[wrapped_fn_name] = (lambda f: ( + lambda tv: globals()[f](gcval(tv['gcr'])) + ))(fn_name) def dump_lj_tv_numx(tv): if tvisint(tv): @@ -409,9 +389,6 @@ def dump_lj_tv_numx(tv): else: return 'number {}'.format(cast('double', tv['n'])) -def dump_lj_tv_invalid(tv): - return dump_lj_tv_udata(gcval(tv['gcr'])) # # Yep, as side effect those unpleasant typos are avoided. # - # }}} gco_dumpers = { =================================================================== Branch is force-pushed. >   > > -- > Best regards, > Maxim Kokryashkin >   -- Best regards, Sergey Kaplun