Skip to content

Commit

Permalink
Merge pull request #51452 from omar-polo/fix-macros
Browse files Browse the repository at this point in the history
  • Loading branch information
akien-mga authored Jan 20, 2022
2 parents e6170aa + bd448e5 commit cfb986c
Show file tree
Hide file tree
Showing 12 changed files with 95 additions and 94 deletions.
5 changes: 2 additions & 3 deletions core/io/marshalls.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,8 @@ ObjectID EncodedObjectAsID::get_object_id() const {
return id;
}

#define _S(a) ((int32_t)a)
#define ERR_FAIL_ADD_OF(a, b, err) ERR_FAIL_COND_V(_S(b) < 0 || _S(a) < 0 || _S(a) > INT_MAX - _S(b), err)
#define ERR_FAIL_MUL_OF(a, b, err) ERR_FAIL_COND_V(_S(a) < 0 || _S(b) <= 0 || _S(a) > INT_MAX / _S(b), err)
#define ERR_FAIL_ADD_OF(a, b, err) ERR_FAIL_COND_V(((int32_t)(b)) < 0 || ((int32_t)(a)) < 0 || ((int32_t)(a)) > INT_MAX - ((int32_t)(b)), err)
#define ERR_FAIL_MUL_OF(a, b, err) ERR_FAIL_COND_V(((int32_t)(a)) < 0 || ((int32_t)(b)) <= 0 || ((int32_t)(a)) > INT_MAX / ((int32_t)(b)), err)

#define ENCODE_MASK 0xFF
#define ENCODE_FLAG_64 1 << 16
Expand Down
8 changes: 4 additions & 4 deletions core/math/face3.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -260,8 +260,8 @@ void Face3::project_range(const Vector3 &p_normal, const Transform3D &p_transfor
}

