[Spice-devel] [PATCH] Fix compile errors on Linux 32bit system

Hongzhi, Song hongzhi.song at windriver.com
Tue Jun 11 01:24:20 UTC 2019


On 6/10/19 9:00 PM, Frediano Ziglio wrote:
>> On 6/5/19 6:18 AM, Hongzhi.Song wrote:
>>> There are folowing compile errors on Linux 32bit system with -Werror
>>> for gcc.
>>>
>>> red-channel.c:207:73: error: format '%x' expects argument of type
>>> 'unsigned int', but argument 7 has type 'long unsigned int'
>>> [-Werror=format=]
>>> |207| red_channel_debug(self, "thread_id 0x%" G_GSIZE_MODIFIER "x",
>>> 				~~~~~~~~~~~~~~~~~~~~~^
>>> 			self->priv->thread_id);
>>> 		~~~~~~~~~~~~~~~~~~~~~^
>>>
>>> On 32bit system, #define G_GSIZE_MODIFIER "". But the type of
>>> 'self->priv->thread_id' is 'unsigned long int', which should match '%lx'
>>> not '%x'.
>>>
>>> So we should recovery the <0x%" G_GSIZE_MODIFIER "x"> to <0x%lx">.
>>> And others files modification are similar to G_GSIZE_MODIFIER.
>> Indeed in pthreadtypes.h appears:
>>     typedef unsigned long int pthread_t;
>>
>> And in zlib.h (as part of struct z_stream_s):
>>       uLong    total_out; /* total number of bytes output so far */
>>
>>> Signed-off-by: Hongzhi.Song <hongzhi.song at windriver.com>
>> Ack, with a minor change below
>>
> All these "fixes" break LLP64 platforms (like Windows 64)


But without these 'fixes', it has compile failure on Linux-32bit.

Is there a compatible method to fix the issue?


--Hongzhi



>>> ---
>>>    server/red-channel.c    | 6 +++---
>>>    server/red-client.c     | 8 ++++----
>>>    server/red-replay-qxl.c | 2 +-
>>>    3 files changed, 8 insertions(+), 8 deletions(-)
>>>
>>> diff --git a/server/red-channel.c b/server/red-channel.c
>>> index 82e5223..11644e4 100644
>>> --- a/server/red-channel.c
>>> +++ b/server/red-channel.c
>>> @@ -202,7 +202,7 @@ red_channel_constructed(GObject *object)
>>>    {
>>>        RedChannel *self = RED_CHANNEL(object);
>>>    
>>> -    red_channel_debug(self, "thread_id 0x%" G_GSIZE_MODIFIER "x",
>>> self->priv->thread_id);
>>> +    red_channel_debug(self, "thread_id 0x%lx", self->priv->thread_id);
>>>    
>>>        RedChannelClass *klass = RED_CHANNEL_GET_CLASS(self);
>>>    
>>> @@ -473,8 +473,8 @@ void red_channel_remove_client(RedChannel *channel,
>>> RedChannelClient *rcc)
>>>    
>>>        if (!pthread_equal(pthread_self(), channel->priv->thread_id)) {
>>>            red_channel_warning(channel,
>>> -                            "channel->thread_id (0x%" G_GSIZE_MODIFIER "x)
>>> != "
>>> -                            "pthread_self (0x%" G_GSIZE_MODIFIER "x)."
>>> +                            "channel->thread_id (0x%lx) != "
>>> +                            "pthread_self (0x%lx)."
>>>                                "If one of the threads is != io-thread && !=
>>>                                vcpu-thread, "
>>>                                "this might be a BUG",
>>>                                channel->priv->thread_id, pthread_self());
>>> diff --git a/server/red-client.c b/server/red-client.c
>>> index 961b497..81258e1 100644
>>> --- a/server/red-client.c
>>> +++ b/server/red-client.c
>>> @@ -174,8 +174,8 @@ void red_client_migrate(RedClient *client)
>>>        RedChannel *channel;
>>>    
>>>        if (!pthread_equal(pthread_self(), client->thread_id)) {
>>> -        spice_warning("client->thread_id (0x%" G_GSIZE_MODIFIER "x) != "
>>> -                      "pthread_self (0x%" G_GSIZE_MODIFIER "x)."
>>> +        spice_warning("client->thread_id (0x%lx) != "
>>> +                      "pthread_self (0x%lx)."
>>>                          "If one of the threads is != io-thread && !=
>>>                          vcpu-thread,"
>>>                          " this might be a BUG",
>>>                          client->thread_id, pthread_self());
>>> @@ -193,8 +193,8 @@ void red_client_destroy(RedClient *client)
>>>        RedChannelClient *rcc;
>>>    
>>>        if (!pthread_equal(pthread_self(), client->thread_id)) {
>>> -        spice_warning("client->thread_id (0x%" G_GSIZE_MODIFIER "x) != "
>>> -                      "pthread_self (0x%" G_GSIZE_MODIFIER "x)."
>>> +        spice_warning("client->thread_id (0x%lx) != "
>>> +                      "pthread_self (0x%lx)."
> Not sure what is better, maybe cast all pthread_t to uintptr_t ?
> Or maybe cast to a void* and use %p format instead ?
>
>>>                          "If one of the threads is != io-thread && !=
>>>                          vcpu-thread,"
>>>                          " this might be a BUG",
>>>                          client->thread_id,
>>> diff --git a/server/red-replay-qxl.c b/server/red-replay-qxl.c
>>> index 6d34818..0deb406 100644
>>> --- a/server/red-replay-qxl.c
>>> +++ b/server/red-replay-qxl.c
>>> @@ -264,7 +264,7 @@ static replay_t read_binary(SpiceReplay *replay, const
>>> char *prefix, size_t *siz
>>>                exit(1);
>>>            }
>>>            if ((ret = inflate(&strm, Z_NO_FLUSH)) != Z_STREAM_END) {
>>> -            spice_error("inflate error %d (disc: %" G_GSSIZE_FORMAT ")",
>>> +            spice_error("inflate error %d (disc: %li)",
>> Everywhere in the project "%[l]d" is used and not "%[l]i".
>> For consistency, I'd like to change this line to "(disc %ld)".
>>
> I think there is better to cast the "*size - strm.total_out" to size_t
> instead.
>
>> Thanks,
>>       Uri.
>>>                            ret, *size - strm.total_out);
>>>                if (ret == Z_DATA_ERROR) {
>>>                    /* last operation may be wrong. since we do the recording
>>>
> Frediano
>


More information about the Spice-devel mailing list