Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: mockingbirdnest/Principia
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: bec06003de40
Choose a base ref
...
head repository: mockingbirdnest/Principia
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: e85b90285a5a
Choose a head ref
  • 7 commits
  • 6 files changed
  • 1 contributor

Commits on May 26, 2019

  1. C# source location

    eggrobin committed May 26, 2019
    Copy the full SHA
    3586ae4 View commit details
  2. source location

    eggrobin committed May 26, 2019
    Copy the full SHA
    ad52fcb View commit details
  3. csproj

    eggrobin committed May 26, 2019
    Copy the full SHA
    185118d View commit details
  4. fix tests

    eggrobin committed May 26, 2019
    Copy the full SHA
    7910f75 View commit details
  5. Copy the full SHA
    7299a97 View commit details

Commits on May 27, 2019

  1. journal

    eggrobin committed May 27, 2019
    Copy the full SHA
    edf541f View commit details
  2. Merge pull request #2182 from eggrobin/source-location

    Source location
    eggrobin authored May 27, 2019
    Copy the full SHA
    e85b902 View commit details
35 changes: 21 additions & 14 deletions ksp_plugin/interface.cpp
Original file line number Diff line number Diff line change
@@ -832,29 +832,36 @@ void principia__InsertUnloadedPart(Plugin* const plugin,

// Exports |LOG(SEVERITY) << text| for fast logging from the C# adapter.
// This will always evaluate its argument even if the corresponding log severity
// is disabled, so it is less efficient than LOG(INFO). It will not report the
// line and file of the caller.
void principia__LogError(char const* const text) {
journal::Method<journal::LogError> m({text});
LOG(ERROR) << text;
// is disabled, so it is less efficient than LOG(SEVERITY).
void principia__LogError(char const* const file,
int const line,
char const* const text) {
journal::Method<journal::LogError> m({file, line, text});
google::LogMessage(file, line, google::ERROR).stream() << text;
return m.Return();
}

void principia__LogFatal(char const* const text) {
journal::Method<journal::LogFatal> m({text});
LOG(FATAL) << text;
void principia__LogFatal(char const* const file,
int const line,
char const* const text) {
journal::Method<journal::LogFatal> m({file, line, text});
google::LogMessageFatal(file, line).stream() << text;
return m.Return();
}

void principia__LogInfo(char const* const text) {
journal::Method<journal::LogInfo> m({text});
LOG(INFO) << text;
void principia__LogInfo(char const* const file,
int const line,
char const* const text) {
journal::Method<journal::LogInfo> m({file, line, text});
google::LogMessage(file, line).stream() << text;
return m.Return();
}

void principia__LogWarning(char const* const text) {
journal::Method<journal::LogWarning> m({text});
LOG(WARNING) << text;
void principia__LogWarning(char const* const file,
int const line,
char const* const text) {
journal::Method<journal::LogWarning> m({file, line, text});
google::LogMessage(file, line, google::WARNING).stream() << text;
return m.Return();
}

1 change: 1 addition & 0 deletions ksp_plugin_adapter/ksp_plugin_adapter.csproj
Original file line number Diff line number Diff line change
@@ -121,6 +121,7 @@
<Compile Include="optional_marshaler.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="reference_frame_selector.cs" />
<Compile Include="source_location.cs" />
<Compile Include="style.cs" />
<Compile Include="utf8_marshaler.cs" />
<Compile Include="utf16_marshaler.cs" />
25 changes: 17 additions & 8 deletions ksp_plugin_adapter/logging.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using System;
using System.Collections.Generic;
using System.Runtime.InteropServices;
using System.Runtime.CompilerServices;

namespace principia {
namespace ksp_plugin_adapter {
@@ -57,22 +58,30 @@ internal static int GetStderrLogging() {
return Interface.GetStderrLogging();
}

internal static void Info(String message) {
Interface.LogInfo(message);
internal static void Info(String message,
[CallerFilePath] string file = "",
[CallerLineNumber] int line = -1) {
Interface.LogInfo(file, line, message);
}

internal static void Warning(String message) {
Interface.LogWarning(message);
internal static void Warning(String message,
[CallerFilePath] string file = "",
[CallerLineNumber] int line = -1) {
Interface.LogWarning(file, line, message);
}

internal static void Error(String message) {
Interface.LogError(message);
internal static void Error(String message,
[CallerFilePath] string file = "",
[CallerLineNumber] int line = -1) {
Interface.LogError(file, line, message);
}

// Returns an exception so it can be thrown so that the compiler doesn't
// complain about non-returning code.
internal static Exception Fatal(String message) {
Interface.LogFatal(message);
internal static Exception Fatal(String message,
[CallerFilePath] string file = "",
[CallerLineNumber] int line = -1) {
Interface.LogFatal(file, line, message);
return new Exception();
}
}
13 changes: 13 additions & 0 deletions ksp_plugin_adapter/source_location.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
// Pretend that we have the caller file path and line number attributes, even
// though they do not exist in .NET 3.5; since this is actually substituted
// at compile time it will work as intended.

namespace System.Runtime.CompilerServices {

[AttributeUsage(AttributeTargets.Parameter, Inherited = false)]
public sealed class CallerFilePathAttribute : Attribute {}

[AttributeUsage(AttributeTargets.Parameter, Inherited = false)]
public sealed class CallerLineNumberAttribute : Attribute {}

} // namespace System.Runtime.CompilerServices
10 changes: 5 additions & 5 deletions ksp_plugin_test/interface_test.cpp
Original file line number Diff line number Diff line change
@@ -200,8 +200,8 @@ TEST_F(InterfaceDeathTest, Errors) {
principia__CelestialFromParent(plugin, celestial_index);
}, "plugin.*non NULL");
EXPECT_DEATH({
principia__LogFatal("a fatal error");
}, "a fatal error");
principia__LogFatal("a file", 1729, "a fatal error");
}, "a file:1729.*a fatal error");
}

TEST_F(InterfaceTest, InitGoogleLogging1) {
@@ -229,9 +229,9 @@ TEST_F(InterfaceDeathTest, ActivateRecorder) {
}

TEST_F(InterfaceTest, Log) {
principia__LogInfo("An info");
principia__LogWarning("A warning");
principia__LogError("An error");
principia__LogInfo("a file", 1, "An info");
principia__LogWarning("another file", 2, "A warning");
principia__LogError("yet another file", 3, "An error");
}

TEST_F(InterfaceTest, NewPlugin) {
8 changes: 8 additions & 0 deletions serialization/journal.proto
Original file line number Diff line number Diff line change
@@ -1328,6 +1328,8 @@ message LogError {
optional LogError extension = 5010;
}
message In {
required string file = 2;
required int32 line = 3;
required string text = 1;
}
optional In in = 1;
@@ -1338,6 +1340,8 @@ message LogFatal {
optional LogFatal extension = 5011;
}
message In {
required string file = 2;
required int32 line = 3;
required string text = 1;
}
optional In in = 1;
@@ -1348,6 +1352,8 @@ message LogInfo {
optional LogInfo extension = 5012;
}
message In {
required string file = 2;
required int32 line = 3;
required string text = 1;
}
optional In in = 1;
@@ -1358,6 +1364,8 @@ message LogWarning {
optional LogWarning extension = 5013;
}
message In {
required string file = 2;
required int32 line = 3;
required string text = 1;
}
optional In in = 1;