Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MSVC compilation and runtime fixes #15

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 and runtime errors (#15, Jonah Beckford)
16 changes: 10 additions & 6 deletions bigstring-io-lib/src/bigstring_io_stubs.c
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@
#include <caml/bigarray.h>
#include <caml/signals.h>
#include <caml/unixsupport.h>
#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)

Expand Down Expand Up @@ -41,20 +45,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();
}
Expand All @@ -71,20 +75,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();
}
Expand Down