diff --git a/src/cxx_stubs/SFImage_stub.cpp b/src/cxx_stubs/SFImage_stub.cpp index e3c717f..4f85a41 100644 --- a/src/cxx_stubs/SFImage_stub.cpp +++ b/src/cxx_stubs/SFImage_stub.cpp @@ -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); } diff --git a/src/cxx_stubs/SFPacket_stub.cpp b/src/cxx_stubs/SFPacket_stub.cpp index 9c963c4..49ec683 100644 --- a/src/cxx_stubs/SFPacket_stub.cpp +++ b/src/cxx_stubs/SFPacket_stub.cpp @@ -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); } @@ -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; diff --git a/src/cxx_stubs/SFTcpSocket_stub.cpp b/src/cxx_stubs/SFTcpSocket_stub.cpp index d146e8d..6dc65dd 100644 --- a/src/cxx_stubs/SFTcpSocket_stub.cpp +++ b/src/cxx_stubs/SFTcpSocket_stub.cpp @@ -31,6 +31,7 @@ #include "SFPacket_stub.hpp" #include "SFTime_stub.hpp" + /* sf::TcpSocket */ CAMLextern_C value @@ -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") diff --git a/src/cxx_stubs/sf_caml_conv.hpp b/src/cxx_stubs/sf_caml_conv.hpp index df556c8..be55524 100644 --- a/src/cxx_stubs/sf_caml_conv.hpp +++ b/src/cxx_stubs/sf_caml_conv.hpp @@ -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) { diff --git a/src/cxx_stubs/sf_caml_incs.hpp b/src/cxx_stubs/sf_caml_incs.hpp index 8c46f62..764b4ca 100644 --- a/src/cxx_stubs/sf_caml_incs.hpp +++ b/src/cxx_stubs/sf_caml_incs.hpp @@ -12,6 +12,7 @@ extern "C" { #include #include #include +#include } #define CAMLextern_C extern "C"