Skip to content
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

[src] Use Runtime.NSLog instead of System.Console.WriteLine #8626

Merged
merged 2 commits into from May 20, 2020

Conversation

spouliot
Copy link
Contributor

inside the product assemblies [1]. The latter brings a lot [2] of the BCL
into the application for, eventually, ending up back to NSLog anyway

Also include a, cecil-based, test to ensure we don't regress.

[1] except for Xamarin.Mac.dll since there's a workaround for a
Sierra (only) bug

[2] https://gist.github.com/spouliot/c63343c1a76f4e49248be3a2c7aa25ed

  • A /Users/poupou/Desktop/linker.app/
  • B /Users/poupou/Projects/linker/linker/bin/iPhone/Release/linker.app/
Directories / Files A B diff %
./_CodeSignature
./
AppIcon20x20@2x~ipad.png 695 695 0 0.0%
AppIcon20x20@3x.png 1,449 1,449 0 0.0%
AppIcon20x20~ipad.png 1,128 1,128 0 0.0%
AppIcon29x29@2x.png 1,069 1,069 0 0.0%
AppIcon29x29@2x~ipad.png 1,069 1,069 0 0.0%
AppIcon29x29@3x.png 1,945 1,945 0 0.0%
AppIcon29x29~ipad.png 492 492 0 0.0%
AppIcon40x40@2x.png 1,834 1,834 0 0.0%
AppIcon40x40@2x~ipad.png 1,834 1,834 0 0.0%
AppIcon40x40@3x.png 2,632 2,632 0 0.0%
AppIcon40x40~ipad.png 695 695 0 0.0%
AppIcon60x60@2x.png 2,632 2,632 0 0.0%
AppIcon60x60@3x.png 3,624 3,624 0 0.0%
AppIcon76x76@2x~ipad.png 3,125 3,125 0 0.0%
AppIcon76x76~ipad.png 1,699 1,699 0 0.0%
AppIcon83.5x83.5@2x~ipad.png 3,369 3,369 0 0.0%
archived-expanded-entitlements.xcent 181 181 0 0.0%
Assets.car 75,128 75,128 0 0.0%
embedded.mobileprovision 8,184 8,184 0 0.0%
Info.plist 1,785 1,785 0 0.0%
linker 4,018,784 3,747,984 -270,800 -6.7%
linker.aotdata.arm64 1,240 1,240 0 0.0%
linker.exe 6,144 6,144 0 0.0%
mscorlib.aotdata.arm64 376,648 296,544 -80,104 -21.3%
mscorlib.dll 478,720 406,528 -72,192 -15.1%
NOTICE 159 159 0 0.0%
PkgInfo 8 8 0 0.0%
System.aotdata.arm64 752 752 0 0.0%
System.dll 4,608 4,608 0 0.0%
Xamarin.iOS.aotdata.arm64 34,152 33,592 -560 -1.6%
Xamarin.iOS.dll 53,760 52,736 -1,024 -1.9%
./LaunchScreen.storyboardc
Info.plist 258 258 0 0.0%
UIViewController-01J-lp-oVM.nib 896 896 0 0.0%
./Main.storyboardc
Info.plist 258 258 0 0.0%
UIViewController-BYZ-38-t0r.nib 916 916 0 0.0%
Statistics
Native subtotal 4,018,784 3,747,984 -270,800 -6.7%
Executable 4,018,784 3,747,984 -270,800 -6.7%
AOT data *.aotdata 0 0 0 -
Managed *.dll/exe 543,232 470,016 -73,216 -13.5%
TOTAL 5,108,815 4,684,135 -424,680 -8.3%

inside the product assemblies [1]. The latter brings a lot [2] of the BCL
into the application for, eventually, ending up back to `NSLog` anyway

Also include a, cecil-based, test to ensure we don't regress.

[1] except for Xamarin.Mac.dll since there's a workaround for a
Sierra (only) bug

[2]
Copy link
Member

@dalexsoto dalexsoto left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nice 👍 what an interesting fix, I'm so used to CWL that I never considered the overhead of it to just circle back into NSLog ♻️

@monojenkins
Copy link
Collaborator

Build failure
Provisioning succeeded
Build succeeded
API Diff (from stable)
API Diff (from PR only) (no change)
ℹ️ Generator Diff (please review changes)
🔥 Test run failed 🔥

Test results

1 tests failed, 90 tests passed.

Failed tests

  • mmptest/macOS/Debug: Failed (Execution failed with exit code 1)

