[Fwd: dereferencing void *]
https://sourceforge.net/p/ags/code/1515/tree/src/ags/thread/ags_returnable_thread.c ___ gtk-app-devel-list mailing list gtk-app-devel-list@gnome.org https://mail.gnome.org/mailman/listinfo/gtk-app-devel-list
Re: [Fwd: dereferencing void *]
On Mon, 2014-03-24 at 00:20 +0100, Joël Krähemann wrote: > https://sourceforge.net/p/ags/code/1515/tree/src/ags/thread/ags_returnable_thread.c > > ___ > gtk-app-devel-list mailing list > gtk-app-devel-list@gnome.org > https://mail.gnome.org/mailman/listinfo/gtk-app-devel-list Hi, I'd like to use g_atomic_pointer_set and g_atomic_pointer_get but obtaining compile error. First the struct containing void * struct _AgsReturnableThread { AgsThread thread; volatile guint flags; volatile void *safe_data; }; (gdb) r Starting program: /home/joel/ags-code/ags warning: Could not load shared library symbols for linux-vdso.so.1. Do you need "set solib-search-path" or "set sysroot"? [Thread debugging using libthread_db enabled] Using host libthread_db library "/lib/x86_64-linux-gnu/libthread_db.so.1". [New Thread 0x7fffe630a700 (LWP 5175)] [New Thread 0x7fffe5aa9700 (LWP 5176)] [New Thread 0x7fffe52a8700 (LWP 5177)] [New Thread 0x7fffe4aa7700 (LWP 5178)] [New Thread 0x7fffd700 (LWP 5179)] [New Thread 0x7fffdf7fe700 (LWP 5180)] [New Thread 0x7fffdeffd700 (LWP 5181)] [New Thread 0x7fffde7fc700 (LWP 5182)] [New Thread 0x7fffddffb700 (LWP 5183)] [New Thread 0x7fffdd7fa700 (LWP 5184)] [New Thread 0x7fffdcff9700 (LWP 5185)] ** Message: AgsRecallFactory creating: ags-delay ** Message: AgsRecallFactory creating: ags-count-beats ** Message: ags_channel_nth: nth channel does not exist `- stopped @: i = 0; nth = 0 ** Message: AgsRecallFactory creating: ags-copy-pattern ** Message: ags_channel_nth: nth channel does not exist `- stopped @: i = 0; nth = 0 ** Message: debug: AGS_IS_COPY_PATTERN_AUDIO_RUN(packable) Program received signal SIGSEGV, Segmentation fault. [Switching to Thread 0x7fffddffb700 (LWP 5183)] ags_task_thread_append_task_queue (thread=0x97a010) at ./src/ags/thread/ags_task_thread.c:264 264 task_thread = append->task_thread; (gdb) make ags gcc -DHAVE_CONFIG_H -I. -I./src/ -I/usr/include/uuid -I/usr/include/alsa-I/usr/include/libxml2 -I/usr/include/libinstpatch-1.0 -I/usr/include/glib-2.0 -I/usr/lib/x86_64-linux-gnu/glib-2.0/include -pthread -I/usr/include/glib-2.0 -I/usr/lib/x86_64-linux-gnu/glib-2.0/include -pthread -I/usr/include/gdk-pixbuf-2.0 -I/usr/include/glib-2.0 -I/usr/lib/x86_64-linux-gnu/glib-2.0/include -I/usr/include/libpng12 -I/usr/include/cairo -I/usr/include/glib-2.0 -I/usr/lib/x86_64-linux-gnu/glib-2.0/include -I/usr/include/pixman-1 -I/usr/include/freetype2 -I/usr/include/libpng12 -I/usr/include/libdrm -pthread -I/usr/include/gtk-2.0 -I/usr/lib/x86_64-linux-gnu/gtk-2.0/include -I/usr/include/atk-1.0 -I/usr/include/cairo -I/usr/include/gdk-pixbuf-2.0 -I/usr/include/pango-1.0 -I/usr/include/gio-unix-2.0/ -I/usr/include/freetype2 -I/usr/include/glib-2.0 -I/usr/lib/x86_64-linux-gnu/glib-2.0/include -I/usr/include/pixman-1 -I/usr/include/libpng12 -I/usr/include/libdrm -I/usr/include/harfbuzz -g -O2 -MT ags-ags_returnable_thread.o -MD -MP -MF .deps/ags-ags_returnable_thread.Tpo -c -o ags-ags_returnable_thread.o `test -f './src/ags/thread/ags_returnable_thread.c' || echo './'`./src/ags/thread/ags_returnable_thread.c In file included from /usr/lib/x86_64-linux-gnu/glib-2.0/include/glibconfig.h:9:0, from /usr/include/glib-2.0/glib/gtypes.h:34, from /usr/include/glib-2.0/glib/galloca.h:34, from /usr/include/glib-2.0/glib.h:32, from ./src/ags/thread/ags_returnable_thread.h:22, from ./src/ags/thread/ags_returnable_thread.c:19: ./src/ags/thread/ags_returnable_thread.c: In function 'ags_returnable_thread_init': /usr/include/glib-2.0/glib/gmacros.h:181:53: error: size of array '_GStaticAssertCompileTimeAssertion_1' is negative #define G_STATIC_ASSERT(expr) typedef char G_PASTE (_GStaticAssertCompileTimeAssertion_, __COUNTER__)[(expr) ? 1 : -1] G_GNUC_UNUSED ^ /usr/include/glib-2.0/glib/gmacros.h:178:47: note: in definition of macro 'G_PASTE_ARGS' #define G_PASTE_ARGS(identifier1,identifier2) identifier1 ## identifier2 ^ /usr/include/glib-2.0/glib/gmacros.h:181:44: note: in expansion of macro 'G_PASTE' #define G_STATIC_ASSERT(expr) typedef char G_PASTE (_GStaticAssertCompileTimeAssertion_, __COUNTER__)[(expr) ? 1 : -1] G_GNUC_UNUSED ^ /usr/include/glib-2.0/glib/gatomic.h:154:5: note: in expansion of macro 'G_STATIC_ASSERT' G_STATIC_ASSERT (sizeof *(atomic) == sizeof (gpointer)); \ ^ ./src/ags/thread/ags_returnable_thread.c:108:3: note: in expansion of macro 'g_atomic_pointer_set' g_atomic_pointer_set((returnable_thread->safe_data), ^ ./src/ags/thread/ags_returnable_thread.c:108:3: error: invalid use of void expression In file included from /usr/include/glib-2.0/glib/gthread.h:34:0, from /usr/include/glib-2.0/glib/gasyncqueue.h:34, from /usr/includ
Re: [Fwd: dereferencing void *]
On Mon, 2014-03-24 at 00:22 +0100, Joël Krähemann wrote: > On Mon, 2014-03-24 at 00:20 +0100, Joël Krähemann wrote: > > https://sourceforge.net/p/ags/code/1515/tree/src/ags/thread/ags_returnable_thread.c > > > > ___ > > gtk-app-devel-list mailing list > > gtk-app-devel-list@gnome.org > > https://mail.gnome.org/mailman/listinfo/gtk-app-devel-list > > Hi, I'd like to use g_atomic_pointer_set and g_atomic_pointer_get but > obtaining compile error. First the struct containing void * > > > struct _AgsReturnableThread > { > AgsThread thread; > > volatile guint flags; > > volatile void *safe_data; > }; > > > (gdb) r > Starting program: /home/joel/ags-code/ags > warning: Could not load shared library symbols for linux-vdso.so.1. > Do you need "set solib-search-path" or "set sysroot"? > [Thread debugging using libthread_db enabled] > Using host libthread_db library > "/lib/x86_64-linux-gnu/libthread_db.so.1". > [New Thread 0x7fffe630a700 (LWP 5175)] > [New Thread 0x7fffe5aa9700 (LWP 5176)] > [New Thread 0x7fffe52a8700 (LWP 5177)] > [New Thread 0x7fffe4aa7700 (LWP 5178)] > [New Thread 0x7fffd700 (LWP 5179)] > [New Thread 0x7fffdf7fe700 (LWP 5180)] > [New Thread 0x7fffdeffd700 (LWP 5181)] > [New Thread 0x7fffde7fc700 (LWP 5182)] > [New Thread 0x7fffddffb700 (LWP 5183)] > [New Thread 0x7fffdd7fa700 (LWP 5184)] > [New Thread 0x7fffdcff9700 (LWP 5185)] > ** Message: AgsRecallFactory creating: ags-delay > ** Message: AgsRecallFactory creating: ags-count-beats > ** Message: ags_channel_nth: > nth channel does not exist > `- stopped @: i = 0; nth = 0 > > ** Message: AgsRecallFactory creating: ags-copy-pattern > ** Message: ags_channel_nth: > nth channel does not exist > `- stopped @: i = 0; nth = 0 > > ** Message: debug: AGS_IS_COPY_PATTERN_AUDIO_RUN(packable) > > > Program received signal SIGSEGV, Segmentation fault. > [Switching to Thread 0x7fffddffb700 (LWP 5183)] > ags_task_thread_append_task_queue (thread=0x97a010) > at ./src/ags/thread/ags_task_thread.c:264 > 264 task_thread = append->task_thread; > > > > > (gdb) make ags > gcc -DHAVE_CONFIG_H -I. -I./src/ -I/usr/include/uuid > -I/usr/include/alsa-I/usr/include/libxml2 > -I/usr/include/libinstpatch-1.0 -I/usr/include/glib-2.0 > -I/usr/lib/x86_64-linux-gnu/glib-2.0/include -pthread > -I/usr/include/glib-2.0 -I/usr/lib/x86_64-linux-gnu/glib-2.0/include > -pthread -I/usr/include/gdk-pixbuf-2.0 -I/usr/include/glib-2.0 > -I/usr/lib/x86_64-linux-gnu/glib-2.0/include -I/usr/include/libpng12 > -I/usr/include/cairo -I/usr/include/glib-2.0 > -I/usr/lib/x86_64-linux-gnu/glib-2.0/include -I/usr/include/pixman-1 > -I/usr/include/freetype2 -I/usr/include/libpng12 -I/usr/include/libdrm > -pthread -I/usr/include/gtk-2.0 > -I/usr/lib/x86_64-linux-gnu/gtk-2.0/include -I/usr/include/atk-1.0 > -I/usr/include/cairo -I/usr/include/gdk-pixbuf-2.0 > -I/usr/include/pango-1.0 -I/usr/include/gio-unix-2.0/ > -I/usr/include/freetype2 -I/usr/include/glib-2.0 > -I/usr/lib/x86_64-linux-gnu/glib-2.0/include -I/usr/include/pixman-1 > -I/usr/include/libpng12 -I/usr/include/libdrm -I/usr/include/harfbuzz > -g -O2 -MT ags-ags_returnable_thread.o -MD -MP > -MF .deps/ags-ags_returnable_thread.Tpo -c -o > ags-ags_returnable_thread.o `test -f > './src/ags/thread/ags_returnable_thread.c' || echo > './'`./src/ags/thread/ags_returnable_thread.c > In file included > from /usr/lib/x86_64-linux-gnu/glib-2.0/include/glibconfig.h:9:0, > from /usr/include/glib-2.0/glib/gtypes.h:34, > from /usr/include/glib-2.0/glib/galloca.h:34, > from /usr/include/glib-2.0/glib.h:32, > from ./src/ags/thread/ags_returnable_thread.h:22, > from ./src/ags/thread/ags_returnable_thread.c:19: > ./src/ags/thread/ags_returnable_thread.c: In function > 'ags_returnable_thread_init': > /usr/include/glib-2.0/glib/gmacros.h:181:53: error: size of array > '_GStaticAssertCompileTimeAssertion_1' is negative > #define G_STATIC_ASSERT(expr) typedef char G_PASTE > (_GStaticAssertCompileTimeAssertion_, __COUNTER__)[(expr) ? 1 : -1] > G_GNUC_UNUSED > ^ > /usr/include/glib-2.0/glib/gmacros.h:178:47: note: in definition of > macro 'G_PASTE_ARGS' > #define G_PASTE_ARGS(identifier1,identifier2) identifier1 ## > identifier2 >^ > /usr/include/glib-2.0/glib/gmacros.h:181:44: note: in expansion of macro > 'G_PASTE' > #define G_STATIC_ASSERT(expr) typedef char G_PASTE > (_GStaticAssertCompileTimeAssertion_, __COUNTER__)[(expr) ? 1 : -1] > G_GNUC_UNUSED > ^ > /usr/include/glib-2.0/glib/gatomic.h:154:5: note: in expansion of macro > 'G_STATIC_ASSERT' > G_STATIC_ASSERT (sizeof *(atomic) == sizeof (gpointer)); > \ > ^ > ./src/ags/thread/ags_returnable_thread.c:108:3: note: in expansion of > macro 'g_atomic_pointer_set' >g_atomic_poi
Re: [Fwd: dereferencing void *]
On 03/23/2014 08:36 PM, Joël Krähemann wrote: > > The following will compile but is it still correct? > > g_atomic_pointer_set(&(returnable_thread->safe_data), >NULL); http://developer.gimp.org/api/2.0/glib/glib-Basic-Types.html#gpointer typedef void* gpointer; http://developer.gimp.org/api/2.0/glib/glib-Atomic-Operations.html void g_atomic_pointer_set (volatile gpointer *atomic, gpointer newval); struct _AgsReturnableThread { AgsThread thread; volatile guint flags; volatile void *safe_data; // volatile gpointer safe_data }; safe_data holds the address pointing to a void value(unassigned type). By putting &(blah->safe_data), you are asking for the address of the address pointing to a void value. That's not what you want. Just put (blah->safe_data, NULL). The compiler shouldn't complain. If it does, you could cast blah->safe_data with (volatile void*)(blah->safe_data) or (volatile gpointer)(blah->safe_data) Both equate to the same thing for the compiler. ___ gtk-app-devel-list mailing list gtk-app-devel-list@gnome.org https://mail.gnome.org/mailman/listinfo/gtk-app-devel-list
Re: [Fwd: dereferencing void *]
Le 24/03/2014 01:36, Joël Krähemann a écrit : > [...] > > The following will compile but is it still correct? > > g_atomic_pointer_set(&(returnable_thread->safe_data), >NULL); Yes, as the atomic_int* functions expect a pointer to the integer to atomically set, the atomic_pointer* ones expect a pointer to the pointer to atomically set. Cheers, Colomban ___ gtk-app-devel-list mailing list gtk-app-devel-list@gnome.org https://mail.gnome.org/mailman/listinfo/gtk-app-devel-list
Re: [Fwd: dereferencing void *]
Le 24/03/2014 02:11, David Marceau a écrit : > On 03/23/2014 08:36 PM, Joël Krähemann wrote: >> >> The following will compile but is it still correct? >> >> g_atomic_pointer_set(&(returnable_thread->safe_data), >>NULL); > http://developer.gimp.org/api/2.0/glib/glib-Basic-Types.html#gpointer > typedef void* gpointer; > > http://developer.gimp.org/api/2.0/glib/glib-Atomic-Operations.html > void g_atomic_pointer_set (volatile gpointer *atomic, gpointer newval); That's not the signature in current GLib, but that's actually correct, and means: void g_atomic_pointer_set (volatile void* *atomic, gpointer newval); hence, pointer to pointer. > struct _AgsReturnableThread > { > AgsThread thread; > volatile guint flags; > volatile void *safe_data; // volatile gpointer safe_data > }; > > safe_data holds the address pointing to a void value(unassigned type). > By putting &(blah->safe_data), you are asking for the address of the > address pointing to a void value. That's not what you want. Yes it is. The atomic pointer functions expect a pointer to the pointer to atomically set, not the pointer to set itself. > Just put (blah->safe_data, NULL). > The compiler shouldn't complain. it shouldn't using a real function, but then it would crash at runtime. Anyway, GLib has various compiler-specific implementation of the atomic operations, and the GCC one uses macros, which will detect the dereference of that pointer to void, which is invalid C. The macros does basically (a lot simplified): #define g_atomic_pointer_set(ptr, valure) \ ({ \ *(ptr) = (value); \ __sync(); \ }) > If it does, you could cast blah->safe_data with > (volatile void*)(blah->safe_data) > > or > > (volatile gpointer)(blah->safe_data) That's not a wise idea in case it'd hide some real issue, nor of any use, in C any pointer is a valid void*. And it wouldn't help here. Cheers, Colomban ___ gtk-app-devel-list mailing list gtk-app-devel-list@gnome.org https://mail.gnome.org/mailman/listinfo/gtk-app-devel-list
Re: [Fwd: dereferencing void *]
On 03/23/2014 09:52 PM, Colomban Wendling wrote: > Le 24/03/2014 02:11, David Marceau a écrit : >> On 03/23/2014 08:36 PM, Joël Krähemann wrote: >>> >>> The following will compile but is it still correct? >>> >>> g_atomic_pointer_set(&(returnable_thread->safe_data), >>>NULL); >> http://developer.gimp.org/api/2.0/glib/glib-Basic-Types.html#gpointer >> typedef void* gpointer; >> >> http://developer.gimp.org/api/2.0/glib/glib-Atomic-Operations.html >> void g_atomic_pointer_set (volatile gpointer *atomic, gpointer newval); My bad: volatile void* * Colomban is correct. > > That's not the signature in current GLib, but that's actually correct, > and means: > > void g_atomic_pointer_set (volatile void* *atomic, gpointer newval); > > hence, pointer to pointer. > >> struct _AgsReturnableThread >> { >> AgsThread thread; >> volatile guint flags; >> volatile void *safe_data; // volatile gpointer safe_data >> }; >> >> safe_data holds the address pointing to a void value(unassigned type). >> By putting &(blah->safe_data), you are asking for the address of the >> address pointing to a void value. That's not what you want. > > Yes it is. The atomic pointer functions expect a pointer to the pointer > to atomically set, not the pointer to set itself. > >> Just put (blah->safe_data, NULL). >> The compiler shouldn't complain. > > it shouldn't using a real function, but then it would crash at runtime. > Anyway, GLib has various compiler-specific implementation of the atomic > operations, and the GCC one uses macros, which will detect the > dereference of that pointer to void, which is invalid C. > > The macros does basically (a lot simplified): > > #define g_atomic_pointer_set(ptr, valure) \ > ({ \ > *(ptr) = (value); \ > __sync(); \ > }) > >> If it does, you could cast blah->safe_data with >> (volatile void*)(blah->safe_data) >> >> or >> >> (volatile gpointer)(blah->safe_data) > > That's not a wise idea in case it'd hide some real issue, nor of any > use, in C any pointer is a valid void*. And it wouldn't help here. > > Cheers, > Colomban > ___ > gtk-app-devel-list mailing list > gtk-app-devel-list@gnome.org > https://mail.gnome.org/mailman/listinfo/gtk-app-devel-list > ___ gtk-app-devel-list mailing list gtk-app-devel-list@gnome.org https://mail.gnome.org/mailman/listinfo/gtk-app-devel-list
Re: [Fwd: dereferencing void *]
On Mon, 2014-03-24 at 02:43 +0100, Colomban Wendling wrote: > Le 24/03/2014 01:36, Joël Krähemann a écrit : > > [...] > > > > The following will compile but is it still correct? > > > > g_atomic_pointer_set(&(returnable_thread->safe_data), > >NULL); > > Yes, as the atomic_int* functions expect a pointer to the integer to > atomically set, the atomic_pointer* ones expect a pointer to the pointer > to atomically set. > > Cheers, > Colomban > ___ > gtk-app-devel-list mailing list > gtk-app-devel-list@gnome.org > https://mail.gnome.org/mailman/listinfo/gtk-app-devel-list Thank you very much but g_atomic_pointer_set doesn't help me in this case. It still crashes with: Program received signal SIGSEGV, Segmentation fault. [Switching to Thread 0x7fffddffb700 (LWP 25872)] ags_task_thread_append_task_queue (thread=0x97a010) at ./src/ags/thread/ags_task_thread.c:266 266 task_thread = append->task_thread; (gdb) bt #0 ags_task_thread_append_task_queue (thread=0x97a010) at ./src/ags/thread/ags_task_thread.c:266 #1 0x74bca2df in ?? () from /usr/lib/x86_64-linux-gnu/libgobject-2.0.so.0 #2 0x74be2df8 in g_signal_emit_valist () from /usr/lib/x86_64-linux-gnu/libgobject-2.0.so.0 #3 0x74be3a52 in g_signal_emit () from /usr/lib/x86_64-linux-gnu/libgobject-2.0.so.0 #4 0x004aec46 in ags_thread_run (thread=0x97a010) at ./src/ags/thread/ags_thread.c:1718 #5 0x004aefd7 in ags_thread_loop (ptr=) at ./src/ags/thread/ags_thread.c:1641 #6 0x7377a062 in start_thread (arg=0x7fffddffb700) at pthread_create.c:312 #7 0x734aea3d in clone () at ../sysdeps/unix/sysv/linux/x86_64/clone.S:111 Here's what it does any idea why? void ags_task_thread_append_tasks_queue(AgsThread *thread) { AgsTask *task; AgsTaskThread *task_thread; AgsTaskThreadAppend *append; GList *list; gboolean initial_wait; int ret; append = (AgsTaskThreadAppend *) g_atomic_pointer_get(&(AGS_RETURNABLE_THREAD(thread)->safe_data)); task_thread = append->task_thread; list = (GList *) append->data; free(append); /* lock */ pthread_mutex_lock(&(task_thread->read_mutex)); /* append to queue */ task_thread->queued += g_list_length(list); task_thread->queue = g_list_concat(task_thread->queue, list); /* */ pthread_mutex_unlock(&(task_thread->read_mutex)); /* give back to pool */ ags_thread_stop(thread); } void ags_task_thread_append_tasks(AgsTaskThread *task_thread, GList *list) { AgsTaskThreadAppend *append; AgsThread *thread; g_message("tasks\0"); append = (AgsTaskThreadAppend *) malloc(sizeof(AgsTaskThreadAppend)); append->task_thread = task_thread; append->data = list; thread = ags_thread_pool_pull(task_thread->thread_pool); g_atomic_pointer_set(&(AGS_RETURNABLE_THREAD(thread)->safe_data), append); ags_thread_lock(thread); AGS_THREAD_GET_CLASS(thread)->run = ags_task_thread_append_tasks_queue; ags_thread_lock(thread); ags_thread_start(thread); } ___ gtk-app-devel-list mailing list gtk-app-devel-list@gnome.org https://mail.gnome.org/mailman/listinfo/gtk-app-devel-list