On Tue, Sep 23, 2025 at 02:12:02PM +0200, Markus Armbruster wrote:
> Daniel P. Berrangé <[email protected]> writes:
> 
> > This will be used to include the thread name in error reports
> > in a later patch. It returns a const string stored in a thread
> > local to avoid memory allocation when it is called repeatedly
> > in a single thread. This makes the assumption that the thread
> > name is set at the very start of the thread, which is the case
> > when using qemu_thread_create.
> >
> > Signed-off-by: Daniel P. Berrangé <[email protected]>
> 
> [...]
> 
> > diff --git a/util/qemu-thread-win32.c b/util/qemu-thread-win32.c
> > index 7a734a7a09..e3789c20d1 100644
> > --- a/util/qemu-thread-win32.c
> > +++ b/util/qemu-thread-win32.c
> 
> [...]
> 
> > @@ -412,3 +418,38 @@ bool qemu_thread_is_self(QemuThread *thread)
> >  {
> >      return GetCurrentThreadId() == thread->tid;
> >  }
> > +
> > +static __thread char namebuf[64];
> > +
> > +const char *qemu_thread_get_name(void)
> > +{
> > +    HRESULT hr;
> > +    wchar_t *namew = NULL;
> > +    g_autofree char *name = NULL;
> > +
> > +    if (namebuf[0] != '\0') {
> > +        return namebuf;
> > +    }
> > +
> > +    if (!load_thread_description()) {
> > +        goto error;
> > +    }
> > +
> > +    hr = GetThreadDescriptionFunc(GetCurrentThread(), &namew);
> > +    if (!SUCCEEDED(hr)) {
> > +        goto error;
> > +    }
> > +
> > +    name = g_utf16_to_utf8(namew, -1, NULL, NULL, NULL);
> > +    LocalFree(namew);
> > +    if (!name) {
> > +        goto error;
> > +    }
> > +
> > +    g_strlcpy(namebuf, name, G_N_ELEMENTS(namebuf));
> > +    return namebuf;
> > +
> > + error:
> > +    strlcpy(namebuf, "unnamed", G_N_ELEMENTS(namebuf));
> > +    return namebuf;
> > +}
> 
> ../util/qemu-thread-win32.c: In function 'qemu_thread_get_name':
> ../util/qemu-thread-win32.c:453:5: error: implicit declaration of function 
> 'strlcpy'; did you mean 'strncpy'? [-Wimplicit-function-declaration]
>   453 |     strlcpy(namebuf, "unnamed", G_N_ELEMENTS(namebuf));
>       |     ^~~~~~~
>       |     strncpy
> ../util/qemu-thread-win32.c:453:5: error: nested extern declaration of 
> 'strlcpy' [-Werror=nested-externs]

Sigh, I meant g_strlcopy like the line shortly before.

With regards,
Daniel
-- 
|: https://berrange.com      -o-    https://www.flickr.com/photos/dberrange :|
|: https://libvirt.org         -o-            https://fstop138.berrange.com :|
|: https://entangle-photo.org    -o-    https://www.instagram.com/dberrange :|


Reply via email to