qemu-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Qemu-devel] [PATCH 0/3] Purge the silly GLib Basic Types


From: Anthony Liguori
Subject: Re: [Qemu-devel] [PATCH 0/3] Purge the silly GLib Basic Types
Date: Sat, 19 Jan 2013 10:47:42 -0600
User-agent: Notmuch/0.13.2+93~ged93d79 (http://notmuchmail.org) Emacs/23.3.1 (x86_64-pc-linux-gnu)

Michael Tokarev <address@hidden> writes:

> 19.01.2013 13:33, Blue Swirl wrote:
>> On Fri, Jan 18, 2013 at 4:17 PM, Anthony Liguori <address@hidden> wrote:
>>> Markus Armbruster <address@hidden> writes:
>>>
>>>> See PATCH 1/3 for rationale.
>>>>
>>>> Markus Armbruster (3):
>>>>    Purge the silly GLib "Basic Types", except for gboolean
>>>>    Purge GLib's gboolean, it's a trap for the unwary
>>>>    checkpatch: Keep out the GLib silliness we just purged
>>>
>>> Changing QEMU code to work around checkpatch's failing is insane.
>>>
>>> When interacting with glib, use glib types.  Not using those types just
>>> makes the code more difficult to understand.
>>
>> While the types are indeed useless and even cause problems (gboolean),
>> I agree with Anthony. It's the same as using DWORD for Win32 APIs.
>
> Actually it is far from DWORD.  DWORD is like uint32_t, where no
> standard C type matches (since these depends on the word size etc).
> So in Win32, these DWORDs are justified.
>
> With GLib, things are sillier than that, since they redefine _standard_
> C types, without gaining anything in portability.

glib predates "standard C types".  They were only introduced in C99 and
weren't widely available until a few years later.

There are reasons for all of it.  For instance, there was a time when
not all C compilers supported const so if you wanted to use it you had
to #define around it.  gconstpointer was a trick to make use of const
while still supporting older compilers.  Likewise, bool is a relatively
new thing so gboolean made sense at the time.  The lack of stdint led to
g[u]int{8,16,32,64} and once you have all of that, gint and guint are
pretty obvious.

We should not use these types pervasively in QEMU, of course preferring
more modern standard C99, but when glib takes a callback of:

gboolean (*GSourceFunc)(gpointer data)

Then the most readable thing to do is to write your callback following
that signature.

Regards,

Anthony Liguori

>
> /mjt



reply via email to

[Prev in Thread] Current Thread [Next in Thread]