glib2: share duplicated code