Skip to content

gatomic: Make fallback g_atomic_pointer_get type-safe

Simon McVittie requested to merge wip/smcv/armel-atomic-pointer-get into master

Since !1715 (merged), g_atomic_pointer_get (&x) has usually returned the type of x, rather than a generic pointer, in C++ code (where x is any pointer, or any pointer-sized integer such as guintptr). glib/tests/cxx.cpp asserts that this is the case.

However, this was only implemented for the lock-free fast-path, not for the slow path used in platforms with an ARMv5 baseline (and therefore no atomic instructions) such as Debian armel.


This is a fix for the issue described below.

I tried uploading a snapshot of recent GLib git master to Debian experimental, and got this build failure on the armel (ARMv5, EABI, software floating point) architecture used for older ARM CPUs such as Marvell Kirkwood:

[127/1241] c++ -Iglib/tests/cxx.p -Iglib/tests -I../../../glib/tests -I. -I../../.. -Iglib -I../../../glib -fdiagnostics-color=always -pipe -D_FILE_OFFSET_BITS=64 -Wall -Winvalid-pch -Wnon-virtual-dtor -g -O2 -ffile-prefix-map=/<<PKGBUILDDIR>>=. -fstack-protector-strong -Wformat -Werror=format-security -Wdate-time -D_FORTIFY_SOURCE=2 -pthread -MD -MQ glib/tests/cxx.p/cxx.cpp.o -MF glib/tests/cxx.p/cxx.cpp.o.d -o glib/tests/cxx.p/cxx.cpp.o -c ../../../glib/tests/cxx.cpp
FAILED: glib/tests/cxx.p/cxx.cpp.o 
c++ -Iglib/tests/cxx.p -Iglib/tests -I../../../glib/tests -I. -I../../.. -Iglib -I../../../glib -fdiagnostics-color=always -pipe -D_FILE_OFFSET_BITS=64 -Wall -Winvalid-pch -Wnon-virtual-dtor -g -O2 -ffile-prefix-map=/<<PKGBUILDDIR>>=. -fstack-protector-strong -Wformat -Werror=format-security -Wdate-time -D_FORTIFY_SOURCE=2 -pthread -MD -MQ glib/tests/cxx.p/cxx.cpp.o -MF glib/tests/cxx.p/cxx.cpp.o.d -o glib/tests/cxx.p/cxx.cpp.o -c ../../../glib/tests/cxx.cpp
In file included from ../../../glib/gthread.h:32,
                 from ../../../glib/gasyncqueue.h:32,
                 from ../../../glib/glib.h:32,
                 from ../../../glib/tests/cxx.cpp:18:
../../../glib/tests/cxx.cpp: In function ‘void test_typeof()’:
../../../glib/gatomic.h:427:25: error: invalid conversion from ‘gpointer’ {aka ‘void*’} to ‘MyObject*’ [-fpermissive]
  427 |   (g_atomic_pointer_get (atomic))
      |   ~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~
      |                         |
      |                         gpointer {aka void*}
../../../glib/tests/cxx.cpp:35:20: note: in expansion of macro ‘g_atomic_pointer_get’
   35 |   MyObject *obj3 = g_atomic_pointer_get (&obj2);
      |                    ^~~~~~~~~~~~~~~~~~~~
Edited by Simon McVittie

Merge request reports