From 50439c9ca9a52f39681fb81bd6768f306125516a Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?=C4=90o=C3=A0n=20Tr=E1=BA=A7n=20C=C3=B4ng=20Danh?=
<congdanhqx@gmail.com>
Date: Tue, 15 Sep 2020 08:21:50 +0700
Subject: [PATCH 1/3] compat: add fallback implementation for reallocarray(3)
ZV: This is from https://gitlab.gnome.org/GNOME/sysprof/-/merge_requests/37.patch
modified to remove the meson-related bits, and add 'subprojects/sysprof'
---
src/libsysprof-capture/sysprof-capture-cursor.c | 4 +++-
src/libsysprof-capture/sysprof-capture-reader.c | 2 +-
.../sysprof-capture-util-private.h | 8 ++++++++
src/libsysprof-capture/sysprof-capture-util.c | 13 +++++++++++++
src/libsysprof-capture/sysprof-capture-writer-cat.c | 7 ++++---
6 files changed, 30 insertions(+), 5 deletions(-)
diff --git a/subprojects/sysprof/src/libsysprof-capture/sysprof-capture-cursor.c b/subprojects/sysprof/src/libsysprof-capture/sysprof-capture-cursor.c
index 24563f0a..cf11bcd5 100644
--- a/subprojects/sysprof/src/libsysprof-capture/sysprof-capture-cursor.c
+++ b/subprojects/sysprof/src/libsysprof-capture/sysprof-capture-cursor.c
@@ -293,7 +293,9 @@ sysprof_capture_cursor_add_condition (SysprofCaptureCursor *self,
*
* FIXME: There’s currently no error reporting from this function, so ENOMEM
* results in an abort. */
- self->conditions = reallocarray (self->conditions, ++self->n_conditions, sizeof (*self->conditions));
+ self->conditions = _sysprof_reallocarray (self->conditions,
+ ++self->n_conditions,
+ sizeof (*self->conditions));
assert (self->conditions != NULL);
self->conditions[self->n_conditions - 1] = sysprof_steal_pointer (&condition);
diff --git a/subprojects/sysprof/src/libsysprof-capture/sysprof-capture-reader.c b/subprojects/sysprof/src/libsysprof-capture/sysprof-capture-reader.c
index 67c6b28b..9a5aa912 100644
--- a/subprojects/sysprof/src/libsysprof-capture/sysprof-capture-reader.c
+++ b/subprojects/sysprof/src/libsysprof-capture/sysprof-capture-reader.c
@@ -1270,7 +1270,7 @@ array_append (const char ***files,
const char **new_files;
*n_files_allocated = (*n_files_allocated > 0) ? 2 * *n_files_allocated : 4;
- new_files = reallocarray (*files, *n_files_allocated, sizeof (**files));
+ new_files = _sysprof_reallocarray (*files, *n_files_allocated, sizeof (**files));
if (new_files == NULL)
return false;
*files = new_files;
diff --git a/subprojects/sysprof/src/libsysprof-capture/sysprof-capture-util-private.h b/subprojects/sysprof/src/libsysprof-capture/sysprof-capture-util-private.h
index 1b1d93e9..13ec1eed 100644
--- a/subprojects/sysprof/src/libsysprof-capture/sysprof-capture-util-private.h
+++ b/subprojects/sysprof/src/libsysprof-capture/sysprof-capture-util-private.h
@@ -108,3 +108,11 @@ size_t _sysprof_strlcpy (char *dest,
const char *src,
size_t dest_size);
#endif
+
+#ifdef HAVE_REALLOCARRAY
+# define _sysprof_reallocarray(p,m,n) reallocarray(p,m,n)
+#else
+void *_sysprof_reallocarray (void *ptr,
+ size_t m,
+ size_t n);
+#endif
diff --git a/subprojects/sysprof/src/libsysprof-capture/sysprof-capture-util.c b/subprojects/sysprof/src/libsysprof-capture/sysprof-capture-util.c
index 0bbea06a..acb71acf 100644
--- a/subprojects/sysprof/src/libsysprof-capture/sysprof-capture-util.c
+++ b/subprojects/sysprof/src/libsysprof-capture/sysprof-capture-util.c
@@ -58,6 +58,7 @@
#include <assert.h>
#include <errno.h>
+#include <stdint.h>
#include <unistd.h>
#ifdef _WIN32
@@ -253,3 +254,15 @@ size_t
return i;
}
+
+void *
+(_sysprof_reallocarray) (void *ptr,
+ size_t m,
+ size_t n)
+{
+ if (n && m > (size_t)(-1) / n) {
+ errno = ENOMEM;
+ return NULL;
+ }
+ return realloc(ptr, m * n);
+}
diff --git a/subprojects/sysprof/src/libsysprof-capture/sysprof-capture-writer-cat.c b/subprojects/sysprof/src/libsysprof-capture/sysprof-capture-writer-cat.c
index 66171b92..a157ed73 100644
--- a/subprojects/sysprof/src/libsysprof-capture/sysprof-capture-writer-cat.c
+++ b/subprojects/sysprof/src/libsysprof-capture/sysprof-capture-writer-cat.c
@@ -64,6 +64,7 @@
#include <unistd.h>
#include "sysprof-capture.h"
+#include "sysprof-capture-util-private.h"
#include "sysprof-macros-internal.h"
typedef struct
@@ -133,7 +134,7 @@ translate_table_add (TranslateTable *tables,
if (table_ptr->n_items == table_ptr->n_items_allocated)
{
table_ptr->n_items_allocated = (table_ptr->n_items_allocated > 0) ? table_ptr->n_items_allocated * 2 : 4;
- table_ptr->items = reallocarray (table_ptr->items, table_ptr->n_items_allocated, sizeof (*table_ptr->items));
+ table_ptr->items = _sysprof_reallocarray (table_ptr->items, table_ptr->n_items_allocated, sizeof (*table_ptr->items));
assert (table_ptr->items != NULL);
}
@@ -481,8 +482,8 @@ sysprof_capture_writer_cat (SysprofCaptureWriter *self,
if (n_elements == n_elements_allocated)
{
n_elements_allocated = (n_elements_allocated > 0) ? n_elements_allocated * 2 : 4;
- ids = reallocarray (ids, n_elements_allocated, sizeof (*ids));
- values = reallocarray (values, n_elements_allocated, sizeof (*values));
+ ids = _sysprof_reallocarray (ids, n_elements_allocated, sizeof (*ids));
+ values = _sysprof_reallocarray (values, n_elements_allocated, sizeof (*values));
if (ids == NULL || values == NULL)
goto panic;
}
--
GitLab
From 429223635e5a9a1de7903465ae1e8a5eb6d61be9 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?=C4=90o=C3=A0n=20Tr=E1=BA=A7n=20C=C3=B4ng=20Danh?=
<congdanhqx@gmail.com>
Date: Tue, 15 Sep 2020 08:47:12 +0700
Subject: [PATCH 2/3] compat: add TEMP_FAILURE_RETRY compatiable implementation
---
src/libsysprof-capture/sysprof-capture-util-private.h | 9 +++++++++
1 file changed, 9 insertions(+)
diff --git a/subprojects/sysprof/src/libsysprof-capture/sysprof-capture-util-private.h b/subprojects/sysprof/src/libsysprof-capture/sysprof-capture-util-private.h
index 13ec1eed..6181212c 100644
--- a/subprojects/sysprof/src/libsysprof-capture/sysprof-capture-util-private.h
+++ b/subprojects/sysprof/src/libsysprof-capture/sysprof-capture-util-private.h
@@ -60,10 +60,19 @@
# include <sys/sendfile.h>
#endif
+#include <errno.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
+#ifndef TEMP_FAILURE_RETRY
+#define TEMP_FAILURE_RETRY(expression) \
+ ({ long int __result; \
+ do { __result = (long int) (expression); } \
+ while (__result == -1L && errno == EINTR); \
+ __result; })
+#endif
+
static inline void *
sysprof_malloc0 (size_t size)
{
--
GitLab
From 088408c085e5d668c872769391787481875293a6 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?=C4=90o=C3=A0n=20Tr=E1=BA=A7n=20C=C3=B4ng=20Danh?=
<congdanhqx@gmail.com>
Date: Tue, 15 Sep 2020 20:51:28 +0700
Subject: [PATCH 3/3] sysprof-capture-condition: always return even if
unreachable
Fix the problem with -Werror=return-type
---
src/libsysprof-capture/sysprof-capture-condition.c | 1 +
1 file changed, 1 insertion(+)
diff --git a/subprojects/sysprof/src/libsysprof-capture/sysprof-capture-condition.c b/subprojects/sysprof/src/libsysprof-capture/sysprof-capture-condition.c
index 8f891577..4b829a98 100644
--- a/subprojects/sysprof/src/libsysprof-capture/sysprof-capture-condition.c
+++ b/subprojects/sysprof/src/libsysprof-capture/sysprof-capture-condition.c
@@ -269,6 +269,7 @@ sysprof_capture_condition_copy (const SysprofCaptureCondition *self)
}
sysprof_assert_not_reached ();
+ return NULL;
}
static void
--
GitLab