~sircmpwn/hare-dev

This thread contains a patchset. You're looking at the original emails, but you may wish to use the patch review UI. Review patch
4 3

[PATCH hare 1/3] log: lfatalf: write to correct logger

Details
Message ID
<20220907060827.631091-1-jose@lombera.dev>
DKIM signature
pass
Download raw message
Patch: +6 -4
Also small improvements to documentation.

Signed-off-by: Jose Lombera <jose@lombera.dev>
---
 log/funcs.ha | 10 ++++++----
 1 file changed, 6 insertions(+), 4 deletions(-)

diff --git a/log/funcs.ha b/log/funcs.ha
index a38b687b79ca..5919ea51f039 100644
--- a/log/funcs.ha
+++ b/log/funcs.ha
@@ -27,23 +27,25 @@ export @noreturn fn lfatal(log: *logger, fields: fmt::formattable...) void = {
	os::exit(1);
};

// Formats and prints data to the log, then terminates the process.
// Formats and prints data to the log with new line, then terminates the
// process.
export @noreturn fn lfatalf(
	log: *logger,
	fmt: str,
	fields: fmt::field...
) void = {
	lprintfln(global, fmt, fields...);
	lprintfln(log, fmt, fields...);
	os::exit(1);
};

// Prints data to the global log, then terminates the process.
// Prints data to the global log with new line, then terminates the process.
export @noreturn fn fatal(fields: fmt::formattable...) void = {
	lprintln(global, fields...);
	os::exit(1);
};

// Formats and prints data to the global log, then terminates the process.
// Formats and prints data to the global log with new line, then terminates the
// process.
export @noreturn fn fatalf(fmt: str, fields: fmt::field...) void = {
	lprintfln(global, fmt, fields...);
	os::exit(1);

base-commit: 2a3bba8623e3c7c5f874ab429bbd278c760bb223
-- 
2.35.1

[PATCH hare 2/3] log: add default logger

Details
Message ID
<20220907060827.631091-2-jose@lombera.dev>
In-Reply-To
<20220907060827.631091-1-jose@lombera.dev> (view parent)
DKIM signature
pass
Download raw message
Patch: +7 -4
Add reference to default logger that doesn't change after updating
global logger with log::setlogger().  This allows user to restore global
logger to default value.

Before:

    log::setlogger(log::silent);
    log::print("NOT LOGGED");

    // At this point log::global == log::silent,
    // thus next line has no effect.
    log::setlogger(log::global);
    log::print("NOT LOGGED EITHER");

After:

    log::setlogger(log::silent);
    log::print("NOT LOGGED");
    log:setlogger(log::default);
    log::print("LOGGED");

Also, make pointer to global logger private, effectively making it an
implementation detail.

Signed-off-by: Jose Lombera <jose@lombera.dev>
---
 log/global.ha | 11 +++++++----
 1 file changed, 7 insertions(+), 4 deletions(-)

diff --git a/log/global.ha b/log/global.ha
index bb4f3dcda4ac..bbab53fdd8f3 100644
--- a/log/global.ha
+++ b/log/global.ha
@@ -1,10 +1,13 @@
use io;
use os;

// The default global logger instance.
export let global: *logger = &_global;
// The global logger instance.
let global: *logger = &_default;

let _global: stdlogger = stdlogger {
// Default logger that writes to [[os::stderr]].
export let default: *logger = &_default;

let _default: stdlogger = stdlogger {
	println = &log_println,
	printfln = &log_printfln,
	sink = -1: io::file,
@@ -12,7 +15,7 @@ let _global: stdlogger = stdlogger {

@init fn init() void = {
	// XXX: Would be nice not to have to do this
	_global.sink = os::stderr;
	_default.sink = os::stderr;
};

// Sets the global logger instance to the provided logger.
-- 
2.35.1

[PATCH hare 3/3] log: make default and silent loggers const

Details
Message ID
<20220907060827.631091-3-jose@lombera.dev>
In-Reply-To
<20220907060827.631091-1-jose@lombera.dev> (view parent)
DKIM signature
pass
Download raw message
Patch: +2 -2
This prevents user from directly modifying pointers to these loggers,
ensuring they remain semantically correct.

For example, now the following produces a compilation error:

    log::default = log::silent;

Signed-off-by: Jose Lombera <jose@lombera.dev>
---
Since only the pointer is declared const but not the data it points to,
the user can still modify the actual logger data.  For example:

    log::default.println = ...


 log/global.ha | 2 +-
 log/silent.ha | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/log/global.ha b/log/global.ha
index bbab53fdd8f3..9ff0559f4f0b 100644
--- a/log/global.ha
+++ b/log/global.ha
@@ -5,7 +5,7 @@ use os;
let global: *logger = &_default;

// Default logger that writes to [[os::stderr]].
export let default: *logger = &_default;
export const default: *logger = &_default;

let _default: stdlogger = stdlogger {
	println = &log_println,
diff --git a/log/silent.ha b/log/silent.ha
index 173c7954f89d..fa2d82884029 100644
--- a/log/silent.ha
+++ b/log/silent.ha
@@ -1,7 +1,7 @@
use fmt;

// A logger that does not print any messages.
export let silent: *logger = &_silent;
export const silent: *logger = &_silent;

let _silent: logger = logger {
	println = &silent_println,
-- 
2.35.1

[hare/patches] build success

builds.sr.ht <builds@sr.ht>
Details
Message ID
<CMPY26G11YEC.XM6RVRP8IU7V@cirno2>
In-Reply-To
<20220907060827.631091-3-jose@lombera.dev> (view parent)
DKIM signature
missing
Download raw message
hare/patches: SUCCESS in 1m35s

[log: lfatalf: write to correct logger][0] from [Jose Lombera][1]

[0]: https://lists.sr.ht/~sircmpwn/hare-dev/patches/35176
[1]: jose@lombera.dev

✓ #839939 SUCCESS hare/patches/alpine.yml  https://builds.sr.ht/~sircmpwn/job/839939
✓ #839940 SUCCESS hare/patches/freebsd.yml https://builds.sr.ht/~sircmpwn/job/839940
Details
Message ID
<CN2TGLXKC6RP.3CLPLLSS6HSEZ@taiga>
In-Reply-To
<20220907060827.631091-1-jose@lombera.dev> (view parent)
DKIM signature
pass
Download raw message
Thanks!

To git@git.sr.ht:~sircmpwn/hare
   27fd53f7..10cf8c9d  master -> master
Reply to thread Export thread (mbox)