New upstream version 2022.7

This commit is contained in:
Simon McVittie committed 2022-11-25 09:52:36 +00:00
commit 0a29322640
82 files changed
+2820 -2348

No files matched your search

+2
View File
@@ -33,6 +33,8 @@ libglnx_la_SOURCES = \
$(libglnx_srcpath)/glnx-macros.h \
$(libglnx_srcpath)/glnx-backport-autocleanups.h \
$(libglnx_srcpath)/glnx-backport-autoptr.h \
$(libglnx_srcpath)/glnx-backport-testutils.h \
$(libglnx_srcpath)/glnx-backport-testutils.c \
$(libglnx_srcpath)/glnx-backports.h \
$(libglnx_srcpath)/glnx-backports.c \
$(libglnx_srcpath)/glnx-local-alloc.h \
+2
View File
@@ -33,6 +33,8 @@ libglnx_la_SOURCES = \
libglnx/glnx-macros.h \
libglnx/glnx-backport-autocleanups.h \
libglnx/glnx-backport-autoptr.h \
libglnx/glnx-backport-testutils.h \
libglnx/glnx-backport-testutils.c \
libglnx/glnx-backports.h \
libglnx/glnx-backports.c \
libglnx/glnx-local-alloc.h \
+145
View File
@@ -0,0 +1,145 @@
/* -*- mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*-
*
* Copyright 2015 Colin Walters
* Copyright 2020 Niels De Graef
* Copyright 2021-2022 Collabora Ltd.
* SPDX-License-Identifier: LGPL-2.1-or-later
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published
* by the Free Software Foundation; either version 2.1 of the licence or (at
* your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General
* Public License along with this library; if not, write to the
* Free Software Foundation, Inc., 59 Temple Place, Suite 330,
* Boston, MA 02111-1307, USA.
*/
#include "libglnx-config.h"
#include <string.h>
#include <unistd.h>
#include <glib/gprintf.h>
#include "glnx-backport-autocleanups.h"
#include "glnx-backport-autoptr.h"
#include "glnx-backport-testutils.h"
#include "glnx-backports.h"
#if !GLIB_CHECK_VERSION (2, 68, 0)
/* Backport of g_assertion_message_cmpstrv() */
void
_glnx_assertion_message_cmpstrv (const char *domain,
const char *file,
int line,
const char *func,
const char *expr,
const char * const *arg1,
const char * const *arg2,
gsize first_wrong_idx)
{
const char *s1 = arg1[first_wrong_idx], *s2 = arg2[first_wrong_idx];
char *a1, *a2, *s, *t1 = NULL, *t2 = NULL;
a1 = g_strconcat ("\"", t1 = g_strescape (s1, NULL), "\"", NULL);
a2 = g_strconcat ("\"", t2 = g_strescape (s2, NULL), "\"", NULL);
g_free (t1);
g_free (t2);
s = g_strdup_printf ("assertion failed (%s): first differing element at index %" G_GSIZE_FORMAT ": %s does not equal %s",
expr, first_wrong_idx, a1, a2);
g_free (a1);
g_free (a2);
g_assertion_message (domain, file, line, func, s);
g_free (s);
}
#endif
#if !GLIB_CHECK_VERSION(2, 70, 0)
/*
* Same as g_test_message(), but split messages with newlines into
* multiple separate messages to avoid corrupting stdout, even in older
* GLib versions that didn't do this
*/
void
_glnx_test_message_safe (const char *format,
...)
{
g_autofree char *message = NULL;
va_list ap;
char *line;
char *saveptr = NULL;
va_start (ap, format);
g_vasprintf (&message, format, ap);
va_end (ap);
for (line = strtok_r (message, "\n", &saveptr);
line != NULL;
line = strtok_r (NULL, "\n", &saveptr))
(g_test_message) ("%s", line);
}
/* Backport of g_test_fail_printf() */
void
_glnx_test_fail_printf (const char *format,
...)
{
g_autofree char *message = NULL;
va_list ap;
va_start (ap, format);
g_vasprintf (&message, format, ap);
va_end (ap);
/* This is the closest we can do in older GLib */
g_test_message ("Bail out! %s", message);
g_test_fail ();
}
/* Backport of g_test_skip_printf() */
void
_glnx_test_skip_printf (const char *format,
...)
{
g_autofree char *message = NULL;
va_list ap;
va_start (ap, format);
g_vasprintf (&message, format, ap);
va_end (ap);
g_test_skip (message);
}
/* Backport of g_test_incomplete_printf() */
void
_glnx_test_incomplete_printf (const char *format,
...)
{
g_autofree char *message = NULL;
va_list ap;
va_start (ap, format);
g_vasprintf (&message, format, ap);
va_end (ap);
#if GLIB_CHECK_VERSION(2, 58, 0)
/* Since 2.58, g_test_incomplete() sets the exit status correctly. */
g_test_incomplete (message);
#elif GLIB_CHECK_VERSION (2, 38, 0)
/* Before 2.58, g_test_incomplete() was treated like a failure for the
* purposes of setting the exit status, so prefer to use (our wrapper
* around) g_test_skip(). */
g_test_skip_printf ("TODO: %s", message);
#else
g_test_message ("TODO: %s", message);
#endif
}
#endif
+204
View File
@@ -0,0 +1,204 @@
/* -*- mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*-
*
* Copyright 1995-1997 Peter Mattis, Spencer Kimball and Josh MacDonald
* Copyright 2015 Colin Walters <walters@verbum.org>
* Copyright 2014 Dan Winship
* Copyright 2015 Colin Walters
* Copyright 2017 Emmanuele Bassi
* Copyright 2018-2019 Endless OS Foundation LLC
* Copyright 2020 Niels De Graef
* Copyright 2021-2022 Collabora Ltd.
* SPDX-License-Identifier: LGPL-2.1-or-later
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the
* Free Software Foundation, Inc., 59 Temple Place - Suite 330,
* Boston, MA 02111-1307, USA.
*/
#pragma once
#include <gio/gio.h>
#include "glnx-backports.h"
G_BEGIN_DECLS
#ifndef g_assert_true /* added in 2.38 */
#define g_assert_true(x) g_assert ((x))
#endif
#ifndef g_assert_false /* added in 2.38 */
#define g_assert_false(x) g_assert (!(x))
#endif
#ifndef g_assert_nonnull /* added in 2.40 */
#define g_assert_nonnull(x) g_assert (x != NULL)
#endif
#ifndef g_assert_null /* added in 2.40 */
#define g_assert_null(x) g_assert (x == NULL)
#endif
#if !GLIB_CHECK_VERSION (2, 38, 0)
/* Not exactly equivalent, but close enough */
#define g_test_skip(s) g_test_message ("SKIP: %s", s)
#endif
#if !GLIB_CHECK_VERSION (2, 58, 0)
/* Before 2.58, g_test_incomplete() didn't set the exit status correctly */
#define g_test_incomplete(s) _glnx_test_incomplete_printf ("%s", s)
#endif
#if !GLIB_CHECK_VERSION (2, 46, 0)
#define g_assert_cmpmem(m1, l1, m2, l2) G_STMT_START {\
gconstpointer __m1 = m1, __m2 = m2; \
int __l1 = l1, __l2 = l2; \
if (__l1 != 0 && __m1 == NULL) \
g_assertion_message (G_LOG_DOMAIN, __FILE__, __LINE__, G_STRFUNC, \
"assertion failed (" #l1 " == 0 || " #m1 " != NULL)"); \
else if (__l2 != 0 && __m2 == NULL) \
g_assertion_message (G_LOG_DOMAIN, __FILE__, __LINE__, G_STRFUNC, \
"assertion failed (" #l2 " == 0 || " #m2 " != NULL)"); \
else if (__l1 != __l2) \
g_assertion_message_cmpnum (G_LOG_DOMAIN, __FILE__, __LINE__, G_STRFUNC, \
#l1 " (len(" #m1 ")) == " #l2 " (len(" #m2 "))", \
(long double) __l1, "==", (long double) __l2, 'i'); \
else if (__l1 != 0 && __m2 != NULL && memcmp (__m1, __m2, __l1) != 0) \
g_assertion_message (G_LOG_DOMAIN, __FILE__, __LINE__, G_STRFUNC, \
"assertion failed (" #m1 " == " #m2 ")"); \
} G_STMT_END
#endif
#if !GLIB_CHECK_VERSION (2, 58, 0)
#define g_assert_cmpfloat_with_epsilon(n1,n2,epsilon) \
G_STMT_START { \
double __n1 = (n1), __n2 = (n2), __epsilon = (epsilon); \
if (G_APPROX_VALUE (__n1, __n2, __epsilon)) ; else \
g_assertion_message_cmpnum (G_LOG_DOMAIN, __FILE__, __LINE__, G_STRFUNC, \
#n1 " == " #n2 " (+/- " #epsilon ")", __n1, "==", __n2, 'f'); \
} G_STMT_END
#endif
#if !GLIB_CHECK_VERSION (2, 60, 0)
#define g_assert_cmpvariant(v1, v2) \
G_STMT_START \
{ \
GVariant *__v1 = (v1), *__v2 = (v2); \
if (!g_variant_equal (__v1, __v2)) \
{ \
gchar *__s1, *__s2, *__msg; \
__s1 = g_variant_print (__v1, TRUE); \
__s2 = g_variant_print (__v2, TRUE); \
__msg = g_strdup_printf ("assertion failed (" #v1 " == " #v2 "): %s does not equal %s", __s1, __s2); \
g_assertion_message (G_LOG_DOMAIN, __FILE__, __LINE__, G_STRFUNC, __msg); \
g_free (__s1); \
g_free (__s2); \
g_free (__msg); \
} \
} \
G_STMT_END
#endif
#if !GLIB_CHECK_VERSION (2, 62, 0)
/* Not exactly equivalent, but close enough */
#define g_test_summary(s) g_test_message ("SUMMARY: %s", s)
#endif
#if !GLIB_CHECK_VERSION (2, 66, 0)
#define g_assert_no_errno(expr) G_STMT_START { \
int __ret, __errsv; \
errno = 0; \
__ret = expr; \
__errsv = errno; \
if (__ret < 0) \
{ \
gchar *__msg; \
__msg = g_strdup_printf ("assertion failed (" #expr " >= 0): errno %i: %s", __errsv, g_strerror (__errsv)); \
g_assertion_message (G_LOG_DOMAIN, __FILE__, __LINE__, G_STRFUNC, __msg); \
g_free (__msg); \
} \
} G_STMT_END
#endif
#if !GLIB_CHECK_VERSION (2, 68, 0)
#define g_assertion_message_cmpstrv _glnx_assertion_message_cmpstrv
void _glnx_assertion_message_cmpstrv (const char *domain,
const char *file,
int line,
const char *func,
const char *expr,
const char * const *arg1,
const char * const *arg2,
gsize first_wrong_idx);
#define g_assert_cmpstrv(strv1, strv2) \
G_STMT_START \
{ \
const char * const *__strv1 = (const char * const *) (strv1); \
const char * const *__strv2 = (const char * const *) (strv2); \
if (!__strv1 || !__strv2) \
{ \
if (__strv1) \
{ \
g_assertion_message (G_LOG_DOMAIN, __FILE__, __LINE__, G_STRFUNC, \
"assertion failed (" #strv1 " == " #strv2 "): " #strv2 " is NULL, but " #strv1 " is not"); \
} \
else if (__strv2) \
{ \
g_assertion_message (G_LOG_DOMAIN, __FILE__, __LINE__, G_STRFUNC, \
"assertion failed (" #strv1 " == " #strv2 "): " #strv1 " is NULL, but " #strv2 " is not"); \
} \
} \
else \
{ \
guint __l1 = g_strv_length ((char **) __strv1); \
guint __l2 = g_strv_length ((char **) __strv2); \
if (__l1 != __l2) \
{ \
char *__msg; \
__msg = g_strdup_printf ("assertion failed (" #strv1 " == " #strv2 "): length %u does not equal length %u", __l1, __l2); \
g_assertion_message (G_LOG_DOMAIN, __FILE__, __LINE__, G_STRFUNC, __msg); \
g_free (__msg); \
} \
else \
{ \
guint __i; \
for (__i = 0; __i < __l1; __i++) \
{ \
if (g_strcmp0 (__strv1[__i], __strv2[__i]) != 0) \
{ \
g_assertion_message_cmpstrv (G_LOG_DOMAIN, __FILE__, __LINE__, G_STRFUNC, \
#strv1 " == " #strv2, \
__strv1, __strv2, __i); \
} \
} \
} \
} \
} \
G_STMT_END
#endif
#if !GLIB_CHECK_VERSION (2, 70, 0)
/* Before 2.70, diagnostic messages containing newlines were problematic */
#define g_test_message(...) _glnx_test_message_safe (__VA_ARGS__)
void _glnx_test_message_safe (const char *format, ...) G_GNUC_PRINTF (1, 2);
#define g_test_fail_printf _glnx_test_fail_printf
void _glnx_test_fail_printf (const char *format, ...) G_GNUC_PRINTF (1, 2);
#define g_test_skip_printf _glnx_test_skip_printf
void _glnx_test_skip_printf (const char *format, ...) G_GNUC_PRINTF (1, 2);
#define g_test_incomplete_printf _glnx_test_incomplete_printf
void _glnx_test_incomplete_printf (const char *format, ...) G_GNUC_PRINTF (1, 2);
#endif
G_END_DECLS
+66 -11
View File
@@ -1,7 +1,10 @@
/* -*- mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*-
*
* Copyright 1998 Manish Singh
* Copyright 1998 Tim Janik
* Copyright (C) 2015 Colin Walters <walters@verbum.org>
* SPDX-License-Identifier: LGPL-2.0-or-later
* Copyright 2017 Emmanuele Bassi
* SPDX-License-Identifier: LGPL-2.1-or-later
*
* GLIB - Library of useful routines for C programming
* Copyright (C) 1995-1997 Peter Mattis, Spencer Kimball and Josh MacDonald
@@ -9,7 +12,7 @@
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
@@ -17,13 +20,13 @@
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the
* Free Software Foundation, Inc., 59 Temple Place - Suite 330,
* Boston, MA 02111-1307, USA.
* License along with this library; if not, see <http://www.gnu.org/licenses/>.
*/
#pragma once
#include <string.h>
#include <gio/gio.h>
G_BEGIN_DECLS
@@ -48,6 +51,10 @@ G_BEGIN_DECLS
} G_STMT_END
#endif
#if !GLIB_CHECK_VERSION(2, 40, 0)
#define g_info(...) g_log (G_LOG_DOMAIN, G_LOG_LEVEL_INFO, __VA_ARGS__)
#endif
#if !GLIB_CHECK_VERSION(2, 44, 0)
#define g_strv_contains glnx_strv_contains
@@ -64,16 +71,64 @@ gboolean glnx_set_object (GObject **object_ptr,
#endif /* !GLIB_CHECK_VERSION(2, 44, 0) */
#ifndef g_assert_nonnull
#define g_assert_nonnull(x) g_assert (x != NULL)
#if !GLIB_CHECK_VERSION(2, 38, 0)
#define G_SPAWN_DEFAULT ((GSpawnFlags) 0)
#endif
#ifndef g_assert_null
#define g_assert_null(x) g_assert (x == NULL)
#if !GLIB_CHECK_VERSION(2, 42, 0)
#define G_OPTION_FLAG_NONE ((GOptionFlags) 0)
#endif
#if !GLIB_CHECK_VERSION (2, 38, 0)
#define g_test_skip(s) g_test_message ("SKIP: %s", s)
#ifndef G_DBUS_METHOD_INVOCATION_HANDLED /* added in 2.68 */
#define G_DBUS_METHOD_INVOCATION_HANDLED TRUE
#endif
#ifndef G_DBUS_METHOD_INVOCATION_UNHANDLED /* added in 2.68 */
#define G_DBUS_METHOD_INVOCATION_UNHANDLED FALSE
#endif
#if !GLIB_CHECK_VERSION(2, 68, 0)
static inline gpointer _glnx_memdup2 (gconstpointer mem,
gsize byte_size) G_GNUC_ALLOC_SIZE(2);
static inline gpointer
_glnx_memdup2 (gconstpointer mem,
gsize byte_size)
{
gpointer new_mem;
if (mem && byte_size != 0)
{
new_mem = g_malloc (byte_size);
memcpy (new_mem, mem, byte_size);
}
else
new_mem = NULL;
return new_mem;
}
#define g_memdup2 _glnx_memdup2
#endif
#ifndef G_OPTION_ENTRY_NULL /* added in 2.70 */
#define G_OPTION_ENTRY_NULL { NULL, 0, 0, 0, NULL, NULL, NULL }
#endif
#ifndef G_APPROX_VALUE /* added in 2.58 */
#define G_APPROX_VALUE(a, b, epsilon) \
(((a) > (b) ? (a) - (b) : (b) - (a)) < (epsilon))
#endif
#if !GLIB_CHECK_VERSION(2, 74, 0)
#define G_APPLICATION_DEFAULT_FLAGS ((GApplicationFlags) 0)
#define G_CONNECT_DEFAULT ((GConnectFlags) 0)
#define G_IO_FLAG_NONE ((GIOFlags) 0)
#define G_MARKUP_DEFAULT_FLAGS ((GMarkupParseFlags) 0)
#define G_REGEX_DEFAULT ((GRegexCompileFlags) 0)
#define G_REGEX_MATCH_DEFAULT ((GRegexMatchFlags) 0)
#define G_TEST_SUBPROCESS_DEFAULT ((GTestSubprocessFlags) 0)
#define G_TEST_TRAP_DEFAULT ((GTestTrapFlags) 0)
#define G_TLS_CERTIFICATE_NO_FLAGS ((GTlsCertificateFlags) 0)
#define G_TYPE_FLAG_NONE ((GTypeFlags) 0)
#endif
G_END_DECLS
+1
View File
@@ -29,6 +29,7 @@ G_BEGIN_DECLS
#include <glnx-missing.h>
#include <glnx-local-alloc.h>
#include <glnx-backport-autocleanups.h>
#include <glnx-backport-testutils.h>
#include <glnx-backports.h>
#include <glnx-lockfile.h>
#include <glnx-errors.h>
+1 -2
View File
@@ -67,8 +67,7 @@ _glnx_test_auto_temp_dir_leave (_GLnxTestAutoTempDir *dir)
glnx_tmpdir_delete (&dir->temp_dir, NULL, &error);
g_assert_no_error (error);
g_close (dir->old_cwd_fd, &error);
g_assert_no_error (error);
glnx_close_fd (&dir->old_cwd_fd);
g_free (dir->old_cwd);
g_free (dir);
+8
View File
@@ -26,6 +26,13 @@
#include <gio/gio.h>
#include <string.h>
static void
test_info (void)
{
g_info ("hello, world");
g_info ("answer=%d", 42);
}
static void
test_inset (void)
{
@@ -104,6 +111,7 @@ test_hash_table_foreach (void)
int main (int argc, char **argv)
{
g_test_init (&argc, &argv, NULL);
g_test_add_func ("/info", test_info);
g_test_add_func ("/inset", test_inset);
g_test_add_func ("/hash_table_foreach", test_hash_table_foreach);
return g_test_run();