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

[corefoundation] Fix TypeInitializationException in OSLog #7962

Merged
merged 3 commits into from
Feb 25, 2020

Conversation

spouliot
Copy link
Contributor

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
@spouliot spouliot requested a review from rolfbjarne as a code owner February 24, 2020 17:03
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 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
Copy link
Member

Choose a reason for hiding this comment

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

No Asserts?

Copy link
Member

@dalexsoto dalexsoto Feb 24, 2020

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

Copy link
Contributor Author

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 ?

Copy link
Member

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 :/

Copy link
Contributor

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.

Copy link
Contributor Author

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 :)

Copy link
Member

Choose a reason for hiding this comment

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

@monojenkins
Copy link
Collaborator

Build failure
Build succeeded
API Diff (from stable)
API Diff (from PR only) (no change)
Generator Diff (no change)
🔥 Test run failed 🔥

Test results

3 tests failed, 86 tests passed.

Failed tests

  • link all/iOS Unified 64-bits - simulator/Release: Failed
  • link all/tvOS - simulator/Debug: Failed
  • link sdk/tvOS - simulator/Release: Failed

[Test]
public void Default ()
{
OSLog.Default.Log (OSLogLevel.Default, "monotouch-test / Default / Default");
Copy link
Member

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.

@spouliot
Copy link
Contributor Author

Unrelated failures (3) due to The remote server returned an error: (504) Gateway Timeout. on some tests


static OSLog ()
{
_os_log_default = Dlfcn.dlsym (Libraries.System.Handle, "_os_log_default");
Copy link
Member

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).

Copy link
Contributor Author

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
@monojenkins
Copy link
Collaborator

Build failure
Build succeeded
API Diff (from stable)
API Diff (from PR only) (no change)
Generator Diff (no change)
🔥 Test run failed 🔥

Test results

1 tests failed, 88 tests passed.

Failed tests

  • link all/tvOS - simulator/Release: Failed

@monojenkins
Copy link
Collaborator

Build success
Build succeeded
API Diff (from stable)
API Diff (from PR only) (no change)
Generator Diff (no change)
Test run succeeded

@spouliot spouliot merged commit 9a88551 into dotnet:master Feb 25, 2020
@spouliot
Copy link
Contributor Author

@monojenkins backport to d16-6

@spouliot spouliot deleted the gh7959 branch February 25, 2020 13:55
@monojenkins
Copy link
Collaborator

@spouliot backporting to d16-6 failed, the patch results in conflicts:

Applying: [corefoundation] Fix TypeInitializationException in OSLog
Using index info to reconstruct a base tree...
M	src/CoreFoundation/OSLog.cs
Falling back to patching base and 3-way merge...
Auto-merging src/CoreFoundation/OSLog.cs
CONFLICT (content): Merge conflict in src/CoreFoundation/OSLog.cs
error: Failed to merge in the changes.
Patch failed at 0001 [corefoundation] Fix TypeInitializationException in OSLog

Please backport manually!

spouliot added a commit to spouliot/xamarin-macios that referenced this pull request Feb 25, 2020
…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
spouliot added a commit that referenced this pull request Feb 25, 2020
…) (#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
dalexsoto pushed a commit to dalexsoto/xamarin-macios that referenced this pull request Mar 3, 2020
`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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

OSLog constructor yields System.TypeInitializationException: handle is null
7 participants