[Pkg-ocaml-maint-commits] [ocaml-ctypes] 01/02: Initialize the return slot for small return values from callbacks
Stéphane Glondu
glondu at moszumanska.debian.org
Tue Jun 21 09:17:11 UTC 2016
This is an automated email from the git hooks/post-receive script.
glondu pushed a commit to branch master
in repository ocaml-ctypes.
commit e64690b1708aa46e9cf5b2b65e4830022a260a71
Author: Stephane Glondu <steph at glondu.net>
Date: Tue Jun 21 09:04:49 2016 +0200
Initialize the return slot for small return values from callbacks
---
...the-return-slot-for-small-return-values-f.patch | 64 ++++++++++++++++++++++
debian/patches/series | 1 +
2 files changed, 65 insertions(+)
diff --git a/debian/patches/0003-Initialize-the-return-slot-for-small-return-values-f.patch b/debian/patches/0003-Initialize-the-return-slot-for-small-return-values-f.patch
new file mode 100644
index 0000000..d2b59f8
--- /dev/null
+++ b/debian/patches/0003-Initialize-the-return-slot-for-small-return-values-f.patch
@@ -0,0 +1,64 @@
+From: Stephane Glondu <steph at glondu.net>
+Date: Tue, 21 Jun 2016 09:02:38 +0200
+Subject: Initialize the return slot for small return values from callbacks
+
+Origin: https://github.com/ocamllabs/ocaml-ctypes/pull/406
+Bug: https://github.com/ocamllabs/ocaml-ctypes/issues/404
+---
+ src/ctypes-foreign-base/ffi_call_stubs.c | 25 +++++++++++++++++++------
+ 1 file changed, 19 insertions(+), 6 deletions(-)
+
+diff --git a/src/ctypes-foreign-base/ffi_call_stubs.c b/src/ctypes-foreign-base/ffi_call_stubs.c
+index af5f214..6a0090f 100644
+--- a/src/ctypes-foreign-base/ffi_call_stubs.c
++++ b/src/ctypes-foreign-base/ffi_call_stubs.c
+@@ -256,12 +256,9 @@ value ctypes_add_argument(value callspec_, value argument_)
+ CAMLreturn(Val_int(offset));
+ }
+
+-
+-static int ffi_return_type_adjustment(ffi_type *f)
++static int ffi_return_type_promotes(ffi_type *f)
+ {
+-#ifdef ARCH_BIG_ENDIAN
+- /* An adjustment is needed (on bigendian systems) for integer types
+- less than the size of a word */
++ /* libffi promotes integer return types that are smaller than a word */
+ if (f->size < sizeof(ffi_arg)) {
+ switch (f->type) {
+ case FFI_TYPE_INT:
+@@ -273,10 +270,21 @@ static int ffi_return_type_adjustment(ffi_type *f)
+ case FFI_TYPE_SINT32:
+ case FFI_TYPE_UINT64:
+ case FFI_TYPE_SINT64:
+- return sizeof(ffi_arg) - f->size;
++ return 1;
+ default: break;
+ }
+ }
++ return 0;
++}
++
++static int ffi_return_type_adjustment(ffi_type *f)
++{
++#ifdef ARCH_BIG_ENDIAN
++ /* An adjustment is needed (on bigendian systems) for integer types
++ less than the size of a word */
++ if (ffi_return_type_promotes(f)) {
++ sizeof(ffi_arg) - f->size;
++ }
+ #endif
+ return 0;
+ }
+@@ -462,6 +470,11 @@ static void callback_handler_with_lock(ffi_cif *cif,
+
+ /* now store the return value */
+ assert (Tag_val(boxedfn) == Done);
++
++ if (ffi_return_type_promotes(cif->rtype)) {
++ *(ffi_arg *)ret = 0;
++ }
++
+ argptr = CTYPES_FROM_PTR(ret + ffi_return_type_adjustment(cif->rtype));
+ caml_callback(Field(boxedfn, 0), argptr);
+
diff --git a/debian/patches/series b/debian/patches/series
index 1767e8d..e76d4c3 100644
--- a/debian/patches/series
+++ b/debian/patches/series
@@ -1,2 +1,3 @@
0001-Use-the-same-C-compiler-as-OCaml-to-build-test-stubs.patch
0002-Fix-for-PowerPC-handle-libffi-s-integer-return-type-.patch
+0003-Initialize-the-return-slot-for-small-return-values-f.patch
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-ocaml-maint/packages/ocaml-ctypes.git
More information about the Pkg-ocaml-maint-commits
mailing list