Fix build when char and signed char differ

https://gitlab.gnome.org/GNOME/gjs/-/merge_requests/825
This commit is contained in:
David King 2023-02-23 21:06:44 +00:00
parent df2f27c0f5
commit bcb88871ab
2 changed files with 67 additions and 0 deletions

View File

@ -0,0 +1,65 @@
From 3dce1d6b1885f326c55aed9e1d401ac79801396a Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Marco=20Trevisan=20=28Trevi=C3=B1o=29?= <mail@3v1n0.net>
Date: Thu, 23 Feb 2023 21:46:59 +0100
Subject: [PATCH 1/2] value: Use a signed char to old g_value_get_schar result
char and signed char are the same in most of platforms, but that's not
always true such as in arm64, s390x, ppc64el and others.
See: https://buildd.debian.org/status/fetch.php?pkg=gjs&arch=arm64&ver=1.75.2-1&stamp=1676991213&raw=0
Closes: #529
---
gi/value.cpp | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/gi/value.cpp b/gi/value.cpp
index 2e2f49aa2..651c21ad3 100644
--- a/gi/value.cpp
+++ b/gi/value.cpp
@@ -881,7 +881,7 @@ gjs_value_from_g_value_internal(JSContext *context,
return false;
}
} else if (gtype == G_TYPE_CHAR) {
- char v;
+ signed char v;
v = g_value_get_schar(gvalue);
value_p.setInt32(v);
} else if (gtype == G_TYPE_UCHAR) {
--
GitLab
From 86a66ea412a725caa59d9fa41ea333117406768e Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Marco=20Trevisan=20=28Trevi=C3=B1o=29?= <mail@3v1n0.net>
Date: Thu, 23 Feb 2023 21:53:16 +0100
Subject: [PATCH 2/2] gi/value: Cleanup schar setting code
We still need to use an int32 to hold its result (as that's where a
signed char is stored in JS), but if the conversion is fine we need to
cast its value to signed char. Do it using C++ style now though.
---
gi/value.cpp | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/gi/value.cpp b/gi/value.cpp
index 651c21ad3..17db002f6 100644
--- a/gi/value.cpp
+++ b/gi/value.cpp
@@ -458,11 +458,11 @@ gjs_value_to_g_value_internal(JSContext *context,
return throw_expect_type(context, value, "string");
}
} else if (gtype == G_TYPE_CHAR) {
- gint32 i;
+ int32_t i;
if (Gjs::js_value_to_c_checked<signed char>(context, value, &i,
&out_of_range) &&
!out_of_range) {
- g_value_set_schar(gvalue, (signed char)i);
+ g_value_set_schar(gvalue, static_cast<signed char>(i));
} else {
return throw_expect_type(context, value, "char", 0, out_of_range);
}
--
GitLab

View File

@ -14,6 +14,8 @@ Summary: Javascript Bindings for GNOME
License: MIT and (MPLv1.1 or GPLv2+ or LGPLv2+)
URL: https://wiki.gnome.org/Projects/Gjs
Source0: https://download.gnome.org/sources/%{name}/1.75/%{name}-%{version}.tar.xz
# https://gitlab.gnome.org/GNOME/gjs/-/merge_requests/825
Patch0: gjs-1.75.2-signed-char.patch
BuildRequires: gcc-c++
BuildRequires: meson