From 236a71f202f226f209d36fcb99c4ce594d516a90 Mon Sep 17 00:00:00 2001 From: Manuel de la Pena Date: Fri, 15 Nov 2019 11:43:22 -0500 Subject: [PATCH 1/4] [Runtime] Enable the -Wsign-conversion on monotouch-debug files. Enable the flag that was disabled via pragmas and fix warnings. Continuation of PR: https://github.com/xamarin/xamarin-macios/pull/7405 --- runtime/monotouch-debug.h | 4 +-- runtime/monotouch-debug.m | 52 +++++++++++++++++---------------------- 2 files changed, 25 insertions(+), 31 deletions(-) diff --git a/runtime/monotouch-debug.h b/runtime/monotouch-debug.h index ea0c3af9556f..4ef8a4b04135 100644 --- a/runtime/monotouch-debug.h +++ b/runtime/monotouch-debug.h @@ -31,8 +31,8 @@ typedef struct { void (*connect) (const char *address); void (*close1) (void); void (*close2) (void); - gboolean (*send) (void *buf, int len); - int (*recv) (void *buf, int len); + gboolean (*send) (void *buf, size_t len); + ssize_t (*recv) (void *buf, size_t len); } DebuggerTransport; void mono_debugger_agent_parse_options (const char *options); diff --git a/runtime/monotouch-debug.m b/runtime/monotouch-debug.m index 3eeff8bd7d59..1e4980b939dd 100644 --- a/runtime/monotouch-debug.m +++ b/runtime/monotouch-debug.m @@ -9,10 +9,6 @@ // Copyright 2011-2013 Xamarin Inc. // -// TODO: temp ignore to minimize diff -#pragma clang diagnostic push -#pragma clang diagnostic ignored "-Wsign-conversion" - #ifdef DEBUG //#define LOG_HTTP(...) do { NSLog (@ __VA_ARGS__); } while (0); @@ -203,7 +199,7 @@ -(int) localDescriptor; -(void) reportCompletion: (bool) success; -(void) connect: (NSString *) ip port: (unsigned long) port completionHandler: (void (^)(bool)) completionHandler; - -(void) sendData: (void *) buffer length: (long) length; + -(void) sendData: (void *) buffer length: (unsigned int) length; /* NSURLSessionDelegate */ -(void) URLSession:(NSURLSession *)session didBecomeInvalidWithError:(NSError *)error; @@ -230,7 +226,7 @@ -(void) URLSession:(NSURLSession *)session task:(NSURLSessionTask *)task didComp long rv = read (fd, buf, 1024); LOG_HTTP ("%i http send read %i bytes from fd=%i; %i=%s", connection.id, rv, fd, errno, strerror (errno)); if (rv > 0) { - [connection sendData: buf length: rv]; + [connection sendData: buf length: (unsigned int) rv]; } else if (rv == -1) { if (errno == EINTR) continue; @@ -308,7 +304,7 @@ -(void) connect: (NSString *) ip port: (unsigned long) port completionHandler: ( LOG_HTTP ("%i Connecting to: %@:%i downloadTask: %@", self.id, ip, port, [[downloadTask currentRequest] URL]); } --(void) sendData: (void *) buffer length: (long) length +-(void) sendData: (void *) buffer length: (unsigned int) length { int c = atomic_fetch_add (&http_send_counter, 1); @@ -356,7 +352,7 @@ -(void) URLSession: (NSURLSession *) session dataTask: (NSURLSessionDataTask *) wr = write (fd, bytes, left); } while (wr == -1 && errno == EINTR); if (wr > 0) { - left -= wr; + left -= (NSUInteger) wr; LOG_HTTP ("%i didReceiveData wrote %i/%lu bytes to %i; %lu bytes left", self.id, wr, (unsigned long) total, fd, (unsigned long) left); } else if (wr == 0) { LOG_HTTP ("%i didReceiveData no data written.", self.id); @@ -595,7 +591,7 @@ void monotouch_configure_debugging () } else if ((shmkey = ftok ("/Library/Frameworks/Xamarin.iOS.framework/Versions/Current/bin/mtouch", 0)) == -1) { LOG (PRODUCT ": Could not create shared memory key: %s\n", strerror (errno)); } else { - int shmsize = 1024; + size_t shmsize = 1024; int shmid = shmget (shmkey, shmsize, 0); if (shmid == -1) { LOG (PRODUCT ": Could not get shared memory id: %s\n", strerror (errno)); @@ -738,33 +734,33 @@ static void sdb_close2 (void) shutdown (sdb_fd, SHUT_RDWR); } -static gboolean send_uninterrupted (int fd, const void *buf, int len) +static gboolean send_uninterrupted (int fd, const void *buf, size_t len) { - long res; + ssize_t res; do { res = send (fd, buf, len, 0); } while (res == -1 && errno == EINTR); - return res == len; + return (size_t) res == len; } -static int recv_uninterrupted (int fd, void *buf, int len) +static ssize_t recv_uninterrupted (int fd, void *buf, size_t len) { - long res; - int total = 0; + ssize_t res; + ssize_t total = 0; int flags = 0; do { - res = recv (fd, (char *) buf + total, len - total, flags); + res = recv (fd, (char *) buf + total, len - (size_t) total, flags); if (res > 0) total += res; - } while ((res > 0 && total < len) || (res == -1 && errno == EINTR)); + } while ((res > 0 && (size_t) total < len) || (res == -1 && errno == EINTR)); return total; } -static gboolean sdb_send (void *buf, int len) +static gboolean sdb_send (void *buf, size_t len) { gboolean rv; @@ -780,9 +776,9 @@ static gboolean sdb_send (void *buf, int len) } -static int sdb_recv (void *buf, int len) +static ssize_t sdb_recv (void *buf, size_t len) { - int rv; + ssize_t rv; if (debugging_configured) { MONO_ENTER_GC_SAFE; @@ -837,7 +833,8 @@ static int sdb_recv (void *buf, int len) connection.ip = [ips objectAtIndex: i]; connection.uniqueRequest = unique_request; [connections addObject: connection]; - [connection connect: [ips objectAtIndex: i] port: monodevelop_port completionHandler: ^void (bool success) + assert (monodevelop_port > 0); // Make sure we do have a valid port + [connection connect: [ips objectAtIndex: i] port: (unsigned long) monodevelop_port completionHandler: ^void (bool success) { LOG_HTTP ("Connected: %@: %i", connection, success); pthread_mutex_lock (&connected_mutex); @@ -940,7 +937,7 @@ static int sdb_recv (void *buf, int len) fcntl (sockets[i], F_SETFL, flags | O_NONBLOCK); // Connect to the host - if ((rv = connect (sockets[i], (struct sockaddr *) sockaddr, len)) == 0) { + if ((rv = connect (sockets[i], (struct sockaddr *) sockaddr, (socklen_t) len)) == 0) { // connection completed, this is our man. connection_port = i; connected = true; @@ -1268,7 +1265,7 @@ static int sdb_recv (void *buf, int len) while (true) { char command [257]; - int rv; + ssize_t rv; unsigned char cmd_len; rv = recv_uninterrupted (fd, &cmd_len, 1); @@ -1518,7 +1515,7 @@ int monotouch_debug_connect (NSMutableArray *ips, int debug_port, int output_por ip = [[ips objectAtIndex:i] UTF8String]; memset (sockaddr, 0, sizeof (sockaddr)); - + // Parse the host IP, assuming IPv4 and falling back to IPv6 if ((rv = inet_pton (AF_INET, ip, &sin->sin_addr)) == 1) { len = sin->sin_len = sizeof (struct sockaddr_in); @@ -1546,7 +1543,7 @@ int monotouch_debug_connect (NSMutableArray *ips, int debug_port, int output_por fcntl (sockets[i], F_SETFL, flags | O_NONBLOCK); // Connect to the host - if ((rv = connect (sockets[i], (struct sockaddr *) sockaddr, len)) == 0) { + if ((rv = connect (sockets[i], (struct sockaddr *) sockaddr, (socklen_t) len)) == 0) { // connection completed, this is our man. connected = true; connection_port = i; @@ -1725,7 +1722,4 @@ int monotouch_debug_connect (NSMutableArray *ips, int debug_port, int output_por #else int xamarin_fix_ranlib_warning_about_no_symbols_v2; -#endif /* DEBUG */ - - -#pragma clang diagnostic pop +#endif /* DEBUG */ \ No newline at end of file From ee7348c113155f591c7019aead42d3e9cb008ee1 Mon Sep 17 00:00:00 2001 From: Manuel de la Pena Date: Mon, 18 Nov 2019 14:06:59 -0500 Subject: [PATCH 2/4] Address reviews. --- runtime/monotouch-debug.m | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/runtime/monotouch-debug.m b/runtime/monotouch-debug.m index 1e4980b939dd..301ad85c4782 100644 --- a/runtime/monotouch-debug.m +++ b/runtime/monotouch-debug.m @@ -833,7 +833,11 @@ static ssize_t sdb_recv (void *buf, size_t len) connection.ip = [ips objectAtIndex: i]; connection.uniqueRequest = unique_request; [connections addObject: connection]; - assert (monodevelop_port > 0); // Make sure we do have a valid port + if (monodevelop_port > 0) { + // Make sure we do have a valid port + NSLog (@"Could not find a valid port to connect to the IDE."); + return; + } [connection connect: [ips objectAtIndex: i] port: (unsigned long) monodevelop_port completionHandler: ^void (bool success) { LOG_HTTP ("Connected: %@: %i", connection, success); @@ -1515,7 +1519,7 @@ int monotouch_debug_connect (NSMutableArray *ips, int debug_port, int output_por ip = [[ips objectAtIndex:i] UTF8String]; memset (sockaddr, 0, sizeof (sockaddr)); - + // Parse the host IP, assuming IPv4 and falling back to IPv6 if ((rv = inet_pton (AF_INET, ip, &sin->sin_addr)) == 1) { len = sin->sin_len = sizeof (struct sockaddr_in); From 7e63a4fa959cda8e55497a36362f3da69b9034aa Mon Sep 17 00:00:00 2001 From: Manuel de la Pena Date: Mon, 18 Nov 2019 14:08:07 -0500 Subject: [PATCH 3/4] Missing new line. --- runtime/monotouch-debug.m | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/runtime/monotouch-debug.m b/runtime/monotouch-debug.m index 301ad85c4782..154816fd101a 100644 --- a/runtime/monotouch-debug.m +++ b/runtime/monotouch-debug.m @@ -1726,4 +1726,4 @@ int monotouch_debug_connect (NSMutableArray *ips, int debug_port, int output_por #else int xamarin_fix_ranlib_warning_about_no_symbols_v2; -#endif /* DEBUG */ \ No newline at end of file +#endif /* DEBUG */ From dbc5aa3792e7f34a90c64b20f5aa2f6ae907f501 Mon Sep 17 00:00:00 2001 From: Manuel de la Pena Date: Tue, 19 Nov 2019 15:05:45 -0500 Subject: [PATCH 4/4] Update runtime/monotouch-debug.m Co-Authored-By: Rolf Bjarne Kvinge --- runtime/monotouch-debug.m | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/runtime/monotouch-debug.m b/runtime/monotouch-debug.m index 154816fd101a..6442732857a8 100644 --- a/runtime/monotouch-debug.m +++ b/runtime/monotouch-debug.m @@ -833,7 +833,7 @@ static ssize_t sdb_recv (void *buf, size_t len) connection.ip = [ips objectAtIndex: i]; connection.uniqueRequest = unique_request; [connections addObject: connection]; - if (monodevelop_port > 0) { + if (monodevelop_port <= 0) { // Make sure we do have a valid port NSLog (@"Could not find a valid port to connect to the IDE."); return;