From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:51743) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YNPcH-0001Xf-GX for qemu-devel@nongnu.org; Mon, 16 Feb 2015 12:37:54 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1YNPcE-0003PE-JP for qemu-devel@nongnu.org; Mon, 16 Feb 2015 12:37:53 -0500 Received: from mx1.redhat.com ([209.132.183.28]:38950) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YNPcE-0003Ov-Bb for qemu-devel@nongnu.org; Mon, 16 Feb 2015 12:37:50 -0500 Received: from int-mx10.intmail.prod.int.phx2.redhat.com (int-mx10.intmail.prod.int.phx2.redhat.com [10.5.11.23]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id t1GHbmoj021476 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=FAIL) for ; Mon, 16 Feb 2015 12:37:49 -0500 Message-ID: <54E22AEB.7020907@redhat.com> Date: Mon, 16 Feb 2015 12:37:47 -0500 From: John Snow MIME-Version: 1.0 References: <54DE97D2.20506@redhat.com> <20150215023746.GA16159@fam-t430.nay.redhat.com> In-Reply-To: <20150215023746.GA16159@fam-t430.nay.redhat.com> Content-Type: text/plain; charset=windows-1252; format=flowed Content-Transfer-Encoding: 7bit Subject: Re: [Qemu-devel] Enum String Generator List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Fam Zheng Cc: qemu-devel On 02/14/2015 09:37 PM, Fam Zheng wrote: > On Fri, 02/13 19:33, John Snow wrote: >> Just a stupid question: We don't have a macro facility in the current >> codebase that generates both an enum and string table / lookup function >> simultaneously, do we? >> >> Some things really do just wind up looking grossly inelegant in C, and this >> is one of them. >> > > There is in QAPI: > > fam@fam-t430:~/build/last$ grep -A 4 NewImageMode_lookup qapi-types.c > const char *NewImageMode_lookup[] = { > "existing", > "absolute-paths", > NULL, > }; > > fam@fam-t430:~/build/last$ grep -C 10 -e NEW_IMAGE qapi-types.h > ... > > extern const char *NewImageMode_lookup[]; > typedef enum NewImageMode > { > NEW_IMAGE_MODE_EXISTING = 0, > NEW_IMAGE_MODE_ABSOLUTE_PATHS = 1, > NEW_IMAGE_MODE_MAX = 2, > } NewImageMode; > > ... > > Is that what you want? > > Fam > More or less; though I wasn't intending on working in QAPI (I'm inside of qtest at the moment) and I assume people wouldn't appreciate the QAPI clutter with qtest junk. Was just trying to figure out the best way to add a bunch of tables to allow some test permutations -- without it being grossly redundant. the GLib test framework doesn't seem to allow for a test matrix / permutations particularly well. I see cases of some 2D iterations in existing qtests, but nobody appears to have implemented some 3D+ options structure for iterating through combinations.