Skip to content

Commit 8266c00

Browse files
committed
core.system.Sys.printf() implemented (depends on libc version) and used
1 parent e79d4d2 commit 8266c00

2 files changed

Lines changed: 10 additions & 27 deletions

File tree

druntime/src/core/gc/config.d

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ module core.gc.config;
99

1010
import core.internal.parseoptions;
1111
import core.stdc.stdio : printf;
12+
import core.system : Sys;
1213
import core.system.opt : Opt;
1314

1415
alias Config = Opt.GcConfig;
@@ -57,21 +58,21 @@ struct ConfigT()
5758
{
5859
import core.gc.registry : registeredGCFactories;
5960

60-
printf("GC options are specified as white space separated assignments:
61+
Sys.printf("GC options are specified as white space separated assignments:
6162
disable:0|1 - start disabled (%d)
6263
fork:0|1 - set fork behaviour (%d)
6364
profile:0|1|2 - enable profiling with summary when terminating program (%d)
64-
gc:".ptr, disable, fork, profile);
65+
gc:", disable, fork, profile);
6566
foreach (i, entry; registeredGCFactories)
6667
{
67-
if (i) printf("|");
68+
if (i) Sys.print("|");
6869
printf("%.*s", cast(int) entry.name.length, entry.name.ptr);
6970
}
7071
auto _initReserve = initReserve.bytes2prettyStruct;
7172
auto _minPoolSize = minPoolSize.bytes2prettyStruct;
7273
auto _maxPoolSize = maxPoolSize.bytes2prettyStruct;
7374
auto _incPoolSize = incPoolSize.bytes2prettyStruct;
74-
printf(" - select gc implementation (default = conservative)
75+
Sys.printf(" - select gc implementation (default = conservative)
7576
7677
initReserve:N - initial memory to reserve in MB (%lld%c)
7778
minPoolSize:N - initial and minimum pool size in MB (%lld%c)
@@ -82,7 +83,7 @@ struct ConfigT()
8283
cleanup:none|collect|finalize - how to treat live objects when terminating (collect)
8384
8485
Memory-related values can use B, K, M or G suffixes.
85-
".ptr,
86+
",
8687
_initReserve.v, _initReserve.u,
8788
_minPoolSize.v, _minPoolSize.u,
8889
_maxPoolSize.v, _maxPoolSize.u,

druntime/src/core/system/package.d

Lines changed: 4 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -33,30 +33,12 @@ struct Sys
3333
Sys.abort();
3434
}
3535

36-
//~ void print(T)(scope const char[] str, T vals) nothrow @nogc
37-
//~ {
38-
//~ // Assume str is null-terminated string
39-
//~ auto r = fputs(str.ptr, stdout);
40-
//~ if(r < 0)
41-
//~ Sys.abort();
42-
//~ }
43-
44-
//~ alias format = snprintf
45-
}
46-
47-
// Special case: we don't have resources to implement mature formatting
48-
// functionality for now just for the sake of using it at debugging
49-
debug
50-
{
51-
static import core.stdc.stdio;
52-
53-
alias sprintf = core.stdc.stdio.sprintf;
54-
alias snprintf = core.stdc.stdio.snprintf;
55-
56-
void printf(T...)(scope const(char*) fmt, T vals) nothrow @nogc
36+
/// C-formatted print
37+
static void printf(T...)(scope const char[] fmt, T vals) nothrow @nogc
5738
{
58-
int r = core.stdc.stdio.printf(fmt, vals);
39+
static assert(T.length > 0);
5940

41+
int r = core.stdc.stdio.printf(fmt.ptr, vals);
6042
if(r < fmt.length)
6143
Sys.abort();
6244
}

0 commit comments

Comments
 (0)