@rolfbjarne rolfbjarne added the note-highlight Worth calling out specifically in release notes label May 20, 2020
public void NoSystemConsoleReference (string assemblyPath)
{
if (Path.GetFileName (assemblyPath) == "Xamarin.Mac.dll")
Assert.Ignore ("Xamarin.Mac has a workaround for Sierra bug w/NSLog");
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just out of curiosity: where is this workaround?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if (PlatformHelper.CheckSystemVersion (10, 12)) {

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Commit: 66cbc10

Copy link
Contributor

@chamons chamons left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Clever.

that maps to our, already existing, native `xamarin_log` function.

This is important because we can call `NSLog` before our runtime
is fully initialized and we hit an issue (see below) when using
the managed `NSString`.

This worked with `Console.WriteLine` because it ended up using
a `NSLog` (inside `mscorlib.dll`) without hitting any ObjC code
path.

* mmptests

```
20:55:16.3579440 Unhandled Exception:
20:55:16.3579850 System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation. ---> System.TypeInitializationException: The type initializer for 'Foundation.NSString' threw an exception. ---> System.ArgumentNullException: Value cannot be null.
20:55:16.3580020 Parameter name: obj
20:55:16.3580150   at (wrapper managed-to-native) System.Object.__icall_wrapper_mono_monitor_enter_v4_internal(object,intptr)
20:55:16.3580260   at ObjCRuntime.Class.GetClassHandle (System.Type type, System.Boolean throw_if_failure, System.Boolean& is_custom_type) [0x0003d] in <fa73a50c75d24e2bba1062a4d389d50f>:0
20:55:16.3580390   at ObjCRuntime.Class.GetClassHandle (System.Type type) [0x00001] in <fa73a50c75d24e2bba1062a4d389d50f>:0
20:55:16.3580510   at ObjCRuntime.Class.GetHandle (System.Type type) [0x00001] in <fa73a50c75d24e2bba1062a4d389d50f>:0
20:55:16.3580630   at Foundation.NSObject.AllocIfNeeded () [0x0001d] in <fa73a50c75d24e2bba1062a4d389d50f>:0
20:55:16.3580750   at Foundation.NSObject..ctor () [0x00008] in <fa73a50c75d24e2bba1062a4d389d50f>:0
20:55:16.3580870   at Foundation.NSString..ctor (System.String str) [0x00000] in <fa73a50c75d24e2bba1062a4d389d50f>:0
20:55:16.3580980   at Foundation.NSString..cctor () [0x0002d] in <fa73a50c75d24e2bba1062a4d389d50f>:0
20:55:16.3581270    --- End of inner exception stack trace ---
20:55:16.3581420   at ObjCRuntime.Runtime.NSLog (System.String format, System.Object[] args) [0x00001] in <fa73a50c75d24e2bba1062a4d389d50f>:0
20:55:16.3581540   at ObjCRuntime.Dlfcn.dlopen (System.String path, System.Int32 mode) [0x00045] in <fa73a50c75d24e2bba1062a4d389d50f>:0
20:55:16.3581670   at ObjCRuntime.Runtime.LookupInternalFunction[T] (System.String name) [0x00040] in <fa73a50c75d24e2bba1062a4d389d50f>:0
20:55:16.3581790   at ObjCRuntime.Runtime.EnsureInitialized () [0x00036] in <fa73a50c75d24e2bba1062a4d389d50f>:0
20:55:16.3581910   at AppKit.NSApplication.Init () [0x00016] in <fa73a50c75d24e2bba1062a4d389d50f>:0
20:55:16.3582020   at (wrapper managed-to-native) System.Reflection.RuntimeMethodInfo.InternalInvoke(System.Reflection.RuntimeMethodInfo,object,object[],System.Exception&)
20:55:16.3582150   at System.Reflection.RuntimeMethodInfo.Invoke (System.Object obj, System.Reflection.BindingFlags invokeAttr, System.Reflection.Binder binder, System.Object[] parameters, System.Globalization.CultureInfo culture) [0x0006a] in <dd436d8b1aa7421eb3bcf48b995163c4>:0
20:55:16.3582440    --- End of inner exception stack trace ---
20:55:16.3582600   at System.Reflection.RuntimeMethodInfo.Invoke (System.Object obj, System.Reflection.BindingFlags invokeAttr, System.Reflection.Binder binder, System.Object[] parameters, System.Globalization.CultureInfo culture) [0x00083] in <dd436d8b1aa7421eb3bcf48b995163c4>:0
20:55:16.3582720   at System.Reflection.MethodBase.Invoke (System.Object obj, System.Object[] parameters) [0x00000] in <dd436d8b1aa7421eb3bcf48b995163c4>:0
20:55:16.3582840   at ConsoleXMApp.MainClass.Main (System.String[] args) [0x00044] in <a2dfeee74db243eab27b7674cfa26c43>:0
20:55:16.3582960 [ERROR] FATAL UNHANDLED EXCEPTION: System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation. ---> System.TypeInitializationException: The type initializer for 'Foundation.NSString' threw an exception. ---> System.ArgumentNullException: Value cannot be null.
20:55:16.3583080 Parameter name: obj
20:55:16.3583200   at (wrapper managed-to-native) System.Object.__icall_wrapper_mono_monitor_enter_v4_internal(object,intptr)
20:55:16.3583500   at ObjCRuntime.Class.GetClassHandle (System.Type type, System.Boolean throw_if_failure, System.Boolean& is_custom_type) [0x0003d] in <fa73a50c75d24e2bba1062a4d389d50f>:0
20:55:16.3583650   at ObjCRuntime.Class.GetClassHandle (System.Type type) [0x00001] in <fa73a50c75d24e2bba1062a4d389d50f>:0
20:55:16.3583770   at ObjCRuntime.Class.GetHandle (System.Type type) [0x00001] in <fa73a50c75d24e2bba1062a4d389d50f>:0
20:55:16.3583890   at Foundation.NSObject.AllocIfNeeded () [0x0001d] in <fa73a50c75d24e2bba1062a4d389d50f>:0
20:55:16.3584020   at Foundation.NSObject..ctor () [0x00008] in <fa73a50c75d24e2bba1062a4d389d50f>:0
20:55:16.3584140   at Foundation.NSString..ctor (System.String str) [0x00000] in <fa73a50c75d24e2bba1062a4d389d50f>:0
20:55:16.3584260   at Foundation.NSString..cctor () [0x0002d] in <fa73a50c75d24e2bba1062a4d389d50f>:0
20:55:16.3584380    --- End of inner exception stack trace ---
20:55:16.3584500   at ObjCRuntime.Runtime.NSLog (System.String format, System.Object[] args) [0x00001] in <fa73a50c75d24e2bba1062a4d389d50f>:0
20:55:16.3584620   at ObjCRuntime.Dlfcn.dlopen (System.String path, System.Int32 mode) [0x00045] in <fa73a50c75d24e2bba1062a4d389d50f>:0
20:55:16.3584940   at ObjCRuntime.Runtime.LookupInternalFunction[T] (System.String name) [0x00040] in <fa73a50c75d24e2bba1062a4d389d50f>:0
20:55:16.3585100   at ObjCRuntime.Runtime.EnsureInitialized () [0x00036] in <fa73a50c75d24e2bba1062a4d389d50f>:0
20:55:16.3585230   at AppKit.NSApplication.Init () [0x00016] in <fa73a50c75d24e2bba1062a4d389d50f>:0
20:55:16.3585350   at (wrapper managed-to-native) System.Reflection.RuntimeMethodInfo.InternalInvoke(System.Reflection.RuntimeMethodInfo,object,object[],System.Exception&)
20:55:16.3585480   at System.Reflection.RuntimeMethodInfo.Invoke (System.Object obj, System.Reflection.BindingFlags invokeAttr, System.Reflection.Binder binder, System.Object[] parameters, System.Globalization.CultureInfo culture) [0x0006a] in <dd436d8b1aa7421eb3bcf48b995163c4>:0
20:55:16.3585600    --- End of inner exception stack trace ---
20:55:16.3585720   at System.Reflection.RuntimeMethodInfo.Invoke (System.Object obj, System.Reflection.BindingFlags invokeAttr, System.Reflection.Binder binder, System.Object[] parameters, System.Globalization.CultureInfo culture) [0x00083] in <dd436d8b1aa7421eb3bcf48b995163c4>:0
20:55:16.3585960   at System.Reflection.MethodBase.Invoke (System.Object obj, System.Object[] parameters) [0x00000] in <dd436d8b1aa7421eb3bcf48b995163c4>:0
20:55:16.3586110   at ConsoleXMApp.MainClass.Main (System.String[] args) [0x00044] in <a2dfeee74db243eab27b7674cfa26c43>:0
```
@monojenkins
Copy link
Collaborator

Build success
Provisioning succeeded
Build succeeded
API Diff (from stable)
API Diff (from PR only) (no change)
ℹ️ Generator Diff (please review changes)
Test run succeeded

@spouliot spouliot merged commit 4cc33f4 into xamarin:master May 20, 2020
@spouliot spouliot deleted the no-console branch May 20, 2020 17:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
note-highlight Worth calling out specifically in release notes
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

6 participants