void Face3::get_support(const Vector3 &p_normal, const Transform3D &p_transform, Vector3 *p_vertices, int *p_count, int p_max) const {
#define _FACE_IS_VALID_SUPPORT_THRESHOLD 0.98
#define _EDGE_IS_VALID_SUPPORT_THRESHOLD 0.05
constexpr double face_support_threshold = 0.98;
constexpr double edge_support_threshold = 0.05;

if (p_max <= 0) {
return;
Expand All @@ -270,7 +270,7 @@ void Face3::get_support(const Vector3 &p_normal, const Transform3D &p_transform,
Vector3 n = p_transform.basis.xform_inv(p_normal);

/** TEST FACE AS SUPPORT **/
if (get_plane().normal.dot(n) > _FACE_IS_VALID_SUPPORT_THRESHOLD) {
if (get_plane().normal.dot(n) > face_support_threshold) {
*p_count = MIN(3, p_max);

for (int i = 0; i < *p_count; i++) {
Expand Down Expand Up @@ -304,7 +304,7 @@ void Face3::get_support(const Vector3 &p_normal, const Transform3D &p_transform,
// check if edge is valid as a support
real_t dot = (vertex[i] - vertex[(i + 1) % 3]).normalized().dot(n);
dot = ABS(dot);
if (dot < _EDGE_IS_VALID_SUPPORT_THRESHOLD) {
if (dot < edge_support_threshold) {
*p_count = MIN(2, p_max);

for (int j = 0; j < *p_count; j++) {
Expand Down
51 changes: 26 additions & 25 deletions core/math/geometry_3d.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -281,16 +281,16 @@ static inline void _plot_face(uint8_t ***p_cell_status, int x, int y, int z, int
int div_y = len_y > 1 ? 2 : 1;
int div_z = len_z > 1 ? 2 : 1;

#define _SPLIT(m_i, m_div, m_v, m_len_v, m_new_v, m_new_len_v) \
if (m_div == 1) { \
m_new_v = m_v; \
m_new_len_v = 1; \
} else if (m_i == 0) { \
m_new_v = m_v; \
m_new_len_v = m_len_v / 2; \
} else { \
m_new_v = m_v + m_len_v / 2; \
m_new_len_v = m_len_v - m_len_v / 2; \
#define SPLIT_DIV(m_i, m_div, m_v, m_len_v, m_new_v, m_new_len_v) \
if (m_div == 1) { \
m_new_v = m_v; \
m_new_len_v = 1; \
} else if (m_i == 0) { \
m_new_v = m_v; \
m_new_len_v = m_len_v / 2; \
} else { \
m_new_v = m_v + m_len_v / 2; \
m_new_len_v = m_len_v - m_len_v / 2; \
}

int new_x;
Expand All @@ -301,18 +301,20 @@ static inline void _plot_face(uint8_t ***p_cell_status, int x, int y, int z, int
int new_len_z;

for (int i = 0; i < div_x; i++) {
_SPLIT(i, div_x, x, len_x, new_x, new_len_x);
SPLIT_DIV(i, div_x, x, len_x, new_x, new_len_x);

for (int j = 0; j < div_y; j++) {
_SPLIT(j, div_y, y, len_y, new_y, new_len_y);
SPLIT_DIV(j, div_y, y, len_y, new_y, new_len_y);

for (int k = 0; k < div_z; k++) {
_SPLIT(k, div_z, z, len_z, new_z, new_len_z);
SPLIT_DIV(k, div_z, z, len_z, new_z, new_len_z);

_plot_face(p_cell_status, new_x, new_y, new_z, new_len_x, new_len_y, new_len_z, voxelsize, p_face);
}
}
}

#undef SPLIT_DIV
}

static inline void _mark_outside(uint8_t ***p_cell_status, int x, int y, int z, int len_x, int len_y, int len_z) {
Expand Down Expand Up @@ -491,11 +493,10 @@ static inline void _build_faces(uint8_t ***p_cell_status, int x, int y, int z, i
}

Vector<Face3> Geometry3D::wrap_geometry(Vector<Face3> p_array, real_t *p_error) {
#define _MIN_SIZE 1.0
#define _MAX_LENGTH 20

int face_count = p_array.size();
const Face3 *faces = p_array.ptr();
constexpr double min_size = 1.0;
constexpr int max_length = 20;

AABB global_aabb;

Expand All @@ -512,22 +513,22 @@ Vector<Face3> Geometry3D::wrap_geometry(Vector<Face3> p_array, real_t *p_error)
// Determine amount of cells in grid axis.
int div_x, div_y, div_z;

if (global_aabb.size.x / _MIN_SIZE < _MAX_LENGTH) {
div_x = (int)(global_aabb.size.x / _MIN_SIZE) + 1;
if (global_aabb.size.x / min_size < max_length) {
div_x = (int)(global_aabb.size.x / min_size) + 1;
} else {
div_x = _MAX_LENGTH;
div_x = max_length;
}

if (global_aabb.size.y / _MIN_SIZE < _MAX_LENGTH) {
div_y = (int)(global_aabb.size.y / _MIN_SIZE) + 1;
if (global_aabb.size.y / min_size < max_length) {
div_y = (int)(global_aabb.size.y / min_size) + 1;
} else {
div_y = _MAX_LENGTH;
div_y = max_length;
}

if (global_aabb.size.z / _MIN_SIZE < _MAX_LENGTH) {
div_z = (int)(global_aabb.size.z / _MIN_SIZE) + 1;
if (global_aabb.size.z / min_size < max_length) {
div_z = (int)(global_aabb.size.z / min_size) + 1;
} else {
div_z = _MAX_LENGTH;
div_z = max_length;
}

Vector3 voxelsize = global_aabb.size;
Expand Down
34 changes: 17 additions & 17 deletions core/string/ustring.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1632,7 +1632,7 @@ String String::utf8(const char *p_utf8, int p_len) {
}

bool String::parse_utf8(const char *p_utf8, int p_len) {
#define _UNICERROR(m_err) print_error("Unicode parsing error: " + String(m_err) + ". Is the string valid UTF-8?");
#define UNICERROR(m_err) print_error("Unicode parsing error: " + String(m_err) + ". Is the string valid UTF-8?");

if (!p_utf8) {
return true;
Expand Down Expand Up @@ -1673,12 +1673,12 @@ bool String::parse_utf8(const char *p_utf8, int p_len) {
} else if ((c & 0xf8) == 0xf0) {
skip = 3;
} else {
_UNICERROR("invalid skip at " + num_int64(cstr_size));
UNICERROR("invalid skip at " + num_int64(cstr_size));
return true; //invalid utf8
}

if (skip == 1 && (c & 0x1e) == 0) {
_UNICERROR("overlong rejected at " + num_int64(cstr_size));
UNICERROR("overlong rejected at " + num_int64(cstr_size));
return true; //reject overlong
}

Expand All @@ -1693,7 +1693,7 @@ bool String::parse_utf8(const char *p_utf8, int p_len) {
}

if (skip) {
_UNICERROR("no space left");
UNICERROR("no space left");
return true; //not enough space
}
}
Expand All @@ -1720,17 +1720,17 @@ bool String::parse_utf8(const char *p_utf8, int p_len) {
} else if ((*p_utf8 & 0xf8) == 0xf0) {
len = 4;
} else {
_UNICERROR("invalid len");
UNICERROR("invalid len");
return true; //invalid UTF8
}

if (len > cstr_size) {
_UNICERROR("no space left");
UNICERROR("no space left");
return true; //not enough space
}

if (len == 2 && (*p_utf8 & 0x1E) == 0) {
_UNICERROR("no space left");
UNICERROR("no space left");
return true; //reject overlong
}

Expand All @@ -1745,18 +1745,18 @@ bool String::parse_utf8(const char *p_utf8, int p_len) {

for (int i = 1; i < len; i++) {
if ((p_utf8[i] & 0xc0) != 0x80) {
_UNICERROR("invalid utf8");
UNICERROR("invalid utf8");
return true; //invalid utf8
}
if (unichar == 0 && i == 2 && ((p_utf8[i] & 0x7f) >> (7 - len)) == 0) {
_UNICERROR("invalid utf8 overlong");
UNICERROR("invalid utf8 overlong");
return true; //no overlong
}
unichar = (unichar << 6) | (p_utf8[i] & 0x3f);
}
}
if (unichar >= 0xd800 && unichar <= 0xdfff) {
_UNICERROR("invalid code point");
UNICERROR("invalid code point");
return CharString();
}

Expand All @@ -1766,7 +1766,7 @@ bool String::parse_utf8(const char *p_utf8, int p_len) {
}

return false;
#undef _UNICERROR
#undef UNICERROR
}

CharString String::utf8() const {
Expand Down Expand Up @@ -1840,7 +1840,7 @@ String String::utf16(const char16_t *p_utf16, int p_len) {
}

bool String::parse_utf16(const char16_t *p_utf16, int p_len) {
#define _UNICERROR(m_err) print_error("Unicode parsing error: " + String(m_err) + ". Is the string valid UTF-16?");
#define UNICERROR(m_err) print_error("Unicode parsing error: " + String(m_err) + ". Is the string valid UTF-16?");

if (!p_utf16) {
return true;
Expand Down Expand Up @@ -1880,7 +1880,7 @@ bool String::parse_utf16(const char16_t *p_utf16, int p_len) {
if ((c & 0xfffffc00) == 0xd800) {
skip = 1; // lead surrogate
} else if ((c & 0xfffffc00) == 0xdc00) {
_UNICERROR("invalid utf16 surrogate at " + num_int64(cstr_size));
UNICERROR("invalid utf16 surrogate at " + num_int64(cstr_size));
return true; // invalid UTF16
} else {
skip = 0;
Expand All @@ -1890,7 +1890,7 @@ bool String::parse_utf16(const char16_t *p_utf16, int p_len) {
if ((c & 0xfffffc00) == 0xdc00) { // trail surrogate
--skip;
} else {
_UNICERROR("invalid utf16 surrogate at " + num_int64(cstr_size));
UNICERROR("invalid utf16 surrogate at " + num_int64(cstr_size));
return true; // invalid UTF16
}
}
Expand All @@ -1900,7 +1900,7 @@ bool String::parse_utf16(const char16_t *p_utf16, int p_len) {
}

if (skip) {
_UNICERROR("no space left");
UNICERROR("no space left");
return true; // not enough space
}
}
Expand All @@ -1925,7 +1925,7 @@ bool String::parse_utf16(const char16_t *p_utf16, int p_len) {
}

if (len > cstr_size) {
_UNICERROR("no space left");
UNICERROR("no space left");
return true; //not enough space
}

Expand All @@ -1943,7 +1943,7 @@ bool String::parse_utf16(const char16_t *p_utf16, int p_len) {
}

return false;
#undef _UNICERROR
#undef UNICERROR
}

Char16String String::utf16() const {
Expand Down
10 changes: 5 additions & 5 deletions editor/animation_track_editor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5700,16 +5700,16 @@ void AnimationTrackEditor::_edit_menu_pressed(int p_option) {
to_restore.push_back(amr);
}

#define _NEW_POS(m_ofs) (((s > 0) ? m_ofs : from_t + (len - (m_ofs - from_t))) - pivot) * ABS(s) + from_t
#define NEW_POS(m_ofs) (((s > 0) ? m_ofs : from_t + (len - (m_ofs - from_t))) - pivot) * ABS(s) + from_t
// 3 - Move the keys (re insert them).
for (Map<SelectedKey, KeyInfo>::Element *E = selection.back(); E; E = E->prev()) {
float newpos = _NEW_POS(E->get().pos);
float newpos = NEW_POS(E->get().pos);
undo_redo->add_do_method(animation.ptr(), "track_insert_key", E->key().track, newpos, animation->track_get_key_value(E->key().track, E->key().key), animation->track_get_key_transition(E->key().track, E->key().key));
}

// 4 - (Undo) Remove inserted keys.
for (Map<SelectedKey, KeyInfo>::Element *E = selection.back(); E; E = E->prev()) {
float newpos = _NEW_POS(E->get().pos);
float newpos = NEW_POS(E->get().pos);
undo_redo->add_undo_method(animation.ptr(), "track_remove_key_at_time", E->key().track, newpos);
}

Expand All @@ -5729,13 +5729,13 @@ void AnimationTrackEditor::_edit_menu_pressed(int p_option) {
// 7-reselect.
for (Map<SelectedKey, KeyInfo>::Element *E = selection.back(); E; E = E->prev()) {
float oldpos = E->get().pos;
float newpos = _NEW_POS(oldpos);
float newpos = NEW_POS(oldpos);
if (newpos >= 0) {
undo_redo->add_do_method(this, "_select_at_anim", animation, E->key().track, newpos);
}
undo_redo->add_undo_method(this, "_select_at_anim", animation, E->key().track, oldpos);
}
#undef _NEW_POS
#undef NEW_POS
undo_redo->commit_action();
} break;
case EDIT_DUPLICATE_SELECTION: {
Expand Down
8 changes: 5 additions & 3 deletions modules/webrtc/register_types.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,11 @@
#include "webrtc_peer_connection_extension.h"

void register_webrtc_types() {
#define _SET_HINT(NAME, _VAL_, _MAX_) \
GLOBAL_DEF(NAME, _VAL_); \
#define SET_HINT(NAME, _VAL_, _MAX_) \
GLOBAL_DEF(NAME, _VAL_); \
ProjectSettings::get_singleton()->set_custom_property_info(NAME, PropertyInfo(Variant::INT, NAME, PROPERTY_HINT_RANGE, "2," #_MAX_ ",1,or_greater"));

_SET_HINT(WRTC_IN_BUF, 64, 4096);
SET_HINT(WRTC_IN_BUF, 64, 4096);

ClassDB::register_custom_instance_class<WebRTCPeerConnection>();
GDREGISTER_CLASS(WebRTCPeerConnectionExtension);
Expand All @@ -51,6 +51,8 @@ void register_webrtc_types() {
GDREGISTER_CLASS(WebRTCDataChannelExtension);

GDREGISTER_CLASS(WebRTCMultiplayerPeer);

#undef SET_HINT
}

void unregister_webrtc_types() {}
14 changes: 7 additions & 7 deletions modules/websocket/wsl_client.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -124,17 +124,17 @@ bool WSLClient::_verify_headers(String &r_protocol) {
}
}

#define _WSL_CHECK(NAME, VALUE) \
#define WSL_CHECK(NAME, VALUE) \
ERR_FAIL_COND_V_MSG(!headers.has(NAME) || headers[NAME].to_lower() != VALUE, false, \
"Missing or invalid header '" + String(NAME) + "'. Expected value '" + VALUE + "'.");
#define _WSL_CHECK_NC(NAME, VALUE) \
#define WSL_CHECK_NC(NAME, VALUE) \
ERR_FAIL_COND_V_MSG(!headers.has(NAME) || headers[NAME] != VALUE, false, \
"Missing or invalid header '" + String(NAME) + "'. Expected value '" + VALUE + "'.");
_WSL_CHECK("connection", "upgrade");
_WSL_CHECK("upgrade", "websocket");
_WSL_CHECK_NC("sec-websocket-accept", WSLPeer::compute_key_response(_key));
#undef _WSL_CHECK_NC
#undef _WSL_CHECK
WSL_CHECK("connection", "upgrade");
WSL_CHECK("upgrade", "websocket");
WSL_CHECK_NC("sec-websocket-accept", WSLPeer::compute_key_response(_key));
#undef WSL_CHECK_NC
#undef WSL_CHECK
if (_protocols.size() == 0) {
// We didn't request a custom protocol
ERR_FAIL_COND_V(headers.has("sec-websocket-protocol"), false);
Expand Down
16 changes: 8 additions & 8 deletions modules/websocket/wsl_server.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -58,17 +58,17 @@ bool WSLServer::PendingPeer::_parse_request(const Vector<String> p_protocols, St
headers[name] = value;
}
}
#define _WSL_CHECK(NAME, VALUE) \
#define WSL_CHECK(NAME, VALUE) \
ERR_FAIL_COND_V_MSG(!headers.has(NAME) || headers[NAME].to_lower() != VALUE, false, \
"Missing or invalid header '" + String(NAME) + "'. Expected value '" + VALUE + "'.");
#define _WSL_CHECK_EX(NAME) \
#define WSL_CHECK_EX(NAME) \
ERR_FAIL_COND_V_MSG(!headers.has(NAME), false, "Missing header '" + String(NAME) + "'.");
_WSL_CHECK("upgrade", "websocket");
_WSL_CHECK("sec-websocket-version", "13");
_WSL_CHECK_EX("sec-websocket-key");
_WSL_CHECK_EX("connection");
#undef _WSL_CHECK_EX
#undef _WSL_CHECK
WSL_CHECK("upgrade", "websocket");
WSL_CHECK("sec-websocket-version", "13");
WSL_CHECK_EX("sec-websocket-key");
WSL_CHECK_EX("connection");
#undef WSL_CHECK_EX
#undef WSL_CHECK
key = headers["sec-websocket-key"];
if (headers.has("sec-websocket-protocol")) {
Vector<String> protos = headers["sec-websocket-protocol"].split(",");
Expand Down
1 change: 0 additions & 1 deletion platform/linuxbsd/display_server_x11.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,6 @@
// EWMH
#define _NET_WM_STATE_REMOVE 0L // remove/unset property
#define _NET_WM_STATE_ADD 1L // add/set property
#define _NET_WM_STATE_TOGGLE 2L // toggle property

#include <dlfcn.h>
#include <fcntl.h>
Expand Down
Loading

0 comments on commit cfb986c

Please sign in to comment.