-
Notifications
You must be signed in to change notification settings - Fork 520
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
[corefoundation] Fix TypeInitializationException in OSLog #7962
Conversation
`Default` property was using a nil-handle which is incorrect since * we don't allow that (this is generally a bad sign) * it does not map to `OS_LOG_DEFAULT` Since `Default` was assigned in the type (static) constructor then the whole type became unusable :( Header `log.h` shows that the right definition requires us to load a field and use it. ``` define OS_LOG_DEFAULT OS_OBJECT_GLOBAL_OBJECT(os_log_t, _os_log_default) ``` While `NULL` can actually be used for disabled (not exposed) by this contradicting (nullability-wise) macro ``` define OS_LOG_DISABLED ((os_log_t _Nonnull)NULL) ``` Also adds unit tests. A more general tests for `.cctor` will be added to introspection tests in a separate PR. Fixes dotnet#7959
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice catch!
using (var log = new OSLog ("subsystem", "category")) { | ||
log.Log (OSLogLevel.Error, "monotouch-test / custom / Debug"); | ||
// this will show in the application output (e.g. inside VSfM) | ||
// and also inside Console.app under the simulator/device |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No Asserts?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As long as it does to crash or throw here :P I think this is fine #YOLO
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@mandel-macaque not quite sure on what to assert (if it does not crash, like it would without the fix). Reading console.app is a quite troublesome from simulator and would not work on devices. Got any ideas ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think there is a way with http://www.cplusplus.com/reference/cstdio/freopen/ freopen stderr to a file, read wha was logged in the file. Maybe too much work :/
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm fine with "not crashing is good enough". I could see redirects being brittle maybe.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I won't stop you PR'ing that... but, for myself, messing with stderr, which is already used used by the test harness, seems more a problem than a solution :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There's a precedent for redirecting stderr... https://github.com/xamarin/maccore/blob/4c92d05de776e6166648f57ff26a5efab8c06363/tools/mlaunch/Xamarin.Hosting/Xamarin.Launcher/InstallationProxyService.cs#L95-L109
Build failure Test results3 tests failed, 86 tests passed.Failed tests
|
[Test] | ||
public void Default () | ||
{ | ||
OSLog.Default.Log (OSLogLevel.Default, "monotouch-test / Default / Default"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You need a version check to avoid this test on older OSes.
Unrelated failures (3) due to |
src/CoreFoundation/OSLog.cs
Outdated
|
||
static OSLog () | ||
{ | ||
_os_log_default = Dlfcn.dlsym (Libraries.System.Handle, "_os_log_default"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would make more sense to fetch this on demand in the Default getter? Otherwise it can't be linked away if someone doesn't use the Default property (it's possible to create custom OSLogs).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yes, another reason is that this will run into a similar issue (TLE) on older OS (even if less a problem since it would be unusable if called anyway)
* Only run tests on Xcode 8.0 and later * Remove .cctor as it will help the linker and ensure a TLE won't happen on older OS versions
Build failure Test results1 tests failed, 88 tests passed.Failed tests
|
Build success |
@monojenkins backport to d16-6 |
@spouliot backporting to d16-6 failed, the patch results in conflicts:
Please backport manually! |
…net#7962) `Default` property was using a nil-handle which is incorrect since * we don't allow that (this is generally a bad sign) * it does not map to `OS_LOG_DEFAULT` Since `Default` was assigned in the type (static) constructor then the whole type became unusable :( Header `log.h` shows that the right definition requires us to load a field and use it. ``` define OS_LOG_DEFAULT OS_OBJECT_GLOBAL_OBJECT(os_log_t, _os_log_default) ``` While `NULL` can actually be used for disabled (not exposed) by this contradicting (nullability-wise) macro ``` define OS_LOG_DISABLED ((os_log_t _Nonnull)NULL) ``` Also adds unit tests. A more general tests for `.cctor` will be added to introspection tests in a separate PR. Fixes dotnet#7959
…) (#7977) `Default` property was using a nil-handle which is incorrect since * we don't allow that (this is generally a bad sign) * it does not map to `OS_LOG_DEFAULT` Since `Default` was assigned in the type (static) constructor then the whole type became unusable :( Header `log.h` shows that the right definition requires us to load a field and use it. ``` define OS_LOG_DEFAULT OS_OBJECT_GLOBAL_OBJECT(os_log_t, _os_log_default) ``` While `NULL` can actually be used for disabled (not exposed) by this contradicting (nullability-wise) macro ``` define OS_LOG_DISABLED ((os_log_t _Nonnull)NULL) ``` Also adds unit tests. A more general tests for `.cctor` will be added to introspection tests in a separate PR. Fixes #7959
`Default` property was using a nil-handle which is incorrect since * we don't allow that (this is generally a bad sign) * it does not map to `OS_LOG_DEFAULT` Since `Default` was assigned in the type (static) constructor then the whole type became unusable :( Header `log.h` shows that the right definition requires us to load a field and use it. ``` define OS_LOG_DEFAULT OS_OBJECT_GLOBAL_OBJECT(os_log_t, _os_log_default) ``` While `NULL` can actually be used for disabled (not exposed) by this contradicting (nullability-wise) macro ``` define OS_LOG_DISABLED ((os_log_t _Nonnull)NULL) ``` Also adds unit tests. A more general tests for `.cctor` will be added to introspection tests in a separate PR. Fixes dotnet#7959
Default
property was using a nil-handle which is incorrect sinceOS_LOG_DEFAULT
Since
Default
was assigned in the type (static) constructor thenthe whole type became unusable :(
Header
log.h
shows that the right definition requires us to load afield and use it.
While
NULL
can actually be used for disabled (not exposed) by thiscontradicting (nullability-wise) macro
Also adds unit tests. A more general tests for
.cctor
will be addedto introspection tests in a separate PR.
Fixes #7959