From d03f002e5035b0e2cd88eaea49680b2823c1f5fb Mon Sep 17 00:00:00 2001 From: Jonah Beckford <71855677+jonahbeckford@users.noreply.github.com> Date: Sat, 10 Feb 2024 18:16:59 -0800 Subject: [PATCH 1/2] Fix MSVC compilation errors 1. Local variable `char* buf` is overloaded with parameter `value buf` bigstring_io_stubs.c(44): error C2082: redefinition of formal parameter 'buf' bigstring_io_stubs.c(74): error C2082: redefinition of formal parameter 'buf' 2. Likely ancient refactor missed Windows code ... no `src` variable. Signed-off-by: Jonah Beckford <71855677+jonahbeckford@users.noreply.github.com> --- CHANGES.md | 1 + bigstring-io-lib/src/bigstring_io_stubs.c | 12 ++++++------ 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/CHANGES.md b/CHANGES.md index 4eabb68..32d33b4 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -3,3 +3,4 @@ - Add `Process.call_xxx` functions that are equivalent to their `Process.run_xxx` counterpart except that they take a single string list as argument (#8, David Chemouil) +- Fix MSVC compilation errors (#15, Jonah Beckford) diff --git a/bigstring-io-lib/src/bigstring_io_stubs.c b/bigstring-io-lib/src/bigstring_io_stubs.c index 850bd71..7981e5d 100644 --- a/bigstring-io-lib/src/bigstring_io_stubs.c +++ b/bigstring-io-lib/src/bigstring_io_stubs.c @@ -41,20 +41,20 @@ CAMLprim value shexp_bigstring_io_read(value fd, value buf, value ofs, value len CAMLparam1(buf); DWORD numread; DWORD err = 0; - char* buf = get_buf(buf, ofs); + char* ptr = get_buf(buf, ofs); if (Descr_kind_val(fd) == KIND_SOCKET) { int ret; SOCKET s = Socket_val(fd); caml_enter_blocking_section(); - ret = recv(s, buf, Long_val(len), 0); + ret = recv(s, ptr, Long_val(len), 0); if (ret == SOCKET_ERROR) err = WSAGetLastError(); caml_leave_blocking_section(); numread = ret; } else { HANDLE h = Handle_val(fd); caml_enter_blocking_section(); - if (! ReadFile(h, buf, Long_val(len), &numread, NULL)) + if (! ReadFile(h, ptr, Long_val(len), &numread, NULL)) err = GetLastError(); caml_leave_blocking_section(); } @@ -71,20 +71,20 @@ CAMLprim value shexp_bigstring_io_write(value fd, value buf, value ofs, value le CAMLparam1(buf); DWORD numwritten; DWORD err = 0; - char* buf = get_buf(buf, ofs); + char* ptr = get_buf(buf, ofs); if (Descr_kind_val(fd) == KIND_SOCKET) { int ret; SOCKET s = Socket_val(fd); caml_enter_blocking_section(); - ret = send(s, buf, Long_val(len), 0); + ret = send(s, ptr, Long_val(len), 0); if (ret == SOCKET_ERROR) err = WSAGetLastError(); caml_leave_blocking_section(); numwritten = ret; } else { HANDLE h = Handle_val(fd); caml_enter_blocking_section(); - if (! WriteFile(h, src, Long_val(len), &numwritten, NULL)) + if (! WriteFile(h, ptr, Long_val(len), &numwritten, NULL)) err = GetLastError(); caml_leave_blocking_section(); } From 124ff5fc89285faa810b421b26cf182786fcff71 Mon Sep 17 00:00:00 2001 From: Jonah Beckford <71855677+jonahbeckford@users.noreply.github.com> Date: Sat, 10 Feb 2024 19:40:43 -0800 Subject: [PATCH 2/2] Fix MSVC runtime errors 1. Fatal error: cannot load shared library dllshexp_bigstring_io_stubs Reason: Cannot resolve send Signed-off-by: Jonah Beckford <71855677+jonahbeckford@users.noreply.github.com> --- CHANGES.md | 2 +- bigstring-io-lib/src/bigstring_io_stubs.c | 4 ++++ 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/CHANGES.md b/CHANGES.md index 32d33b4..788ab19 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -3,4 +3,4 @@ - Add `Process.call_xxx` functions that are equivalent to their `Process.run_xxx` counterpart except that they take a single string list as argument (#8, David Chemouil) -- Fix MSVC compilation errors (#15, Jonah Beckford) +- Fix MSVC compilation and runtime errors (#15, Jonah Beckford) diff --git a/bigstring-io-lib/src/bigstring_io_stubs.c b/bigstring-io-lib/src/bigstring_io_stubs.c index 7981e5d..303278b 100644 --- a/bigstring-io-lib/src/bigstring_io_stubs.c +++ b/bigstring-io-lib/src/bigstring_io_stubs.c @@ -5,6 +5,10 @@ #include #include #include +#ifdef _MSC_VER +/* Link with the ws2_32 WinSock library so that send() and recv() are linked. */ +#pragma comment( lib, "ws2_32" ) +#endif #define get_buf(v_buf, v_pos) (char *) Caml_ba_data_val(v_buf) + Long_val(v_pos)