From fd035c931df74282a9f409a8dad18b5f229fc6a2 Mon Sep 17 00:00:00 2001 From: Fabio Alessandrelli Date: Tue, 25 Feb 2020 10:15:45 +0100 Subject: [PATCH] Fix Javascript platform after PoolVector removal. Eval should be rechecked. --- modules/websocket/emws_peer.cpp | 5 ++-- platform/javascript/http_client.h.inc | 2 +- .../javascript/http_client_javascript.cpp | 23 +++++------------- platform/javascript/javascript_eval.cpp | 10 ++++---- platform/javascript/os_javascript.cpp | 24 +++++++------------ 5 files changed, 22 insertions(+), 42 deletions(-) diff --git a/modules/websocket/emws_peer.cpp b/modules/websocket/emws_peer.cpp index f396a1c812f..9472daa6207 100644 --- a/modules/websocket/emws_peer.cpp +++ b/modules/websocket/emws_peer.cpp @@ -90,12 +90,11 @@ Error EMWSPeer::get_packet(const uint8_t **r_buffer, int &r_buffer_size) { if (_in_buffer.packets_left() == 0) return ERR_UNAVAILABLE; - uint8_t *rw = _packet_buffer.ptrw(); int read = 0; - Error err = _in_buffer.read_packet(rw.ptr(), _packet_buffer.size(), &_is_string, read); + Error err = _in_buffer.read_packet(_packet_buffer.ptrw(), _packet_buffer.size(), &_is_string, read); ERR_FAIL_COND_V(err != OK, err); - *r_buffer = rw.ptr(); + *r_buffer = _packet_buffer.ptr(); r_buffer_size = read; return OK; diff --git a/platform/javascript/http_client.h.inc b/platform/javascript/http_client.h.inc index 03e2ce8b8a9..ac275aadbc6 100644 --- a/platform/javascript/http_client.h.inc +++ b/platform/javascript/http_client.h.inc @@ -45,7 +45,7 @@ String password; int polled_response_code; String polled_response_header; -PoolByteArray polled_response; +PackedByteArray polled_response; #ifdef DEBUG_ENABLED bool has_polled; diff --git a/platform/javascript/http_client_javascript.cpp b/platform/javascript/http_client_javascript.cpp index d7796cc4f48..472384cf300 100644 --- a/platform/javascript/http_client_javascript.cpp +++ b/platform/javascript/http_client_javascript.cpp @@ -108,8 +108,7 @@ Error HTTPClient::request_raw(Method p_method, const String &p_url, const Vector Error err = prepare_request(p_method, p_url, p_headers); if (err != OK) return err; - const uint8_t *read = p_body.ptr(); - godot_xhr_send_data(xhr_id, read.ptr(), p_body.size()); + godot_xhr_send_data(xhr_id, p_body.ptr(), p_body.size()); return OK; } @@ -180,11 +179,7 @@ PackedByteArray HTTPClient::read_response_body_chunk() { int to_read = MIN(read_limit, polled_response.size() - response_read_offset); PackedByteArray chunk; chunk.resize(to_read); - uint8_t *write = chunk.ptrw(); - const uint8_t *read = polled_response.ptr(); - memcpy(write.ptr(), read.ptr() + response_read_offset, to_read); - write = uint8_t * (); - read = const uint8_t * (); + memcpy(chunk.ptrw(), polled_response.ptr() + response_read_offset, to_read); response_read_offset += to_read; if (response_read_offset == polled_response.size()) { @@ -267,19 +262,13 @@ Error HTTPClient::poll() { int len = godot_xhr_get_response_headers_length(xhr_id); bytes.resize(len + 1); - uint8_t *write = bytes.ptrw(); - godot_xhr_get_response_headers(xhr_id, reinterpret_cast(write.ptr()), len); - write[len] = 0; - write = uint8_t * (); + godot_xhr_get_response_headers(xhr_id, reinterpret_cast(bytes.ptrw()), len); + bytes.ptrw()[len] = 0; - const uint8_t *read = bytes.ptr(); - polled_response_header = String::utf8(reinterpret_cast(read.ptr())); - read = const uint8_t * (); + polled_response_header = String::utf8(reinterpret_cast(bytes.ptr())); polled_response.resize(godot_xhr_get_response_length(xhr_id)); - write = polled_response.ptrw(); - godot_xhr_get_response(xhr_id, write.ptr(), polled_response.size()); - write = uint8_t * (); + godot_xhr_get_response(xhr_id, polled_response.ptrw(), polled_response.size()); break; } diff --git a/platform/javascript/javascript_eval.cpp b/platform/javascript/javascript_eval.cpp index 44cce28d578..db8050b90e6 100644 --- a/platform/javascript/javascript_eval.cpp +++ b/platform/javascript/javascript_eval.cpp @@ -33,11 +33,11 @@ #include "api/javascript_eval.h" #include "emscripten.h" -extern "C" EMSCRIPTEN_KEEPALIVE uint8_t *resize_PackedByteArray_and_open_write(PackedByteArray *p_arr, uint8_t **r_write, int p_len) { +extern "C" EMSCRIPTEN_KEEPALIVE uint8_t *resize_PackedByteArray_and_open_write(PackedByteArray *p_arr, VectorWriteProxy *r_write, int p_len) { p_arr->resize(p_len); - *r_write = p_arr->write(); - return r_write->ptr(); + *r_write = p_arr->write; + return p_arr->ptrw(); } Variant JavaScript::eval(const String &p_code, bool p_use_global_exec_context) { @@ -49,7 +49,7 @@ Variant JavaScript::eval(const String &p_code, bool p_use_global_exec_context) { } js_data; PackedByteArray arr; - uint8_t *arr_write; + VectorWriteProxy arr_write; /* clang-format off */ Variant::Type return_type = static_cast(EM_ASM_INT({ @@ -138,7 +138,7 @@ Variant JavaScript::eval(const String &p_code, bool p_use_global_exec_context) { return str; } case Variant::PACKED_BYTE_ARRAY: - arr_write = uint8_t * (); + arr_write = VectorWriteProxy(); return arr; default: return Variant(); diff --git a/platform/javascript/os_javascript.cpp b/platform/javascript/os_javascript.cpp index 037f78c7af6..3408995d8d7 100644 --- a/platform/javascript/os_javascript.cpp +++ b/platform/javascript/os_javascript.cpp @@ -539,15 +539,11 @@ void OS_JavaScript::set_custom_mouse_cursor(const RES &p_cursor, CursorShape p_s PackedByteArray png; size_t len; - const uint8_t *r = image->get_data().ptr(); - ERR_FAIL_COND(!png_image_write_get_memory_size(png_meta, len, 0, r.ptr(), 0, NULL)); + PackedByteArray data = image->get_data(); + ERR_FAIL_COND(!png_image_write_get_memory_size(png_meta, len, 0, data.ptr(), 0, NULL)); png.resize(len); - uint8_t *w = png.ptrw(); - ERR_FAIL_COND(!png_image_write_to_memory(&png_meta, w.ptr(), &len, 0, r.ptr(), 0, NULL)); - w = uint8_t * (); - - r = png.ptr(); + ERR_FAIL_COND(!png_image_write_to_memory(&png_meta, png.ptrw(), &len, 0, data.ptr(), 0, NULL)); char *object_url; /* clang-format off */ @@ -562,9 +558,8 @@ void OS_JavaScript::set_custom_mouse_cursor(const RES &p_cursor, CursorShape p_s var string_on_wasm_heap = _malloc(length_bytes); setValue(PTR, string_on_wasm_heap, '*'); stringToUTF8(url, string_on_wasm_heap, length_bytes); - }, r.ptr(), len, &object_url); + }, png.ptr(), len, &object_url); /* clang-format on */ - r = const uint8_t * (); String url = String::utf8(object_url) + "?" + itos(p_hotspot.x) + " " + itos(p_hotspot.y); @@ -1181,15 +1176,12 @@ void OS_JavaScript::set_icon(const Ref &p_icon) { PackedByteArray png; size_t len; - const uint8_t *r = icon->get_data().ptr(); - ERR_FAIL_COND(!png_image_write_get_memory_size(png_meta, len, 0, r.ptr(), 0, NULL)); + PackedByteArray data = icon->get_data(); + ERR_FAIL_COND(!png_image_write_get_memory_size(png_meta, len, 0, data.ptr(), 0, NULL)); png.resize(len); - uint8_t *w = png.ptrw(); - ERR_FAIL_COND(!png_image_write_to_memory(&png_meta, w.ptr(), &len, 0, r.ptr(), 0, NULL)); - w = uint8_t * (); + ERR_FAIL_COND(!png_image_write_to_memory(&png_meta, png.ptrw(), &len, 0, data.ptr(), 0, NULL)); - r = png.ptr(); /* clang-format off */ EM_ASM_ARGS({ var PNG_PTR = $0; @@ -1205,7 +1197,7 @@ void OS_JavaScript::set_icon(const Ref &p_icon) { document.head.appendChild(link); } link.href = url; - }, r.ptr(), len); + }, png.ptr(), len); /* clang-format on */ }