mirror of
https://github.com/servo/servo.git
synced 2025-08-05 13:40:08 +01:00
Auto merge of #21950 - jdm:android-logging-fix, r=jdm
Make android logging work for multiple println calls The existing implementation had incorrect calculations for calculating when there was unlogged data sitting in the buffer and when the buffer was full. With these changes I am able to see the expected output for the following testcase: ```html <script> console.log("hi"); console.log("hi there"); console.log("hi there again"); let s = "hi there again x2 "; for (var i = 0; i < 10; i++) { s += s; } console.log(s); </script> ``` --- - [x] `./mach build -d` does not report any errors - [x] `./mach test-tidy` does not report any errors - [x] These changes fix #21875 - [x] These changes do not require tests because no automated tests for behaviour of logcat on android <!-- Reviewable:start --> --- This change is [<img src="https://reviewable.io/review_button.svg" height="34" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/servo/servo/21950) <!-- Reviewable:end -->
This commit is contained in:
commit
683298a109
1 changed files with 8 additions and 2 deletions
|
@ -483,11 +483,17 @@ fn redirect_stdout_to_logcat() {
|
|||
let end = if result == 0 {
|
||||
return;
|
||||
} else if result < 0 {
|
||||
return; /* TODO: report problem */
|
||||
unsafe {
|
||||
__android_log_write(3, tag, b"error in log thread; closing\0".as_ptr() as *const _);
|
||||
}
|
||||
return;
|
||||
} else {
|
||||
result as usize + cursor
|
||||
};
|
||||
|
||||
// Only modify the portion of the buffer that contains real data.
|
||||
let buf = &mut buf[0..end];
|
||||
|
||||
if let Some(last_newline_pos) = buf.iter().rposition(|&c| c == b'\n' as c_char) {
|
||||
buf[last_newline_pos] = b'\0' as c_char;
|
||||
unsafe {
|
||||
|
@ -503,7 +509,7 @@ fn redirect_stdout_to_logcat() {
|
|||
} else {
|
||||
cursor = 0;
|
||||
}
|
||||
} else if cursor == BUF_AVAILABLE {
|
||||
} else if end == BUF_AVAILABLE {
|
||||
// No newline found but the buffer is full, flush it anyway.
|
||||
// `buf.as_ptr()` is null-terminated by BUF_LENGTH being 1 less than BUF_AVAILABLE.
|
||||
unsafe {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue