From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1MySDx-0001IO-1A for qemu-devel@nongnu.org; Thu, 15 Oct 2009 11:26:41 -0400 Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1MySDr-0001EN-Jg for qemu-devel@nongnu.org; Thu, 15 Oct 2009 11:26:40 -0400 Received: from [199.232.76.173] (port=48172 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1MySDr-0001EG-El for qemu-devel@nongnu.org; Thu, 15 Oct 2009 11:26:35 -0400 Received: from mx1.redhat.com ([209.132.183.28]:43161) by monty-python.gnu.org with esmtp (Exim 4.60) (envelope-from ) id 1MySDp-0007lM-Gw for qemu-devel@nongnu.org; Thu, 15 Oct 2009 11:26:34 -0400 Date: Thu, 15 Oct 2009 12:26:22 -0300 From: Luiz Capitulino Subject: Re: [Qemu-devel] [PATCH 01/10] Introduce qmisc module Message-ID: <20091015122622.1f93ea2d@doriath> In-Reply-To: <4AD72B88.2040107@codemonkey.ws> References: <1255037747-3340-1-git-send-email-lcapitulino@redhat.com> <1255037747-3340-2-git-send-email-lcapitulino@redhat.com> <4AD72B88.2040107@codemonkey.ws> Mime-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit List-Id: qemu-devel.nongnu.org List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Anthony Liguori Cc: qemu-devel@nongnu.org On Thu, 15 Oct 2009 09:02:48 -0500 Anthony Liguori wrote: > Luiz Capitulino wrote: > > This module provides miscellania QObject functions. > > > > Currently it exports qobject_from_fmt(), which is somewhat > > based on Python's Py_BuildValue() function. It is capable of > > creating QObjects from a specified string format. > > > > For example, to create a QDict with mixed data-types one > > could do: > > > > QObject *obj = qobject_from_fmt("{ s: [ i, s ], s: i }", ... ); > > > > Signed-off-by: Luiz Capitulino > > --- > > Makefile | 2 +- > > qmisc.c | 222 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ > > qmisc.h | 19 +++++ > > 3 files changed, 242 insertions(+), 1 deletions(-) > > create mode 100644 qmisc.c > > create mode 100644 qmisc.h > > > > diff --git a/Makefile b/Makefile > > index d96fb4b..182f176 100644 > > --- a/Makefile > > +++ b/Makefile > > @@ -100,7 +100,7 @@ obj-y += buffered_file.o migration.o migration-tcp.o net.o qemu-sockets.o > > obj-y += qemu-char.o aio.o net-checksum.o savevm.o > > obj-y += msmouse.o ps2.o > > obj-y += qdev.o qdev-properties.o ssi.o > > -obj-y += qint.o qstring.o qdict.o qlist.o qemu-config.o > > +obj-y += qint.o qstring.o qdict.o qlist.o qmisc.o qemu-config.o > > > > obj-$(CONFIG_BRLAPI) += baum.o > > obj-$(CONFIG_WIN32) += tap-win32.o > > diff --git a/qmisc.c b/qmisc.c > > new file mode 100644 > > index 0000000..42b6f22 > > --- /dev/null > > +++ b/qmisc.c > > @@ -0,0 +1,222 @@ > > +/* > > + * Misc QObject functions. > > + * > > + * Copyright (C) 2009 Red Hat Inc. > > + * > > + * Authors: > > + * Luiz Capitulino > > + * > > + * This work is licensed under the terms of the GNU GPL, version 2. See > > + * the COPYING file in the top-level directory. > > + */ > > +#include "qmisc.h" > > +#include "qint.h" > > +#include "qlist.h" > > +#include "qdict.h" > > +#include "qstring.h" > > +#include "qobject.h" > > +#include "qemu-common.h" > > + > > +/* > > + * qobject_from_fmt() and related functions are based on the Python's > > + * Py_BuildValue() and are subject to the Python Software Foundation > > + * License Version 2. > > + * > > + * Copyright (c) 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009 Python > > + * Software Foundation. > > + */ > > > > If we're introducing third-party code under a new license, we need to > update the top-level LICENSE file. I took a brief look and it wasn't > immediately clear that this license is GPL compatible. According to the > FSF, certain versions of this license are incompatible and some are > compatible. I think it would have been better to just write something > from scratch... According to the Python's LICENSE file it's compatible since 2001 (2.0.1 release). > > + case '[': > > + return do_mklist(fmt, args, ']', count_format(*fmt, ']')); > > > > Because this is bizarre. It looks ahead to count the number of > arguments which is a very strange way to parse something like this. > > Why not a simple recursive decent parser? I could try it, but I think this is going to take some time as I would have to read more about it. I thought the Python's implementation was a good idea as we're short in time and it was easy to adapt and is widely used in production. > > +/** > > + * qobject_from_fmt(): build QObjects from a specified format. > > + * > > + * Valid characters of the format: > > + * > > + * i integer, map to QInt > > + * s string, map to QString > > + * [] list, map to QList > > + * {} dictionary, map to QDict > > + * > > + * Examples: > > + * > > + * - Create a QInt > > + * > > + * qobject_from_fmt("i", 42); > > + * > > + * - Create a QList of QStrings > > + * > > + * qobject_from_fmt("[ i, i, i ]", 0, 1 , 2); > > + * > > + * - Create a QDict with mixed data-types > > + * > > + * qobject_from_fmt("{ s: [ i, s ], s: i }", ... ); > > + * > > + * Return a strong reference to a QObject on success, NULL otherwise. > > + */ > > > > But my real objection is that we should make this "{%s: [%d, %s], %s: > %d}" so that we can mark it as a printf formatted function and get type > checking. You'll probably have to support both "%d" and "%" PRId64 for > sanity sake. Trivial to do if we ignore the '%' characters. :))