-
Notifications
You must be signed in to change notification settings - Fork 682
Fix MinGW compilation errors in jerry-ext #4510
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
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
And, please, remove the build log from the commit message. That's yet another thing that should go into a comment only.
24b7fbc
to
0157129
Compare
jerry-ext/debugger/debugger-tcp.c
Outdated
typedef SOCKET jerryx_socket; | ||
|
||
/* | ||
* On Windows, socket functions has the following signature: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(minor) ... functions have ...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(minor) ... functions have ...
why? it's socket related functions
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fix with socket related functions
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Because that's how the English grammar works. Plural goes with "have". "Functions" is plural. The proper sentence should read as "On Windows, socket functions have the following signature:" (or "signatures")
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks, I fixed it with signatures
jerry-ext/debugger/debugger-tcp.c
Outdated
/* On *nix the sockets are integer identifiers */ | ||
typedef int jerryx_socket; | ||
/* | ||
* On *nix, socket functions has the following signature: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(same here)
jerry-ext/debugger/debugger-tcp.c
Outdated
@@ -167,7 +184,10 @@ jerryx_debugger_tcp_send (jerry_debugger_transport_header_t *header_p, /**< tcp | |||
} | |||
#endif /* __linux__ */ | |||
|
|||
ssize_t sent_bytes = send (tcp_p->tcp_socket, message_p, message_length, 0); | |||
jerryx_socket_return_t sent_bytes = send (tcp_p->tcp_socket, | |||
(const jerryx_socket_buffer_t) message_p, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure that the const
qualifier is necessary here, please double check.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ssize_t send(int sockfd, const void *buf, size_t len, int flags);
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure that the
const
qualifier is necessary here, please double check.
indeed message_p should be const uint8_t*, so that user can use send string literal, even though in jerry there is no such usage
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure I get your argument. Did you try it (as requested, see "please double check" above)? I've just fetched this PR branch and dropped these const
s from the type casts, and everything compiled fine. As it should IMO. That const
modifier in the signature of send
prevents send
from altering the contents of the buffer -- but does not prevent the caller of send
from passing in a non-const
buffer.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure I get your argument. Did you try it (as requested, see "please double check" above)? I've just fetched this PR branch and dropped these
const
s from the type casts, and everything compiled fine. As it should IMO. Thatconst
modifier in the signature ofsend
preventssend
from altering the contents of the buffer -- but does not prevent the caller ofsend
from passing in a non-const
buffer.
Yeap, but when doing type cast, it's better to match the calle site, not the caller site, that's would misleading.
We do cast meant to match the called function's signature,
jerry-ext/debugger/debugger-tcp.c
Outdated
@@ -252,7 +275,7 @@ jerryx_debugger_tcp_configure_socket (jerryx_socket server_socket, /** < socket | |||
|
|||
int opt_value = 1; | |||
|
|||
if (setsockopt (server_socket, SOL_SOCKET, SO_REUSEADDR, &opt_value, sizeof (int)) != 0) | |||
if (setsockopt (server_socket, SOL_SOCKET, SO_REUSEADDR, (const jerryx_socket_opt_t) &opt_value, sizeof (int)) != 0) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not sure about const
here either.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
int setsockopt(SOCKET s, int level, int optname, const char *optval, int optlen);
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it's set, and get, so const are necessary.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can we merge
typedef char *jerryx_socket_buffer_t;
typedef char *jerryx_socket_opt_t;
maybe
typedef char jerrx_socket_void_t?
then we use (const jerrx_socket_void_t *) instead.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How about
/*
* On Windows, socket related functions has the following signature:
* int send(SOCKET s, const char *buf, int len, int flags);
* int recv(SOCKET s, char *buf, int len, int flags);
* int setsockopt(SOCKET s, int level, int optname, const char *optval, int optlen);
*/
typedef int jerryx_socket_ssize_t;
typedef SOCKET jerryx_socket_t;
typedef char jerryx_socket_void_t;
typedef int jerryx_socket_size_t;
typedef int jerryx_socket_len_t;
and
/*
* On *nix, socket related functions has the following signature:
* ssize_t send(int sockfd, const void *buf, size_t len, int flags);
* ssize_t recv(int sockfd, void *buf, size_t len, int flags);
* int setsockopt(int sockfd, int level, int optname, const void *optval, socklen_t optlen);
*/
typedef ssize_t jerryx_socket_ssize_t;
typedef int jerryx_socket_t;
typedef void jerryx_socket_void_t;
typedef size_t jerryx_socket_size_t;
typedef socklen_t jerryx_socket_len_t;
jerry-ext/debugger/debugger-tcp.c
Outdated
typedef char *jerryx_socket_buffer_t; | ||
typedef int jerryx_socket_buffer_length_t; | ||
typedef char *jerryx_socket_opt_t; | ||
typedef int jerryx_socket_len_t; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this type is unused, should be removed
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this type is unused, should be removed
forgot refer to it
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This type is only used to cast (jerryx_socket_len_t) sizeof (int)
. The sizeof (int)
is a compile-time constant, and most probably / it seems is compatible both with Windows's int
and *nix's socklen_t
. If that's so -- it is -- then casting is unnecessary. Code should not be cluttered with unnecessary casts. Thus, the type is not needed. Just remove it.
cfc0560
to
0c17bd1
Compare
114411f
to
0d9df24
Compare
jerry-ext/debugger/debugger-tcp.c
Outdated
typedef char *jerryx_socket_buffer_t; | ||
typedef int jerryx_socket_buffer_length_t; | ||
typedef char *jerryx_socket_opt_t; | ||
typedef int jerryx_socket_len_t; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This type is only used to cast (jerryx_socket_len_t) sizeof (int)
. The sizeof (int)
is a compile-time constant, and most probably / it seems is compatible both with Windows's int
and *nix's socklen_t
. If that's so -- it is -- then casting is unnecessary. Code should not be cluttered with unnecessary casts. Thus, the type is not needed. Just remove it.
jerry-ext/debugger/debugger-tcp.c
Outdated
@@ -167,7 +182,10 @@ jerryx_debugger_tcp_send (jerry_debugger_transport_header_t *header_p, /**< tcp | |||
} | |||
#endif /* __linux__ */ | |||
|
|||
ssize_t sent_bytes = send (tcp_p->tcp_socket, message_p, message_length, 0); | |||
jerryx_socket_ssize_t sent_bytes = send (tcp_p->tcp_socket, | |||
(const jerryx_socket_void_t *) message_p, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let me write it again, drop the const
qualifier from the cast. The const
qualifier in the signature of send
is a guarantee that it will not modify the contents of the buffer, not a requirement to the caller to pass in an unmodifiable buffer.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
as you insist, then i remove the const,
but consider this
if people modify the message_p parameter from uint8_t * to const uint8_t *,
then this cast will hidden the compiling error, doing this just hidding things
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If you rewrite the signature of the function to take message_p
as a pointer to const (and/or rewrite the opt value to be a const int
) then I'll accept a const cast.
jerry-ext/debugger/debugger-tcp.c
Outdated
jerryx_socket_ssize_t sent_bytes = send (tcp_p->tcp_socket, | ||
(jerryx_socket_void_t *) message_p, | ||
(jerryx_socket_size_t) message_length, | ||
0); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(minor style) indentation is off by one space (the last three lines should start where tcp_p->...
starts on the first line)
jerry-ext/debugger/debugger-tcp.c
Outdated
jerryx_socket_ssize_t length = recv (tcp_p->tcp_socket, | ||
(jerryx_socket_void_t *) buffer_p, | ||
(jerryx_socket_size_t) buffer_size, | ||
0); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(minor style) indentation is off by one space
c15f5b2
to
0bf0973
Compare
jerry-ext/debugger/debugger-tcp.c
Outdated
@@ -167,7 +181,8 @@ jerryx_debugger_tcp_send (jerry_debugger_transport_header_t *header_p, /**< tcp | |||
} | |||
#endif /* __linux__ */ | |||
|
|||
ssize_t sent_bytes = send (tcp_p->tcp_socket, message_p, message_length, 0); | |||
const jerryx_socket_void_t *message_to_send_p = (const jerryx_socket_void_t *) message_p; | |||
jerryx_socket_ssize_t sent_bytes = send (tcp_p->tcp_socket, message_to_send_p, message_to_send_length, 0); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This was not what the previous review was about. I've suggested to change the signature of jerryx_debugger_tcp_send
to have its parameter as uint8_t *message_p
. Then, send
can be called as send (tcp_p->tcp_socket, (const jerry_socket_void_t *) message_p, message_to_send_length, 0);
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This was not what the previous review was about. I've suggested to change the signature of
jerryx_debugger_tcp_send
to have its parameter asuint8_t *message_p
. Then,send
can be called assend (tcp_p->tcp_socket, (const jerry_socket_void_t *) message_p, message_to_send_length, 0);
Tried but failed, jerryx_debugger_tcp_send parameter can not changed to const uint8_t *message_p
.
It's will cause new compiling error, because websocket modify the content of message_p
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Use (jerryx_socket_void_t *) message_p
, din't want modify here anymore
jerry-ext/debugger/debugger-tcp.c
Outdated
@@ -250,9 +267,10 @@ jerryx_debugger_tcp_configure_socket (jerryx_socket server_socket, /** < socket | |||
addr.sin_port = htons (port); | |||
addr.sin_addr.s_addr = INADDR_ANY; | |||
|
|||
int opt_value = 1; | |||
const int opt_value = 1; | |||
const jerryx_socket_void_t *opt_value_p = (const jerryx_socket_void_t *) &opt_value; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This variable is unnecessary. Do the cast in the call to setsockopt
.
jerry-ext/debugger/debugger-tcp.c
Outdated
@@ -152,6 +165,7 @@ jerryx_debugger_tcp_send (jerry_debugger_transport_header_t *header_p, /**< tcp | |||
JERRYX_ASSERT (jerry_debugger_transport_is_connected ()); | |||
|
|||
jerryx_debugger_transport_tcp_t *tcp_p = (jerryx_debugger_transport_tcp_t *) header_p; | |||
jerryx_socket_size_t message_to_send_length = (jerryx_socket_size_t) message_length; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(minor) This is a bit long variable name. Let's look for something simpler but still descriptive. Could be remaining_bytes
, as there is already a variable sent_bytes
.
2434d90
to
2807b7c
Compare
mingw also need linkage to ws2_32, try define socket types for unix/win32 for compatibility reason and fixes jerryscript-project#4512 JerryScript-DCO-1.0-Signed-off-by: Yonggang Luo luoyonggang@gmail.com
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
mingw also need linkage to ws2_32, try define socket types for unix/win32 for compat reason
and fixes #4512
JerryScript-DCO-1.0-Signed-off-by: Yonggang Luo luoyonggang@gmail.com