From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:39130) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YpCht-0007Wz-Am for qemu-devel@nongnu.org; Mon, 04 May 2015 05:30:34 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1YpChq-0000E4-Bj for qemu-devel@nongnu.org; Mon, 04 May 2015 05:30:33 -0400 Received: from mail-pa0-f42.google.com ([209.85.220.42]:35833) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YpChq-0000Dd-3J for qemu-devel@nongnu.org; Mon, 04 May 2015 05:30:30 -0400 Received: by pabtp1 with SMTP id tp1so156037447pab.2 for ; Mon, 04 May 2015 02:30:29 -0700 (PDT) Message-ID: <55473C2C.7020200@linaro.org> Date: Mon, 04 May 2015 17:30:20 +0800 From: Shannon Zhao MIME-Version: 1.0 References: <1429104309-3844-1-git-send-email-zhaoshenglong@huawei.com> <1429104309-3844-14-git-send-email-zhaoshenglong@huawei.com> <20150428085412.5d215d01@nial.brq.redhat.com> <553F3ACE.2060208@huawei.com> <20150428101529.5feb4915@nial.brq.redhat.com> <553F4A43.2090104@huawei.com> <20150428113503.0fe6fe9c@nial.brq.redhat.com> <553F5782.7020707@huawei.com> <5540DF93.4090000@linaro.org> <20150504112201.693d9e26@nial.brq.redhat.com> In-Reply-To: <20150504112201.693d9e26@nial.brq.redhat.com> Content-Type: text/plain; charset=windows-1252 Content-Transfer-Encoding: 7bit Subject: Re: [Qemu-devel] [PATCH v5 13/20] hw/acpi/aml-build: Add ToUUID macro List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Igor Mammedov Cc: peter.maydell@linaro.org, hangaohuai@huawei.com, mst@redhat.com, a.spyridakis@virtualopensystems.com, claudio.fontana@huawei.com, qemu-devel@nongnu.org, peter.huangpeng@huawei.com, alex.bennee@linaro.org, hanjun.guo@linaro.org, Shannon Zhao , pbonzini@redhat.com, lersek@redhat.com, christoffer.dall@linaro.org On 2015/5/4 17:22, Igor Mammedov wrote: > On Wed, 29 Apr 2015 21:41:39 +0800 > Shannon Zhao wrote: > >> >> >> On 2015/4/28 17:48, Shannon Zhao wrote: >>> On 2015/4/28 17:35, Igor Mammedov wrote: >>>> On Tue, 28 Apr 2015 16:52:19 +0800 >>>> Shannon Zhao wrote: >>>> >>>>> On 2015/4/28 16:15, Igor Mammedov wrote: >>>>>>>> btw: >>>>>>>>>> whole thing might be simpler if an intermediate conversion is avoided, >>>>>>>>>> just pack buffer as in spec byte by byte: >>>>>>>>>> >>>>>>>>>> /* format: aabbccdd-eeff-gghh-iijj-kkllmmnnoopp */ >>>>>>>>>> assert(strlen(uuid) == ...); >>>>>>>>>> build_append_byte(var->buf, HEX2BYTE(uuid[3]); /* dd */ >>>>>>>> >>>>>>>> use build_append_byte(var->buf, HEX2BYTE(uuid + 7); ? >>>>>>>> >>>>>>>>>> build_append_byte(var->buf, HEX2BYTE(uuid[2]); /* cc */ >>>>>>>> >>>>>>>> use build_append_byte(var->buf, HEX2BYTE(uuid + 5); ? >>>>>> if you mean hyphens /-/ then they are not encoded, >>>>>> but you surely can add checks for them to make sure that >>>>>> UUID format is as expected. >>>>>> >>>>> >>>>> I mean uuid[3] points to b not dd. Maybe use following way: >>>>> >>>>> static uint8_t Hex2Byte(char *src) >>>> or even better: >>>> Hex2Byte(char *src, byte_idx) >>>> and do pointer arithmetic inside >>>> >>>> [...] >>>>> build_append_byte(var->buf, Hex2Byte(uuid + (3 * 2))); /* dd */ >>>> build_append_byte(var->buf, Hex2Byte(uuid, 3)); /* dd - at offset 00 */ >>>> build_append_byte(var->buf, Hex2Byte(uuid, 2)); /* cc - at offset 01 */ >>>> ... >>>> >>> Yes, it's better to first four bytes. But there are hyphens /-/, for >>> offset 04, 05 and etc it doesn't work. We can't use following expression: >>> >>> build_append_byte(var->buf, Hex2Byte(uuid, 5)); /* ff - at offset 04 */ >>> build_append_byte(var->buf, Hex2Byte(uuid, 4)); /* ee - at offset 05 */ >>> ... >>> >>> >> >> So about the implementation of this macro, I think I'd like to use >> following approach. This lets Hex2Byte do what it should only do and >> still has a clear look of UUID. What do you think about? >> >> static uint8_t Hex2Byte(char *src) >> { >> int hi = Hex2Digit(*src++); >> int lo = Hex2Digit(*src); >> >> if ((hi < 0) || (lo < 0)) >> return -1; > just make Hex2Digit() assert on wrong input. > Ok. >> >> return (hi << 4) | lo; >> } >> >> g_assert((strlen(uuid) == 36) && (uuid[8] == '-') && (uuid[13] == '-') >> && (uuid[18] == '-') && (uuid[23] == '-')); >> >> build_append_byte(var->buf, Hex2Byte(uuid + (3 * 2))); /* dd */ > ^^^^^ > I'd make it one number, instead of forcing reader to do math > every time he/she looks at this code. > Ok, will do this. And about other patches in this series could you offer your comments? Thanks, Shannon > >> build_append_byte(var->buf, Hex2Byte(uuid + (2 * 2))); /* cc */ >> build_append_byte(var->buf, Hex2Byte(uuid + (1 * 2))); /* bb */ >> build_append_byte(var->buf, Hex2Byte(uuid + (0 * 2))); /* aa */ >> >> build_append_byte(var->buf, Hex2Byte(uuid + (5 * 2 + 1))); /* ff */ >> build_append_byte(var->buf, Hex2Byte(uuid + (4 * 2 + 1))); /* ee */ >> >> build_append_byte(var->buf, Hex2Byte(uuid + (7 * 2 + 2))); /* hh */ >> build_append_byte(var->buf, Hex2Byte(uuid + (6 * 2 + 2))); /* gg */ >> >> build_append_byte(var->buf, Hex2Byte(uuid + (8 * 2 + 3))); /* ii */ >> build_append_byte(var->buf, Hex2Byte(uuid + (9 * 2 + 3))); /* jj */ >> >> build_append_byte(var->buf, Hex2Byte(uuid + (10 * 2 + 4))); /* kk */ >> build_append_byte(var->buf, Hex2Byte(uuid + (11 * 2 + 4))); /* ll */ >> build_append_byte(var->buf, Hex2Byte(uuid + (12 * 2 + 4))); /* mm */ >> build_append_byte(var->buf, Hex2Byte(uuid + (13 * 2 + 4))); /* nn */ >> build_append_byte(var->buf, Hex2Byte(uuid + (14 * 2 + 4))); /* oo */ >> build_append_byte(var->buf, Hex2Byte(uuid + (15 * 2 + 4))); /* pp */ >