Skip to content

Commit

Permalink
ocaml 4.10 support (fixes #1)
Browse files Browse the repository at this point in the history
  • Loading branch information
fccm committed Aug 8, 2020
1 parent 51a2d70 commit e4dacd1
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 8 deletions.
3 changes: 1 addition & 2 deletions src/cxx_stubs/SFImage_stub.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -132,8 +132,7 @@ caml_sfImage_getPixelsStr(value sf_image)
unsigned int len = width * height * 4;
const sf::Uint8 *img_data = SfImage_val(sf_image)->getPixelsPtr();
if (img_data == NULL) caml_failwith("SFImage.getPixelsStr");
img_str = caml_alloc_string(len);
memcpy(String_val(img_str), img_data, len);
img_str = caml_alloc_initialized_string(len, (const char *)img_data);
CAMLreturn(img_str);
}

Expand Down
8 changes: 3 additions & 5 deletions src/cxx_stubs/SFPacket_stub.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -75,8 +75,7 @@ caml_sfPacket_getData(value packet)
CAMLlocal1(str);
const std::size_t size = SfPacket_val(packet)->getDataSize();
const void *ptr = SfPacket_val(packet)->getData();
str = caml_alloc_string(size);
memcpy(String_val(str), ptr, size);
str = caml_alloc_initialized_string(size, (const char *)ptr);
CAMLreturn(str);
}

Expand Down Expand Up @@ -163,15 +162,14 @@ caml_sfPacket_readString(value packet)
if (size != len) {
caml_failwith("SFPacket.readString: length mismatch");
}
str = caml_alloc_string(size);
memcpy(String_val(str), s.c_str(), size);
str = caml_alloc_initialized_string(size, s.c_str());
CAMLreturn(str);
}

CAMLextern_C value
caml_sfPacket_writeString(value packet, value str)
{
char *s = String_val(str);
const char *s = String_val(str);
sf::Uint32 len = caml_string_length(str);
*SfPacket_val(packet) << len;
*SfPacket_val(packet) << s;
Expand Down
3 changes: 2 additions & 1 deletion src/cxx_stubs/SFTcpSocket_stub.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
#include "SFPacket_stub.hpp"
#include "SFTime_stub.hpp"


/* sf::TcpSocket */

CAMLextern_C value
Expand Down Expand Up @@ -111,7 +112,7 @@ caml_sfTcpSocket_receive(value socket, value data)
std::size_t sizeReceived;
sf::Socket::Status st =
SfTcpSocket_val(socket)->receive(
String_val(data),
Bytes_val(data),
caml_string_length(data),
sizeReceived);
check_sfSocketStatus(st, "SFTcpSocket")
Expand Down
4 changes: 4 additions & 0 deletions src/cxx_stubs/sf_caml_conv.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@ value Val_some(value v);

#define UInt_val(v) ((unsigned int) Long_val(v))

#if OCAML_VERSION < 40600
#define Bytes_val(x) String_val(x)
#endif

/*
static inline
unsigned int UInt_val(value v) {
Expand Down
1 change: 1 addition & 0 deletions src/cxx_stubs/sf_caml_incs.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ extern "C" {
#include <caml/signals.h>
#include <caml/custom.h>
#include <caml/callback.h>
#include <caml/version.h>
}

#define CAMLextern_C extern "C"
Expand Down

0 comments on commit e4dacd1

Please sign in to comment.