Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 24 additions & 1 deletion runtime/xamarin-support.m
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,30 @@
fwrite ("\n", 1, 1, stdout);
fflush (stdout);
#else
NSLog (@"%@", msg);
if (length > 4096) {
// Write in chunks of max 4096 characters; older versions of iOS seems to have a bug where NSLog may hang with long strings (!).
// https://github.com/xamarin/maccore/issues/1014
const char *utf8 = [msg UTF8String];
int len = strlen (utf8);
const int max_size = 4096;
Comment thread
spouliot marked this conversation as resolved.
while (len > 0) {
int chunk_size = len > max_size ? max_size : len;

// Try to not break in the middle of a line, by looking backwards for a newline
while (chunk_size > 0 && utf8 [chunk_size] != 0 && utf8 [chunk_size] != '\n')
chunk_size--;
if (chunk_size == 0) {
// No newline found, break in the middle.
chunk_size = len > max_size ? max_size : len;
}
NSLog (@"%.*s", chunk_size, utf8);

len -= chunk_size;
utf8 += chunk_size;
}
} else {
NSLog (@"%@", msg);
}
#endif
[msg release];
}
Expand Down