-
Notifications
You must be signed in to change notification settings - Fork 4.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
113 additions
and
27 deletions.
There are no files selected for viewing
15 changes: 15 additions & 0 deletions
15
src/libraries/Common/src/Interop/iOS/System.Native/Interop.Log.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
// Licensed to the .NET Foundation under one or more agreements. | ||
This comment has been minimized.
Sorry, something went wrong. |
||
// The .NET Foundation licenses this file to you under the MIT license. | ||
// See the LICENSE file in the project root for more information. | ||
|
||
using System; | ||
using System.Runtime.InteropServices; | ||
|
||
internal static partial class Interop | ||
{ | ||
internal static partial class Sys | ||
{ | ||
[DllImport(Libraries.SystemNative, EntryPoint = "SystemNative_Log")] | ||
internal static extern unsafe bool Log(IntPtr buffer, int count); | ||
This comment has been minimized.
Sorry, something went wrong. |
||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
|
||
// Licensed to the .NET Foundation under one or more agreements. | ||
// The .NET Foundation licenses this file to you under the MIT license. | ||
// See the LICENSE file in the project root for more information. | ||
|
||
#pragma once | ||
|
||
#include "pal_compiler.h" | ||
#include "pal_types.h" | ||
|
||
PALEXPORT void SystemNative_Log(uint8_t* buffer, int32_t length); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
|
||
// Licensed to the .NET Foundation under one or more agreements. | ||
// The .NET Foundation licenses this file to you under the MIT license. | ||
// See the LICENSE file in the project root for more information. | ||
|
||
#include "pal_sys.h" | ||
#import <Foundation/Foundation.h> | ||
|
||
void SystemNative_Log (uint8_t* buffer, int32_t length) | ||
{ | ||
// COOP: no managed memory access: any mode. | ||
NSString *msg = [[NSString alloc] initWithBytes: buffer length: length encoding: NSUTF16LittleEndianStringEncoding]; | ||
|
||
// TODO: TARGET_OS_WATCH is not supported yet | ||
#if TARGET_OS_WATCH && defined (__arm__) | ||
This comment has been minimized.
Sorry, something went wrong. |
||
const char* utf8 = [msg UTF8String]; | ||
size_t len = strlen (utf8); | ||
fwrite (utf8, 1, len, stdout); | ||
if (len == 0 || utf8 [len - 1] != '\n') | ||
{ | ||
fwrite ("\n", 1, 1, stdout); | ||
} | ||
fflush (stdout); | ||
#else | ||
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]; | ||
size_t len = strlen (utf8); | ||
const size_t max_size = 4096; | ||
while (len > 0) | ||
{ | ||
size_t 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", (int) chunk_size, utf8); | ||
len -= chunk_size; | ||
utf8 += chunk_size; | ||
} | ||
} | ||
else | ||
{ | ||
NSLog (@"%@", msg); | ||
} | ||
#endif | ||
[msg release]; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This should not be under ios (tvos, macos and others have it too)