aboutsummaryrefslogtreecommitdiffstats
path: root/lib/erl_interface
diff options
context:
space:
mode:
Diffstat (limited to 'lib/erl_interface')
-rw-r--r--lib/erl_interface/configure.in4
-rw-r--r--lib/erl_interface/src/legacy/erl_marshal.c40
-rw-r--r--lib/erl_interface/src/misc/ei_portio.h9
-rw-r--r--lib/erl_interface/src/misc/show_msg.c2
-rw-r--r--lib/erl_interface/test/ei_decode_SUITE_data/ei_decode_test.c10
-rw-r--r--lib/erl_interface/test/runner.erl6
6 files changed, 50 insertions, 21 deletions
diff --git a/lib/erl_interface/configure.in b/lib/erl_interface/configure.in
index 9e52a2adcf..0a8fbf513c 100644
--- a/lib/erl_interface/configure.in
+++ b/lib/erl_interface/configure.in
@@ -100,7 +100,9 @@ AC_CHECK_SIZEOF(long)
AC_CHECK_SIZEOF(void *)
AC_CHECK_SIZEOF(long long)
-if test $ac_cv_sizeof_void_p = 8; then
+dnl We set EI_64BIT mode when long is 8 bytes, this makes things
+dnl work on windows and unix correctly
+if test $ac_cv_sizeof_long = 8; then
CFLAGS="$CFLAGS -DEI_64BIT"
fi
diff --git a/lib/erl_interface/src/legacy/erl_marshal.c b/lib/erl_interface/src/legacy/erl_marshal.c
index 3c212bf177..2bdf5f2134 100644
--- a/lib/erl_interface/src/legacy/erl_marshal.c
+++ b/lib/erl_interface/src/legacy/erl_marshal.c
@@ -767,6 +767,13 @@ static ETERM *erl_decode_it(unsigned char **ext)
((*ext)[2]) << 8 |((*ext)[3]);
*ext += 4;
big_cont:
+
+#ifdef _MSC_VER
+#define MAX_TO_NEGATE 0x8000000000000000Ui64
+#else
+#define MAX_TO_NEGATE 0x8000000000000000ULL
+#endif
+
sign = *(*ext)++;
if (arity > 8)
goto big_truncate;
@@ -803,23 +810,28 @@ static ETERM *erl_decode_it(unsigned char **ext)
*ext += arity;
return ep;
} else {
- /* Fits in a long long */
- int x;
- long long l = 0LL;
+ /* Fits in a signed long long */
+ int x;
+ unsigned long long l = 0LL;
+ long long sl;
- for(x = 0 ; x < arity ; x++) {
- l |= ((long long)(*ext)[x]) << ((long long)(8*x));
- }
- if (sign) {
- l = -l;
- if (l > 0) goto big_truncate;
- }
+ for(x = 0 ; x < arity ; x++) {
+ l |= ((unsigned long long)(*ext)[x]) << ((unsigned long long)(8*x));
+ }
- ERL_TYPE(ep) = ERL_LONGLONG;
- ep->uval.llval.i = l;
- *ext += arity;
- return ep;
+ sl = (long long)l;
+
+ if (sign && l != MAX_TO_NEGATE) {
+ sl = -sl;
+ if (sl > 0) goto big_truncate;
+ }
+
+ ERL_TYPE(ep) = ERL_LONGLONG;
+ ep->uval.llval.i = sl;
+ *ext += arity;
+ return ep;
}
+#undef MAX_TO_NEGATE
big_truncate:
/* truncate to: (+/-) 1 */
#ifdef DEBUG
diff --git a/lib/erl_interface/src/misc/ei_portio.h b/lib/erl_interface/src/misc/ei_portio.h
index a14fdbd7d1..fbb61b0ccf 100644
--- a/lib/erl_interface/src/misc/ei_portio.h
+++ b/lib/erl_interface/src/misc/ei_portio.h
@@ -21,6 +21,12 @@
*/
#ifndef _EI_PORTIO_H
#define _EI_PORTIO_H
+#if !defined(__WIN32__) || !defined(VXWORKS)
+#ifdef HAVE_WRITEV
+/* Declaration of struct iovec *iov should be visible in this scope. */
+#include <sys/uio.h>
+#endif
+#endif
int ei_accept_t(int fd, void *addr, void *addrlen, unsigned ms);
int ei_connect_t(int fd, void *sinp, int sin_siz, unsigned ms);
@@ -29,8 +35,7 @@ int ei_write_fill(int fd, const char *buf, int len);
int ei_read_fill_t(int fd, char* buf, int len, unsigned ms);
int ei_write_fill_t(int fd, const char *buf, int len, unsigned ms);
#ifdef HAVE_WRITEV
-int ei_writev_fill_t(int fd, const struct iovec *iov, int iovcnt,
- unsigned ms);
+int ei_writev_fill_t(int fd, const struct iovec *iov, int iovcnt, unsigned ms);
#endif
#endif /* _EI_PORTIO_H */
diff --git a/lib/erl_interface/src/misc/show_msg.c b/lib/erl_interface/src/misc/show_msg.c
index 81accab4b6..5868cccba6 100644
--- a/lib/erl_interface/src/misc/show_msg.c
+++ b/lib/erl_interface/src/misc/show_msg.c
@@ -40,6 +40,8 @@
# include <time.h>
# endif
# endif
+#else
+# include <time.h>
#endif
#include "eiext.h"
diff --git a/lib/erl_interface/test/ei_decode_SUITE_data/ei_decode_test.c b/lib/erl_interface/test/ei_decode_SUITE_data/ei_decode_test.c
index 30f5fe33a0..cfe9083065 100644
--- a/lib/erl_interface/test/ei_decode_SUITE_data/ei_decode_test.c
+++ b/lib/erl_interface/test/ei_decode_SUITE_data/ei_decode_test.c
@@ -377,8 +377,14 @@ TESTCASE(test_ei_decode_ulong)
EI_DECODE_2 (decode_ulong, 11, unsigned long, ll(0x8000000000000000));
EI_DECODE_2 (decode_ulong, 11, unsigned long, ll(0xffffffffffffffff));
} else {
- EI_DECODE_2 (decode_ulong, 7, unsigned long, 0x80000000);
- EI_DECODE_2 (decode_ulong, 7, unsigned long, 0xffffffff);
+ if (sizeof(void*) > 4) {
+ /* Windows */
+ EI_DECODE_2_FAIL(decode_ulong, 11, unsigned long, ll(0x8000000000000000));
+ EI_DECODE_2_FAIL(decode_ulong, 11, unsigned long, ll(0xffffffffffffffff));
+ } else {
+ EI_DECODE_2 (decode_ulong, 7, unsigned long, 0x80000000);
+ EI_DECODE_2 (decode_ulong, 7, unsigned long, 0xffffffff);
+ }
}
EI_DECODE_2_FAIL(decode_ulong, 9, unsigned long, ll(0x7fffffffffff));
diff --git a/lib/erl_interface/test/runner.erl b/lib/erl_interface/test/runner.erl
index 9a27eda038..1084eec2a3 100644
--- a/lib/erl_interface/test/runner.erl
+++ b/lib/erl_interface/test/runner.erl
@@ -55,7 +55,7 @@ test(Tc, Timeout) ->
%% Returns: {ok, Port}
start({Prog, Tc}) when is_list(Prog), is_integer(Tc) ->
- Port = open_port({spawn, Prog}, [{packet, 4}]),
+ Port = open_port({spawn, Prog}, [{packet, 4}, exit_status]),
Command = [Tc div 256, Tc rem 256],
Port ! {self(), {command, Command}},
Port.
@@ -125,7 +125,9 @@ get_term(Port, Timeout) ->
get_reply(Port, Timeout) when is_port(Port) ->
receive
{Port, {data, Reply}} ->
- Reply
+ Reply;
+ Fail when element(1, Fail) == Port ->
+ ct:fail("Got unexpected message from port: ~p",[Fail])
after Timeout ->
ct:fail("No response from C program")
end.