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

Avoid unnecessary template #16982

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions compiler/src/dmd/glue.d
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@
if (writeLibrary && !global.errors)
{
if (verbose)
eSink.message(Loc.initial, "library %.*s", library.filename.fTuple.expand);
eSink.message(Loc.initial, "library %.*s", cast(int) library.filename.length, library.filename.ptr);

Check warning on line 172 in compiler/src/dmd/glue.d

View check run for this annotation

Codecov / codecov/patch

compiler/src/dmd/glue.d#L172

Added line #L172 was not covered by tests

if (!ensurePathToNameExists(Loc.initial, library.filename))
fatal();
Expand All @@ -184,7 +184,7 @@

if (!libbuf.moveToFile(library.filename))
{
eSink.error(Loc.initial, "error writing file '%.*s'", library.filename.fTuple.expand);
eSink.error(Loc.initial, "error writing file '%.*s'", cast(int) library.filename.length, library.filename.ptr);

Check warning on line 187 in compiler/src/dmd/glue.d

View check run for this annotation

Codecov / codecov/patch

compiler/src/dmd/glue.d#L187

Added line #L187 was not covered by tests
destroy(tmpname);
fatal();
}
Expand Down
2 changes: 1 addition & 1 deletion compiler/src/dmd/lib/elf.d
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ final class LibElf : Library
void corrupt(int reason)
{
eSink.error(Loc.initial, "corrupt ELF object `%.*s` module %.*s %d",
filename.fTuple.expand, module_name.fTuple.expand, reason);
cast(int) filename.length, filename.ptr, cast(int) module_name.length, module_name.ptr, reason);
}

int fromfile = 0;
Expand Down
2 changes: 1 addition & 1 deletion compiler/src/dmd/lib/mach.d
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ final class LibMach : Library
void corrupt(int reason)
{
eSink.error(Loc.initial, "corrupt Mach object `%.*s` module %.*s %d",
filename.fTuple.expand, module_name.fTuple.expand, reason);
cast(int) filename.length, filename.ptr, cast(int) module_name.length, module_name.ptr, reason);
}

int fromfile = 0;
Expand Down
2 changes: 1 addition & 1 deletion compiler/src/dmd/lib/mscoff.d
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ final class LibMSCoff : Library
void corrupt(int reason)
{
eSink.error(Loc.initial, "corrupt MS Coff object `%.*s` module %.*s %d",
filename.fTuple.expand, module_name.fTuple.expand, reason);
cast(int) filename.length, filename.ptr, cast(int) module_name.length, module_name.ptr, reason);
}

int fromfile = 0;
Expand Down
3 changes: 1 addition & 2 deletions compiler/src/dmd/lib/scanelf.d
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@

import dmd.errorsink;
import dmd.location;
import dmd.root.string : fTuple;

nothrow:

Expand All @@ -44,8 +43,8 @@

void corrupt(int reason)
{
eSink.error(Loc.initial, "corrupt ELF object `%.*s` module `%s` %d", filename.fTuple.expand, module_name, reason);
eSink.error(Loc.initial, "corrupt ELF object `%.*s` module `%s` %d", cast(int) filename.length, filename.ptr, module_name, reason);
}

Check warning on line 47 in compiler/src/dmd/lib/scanelf.d

View check run for this annotation

Codecov / codecov/patch

compiler/src/dmd/lib/scanelf.d#L46-L47

Added lines #L46 - L47 were not covered by tests

if (base.length < Elf32_Ehdr.sizeof)
return corrupt(__LINE__); // must be at least large enough for ELF32
Expand Down
3 changes: 1 addition & 2 deletions compiler/src/dmd/lib/scanmach.d
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ import dmd.errorsink;
import dmd.location;
//import core.sys.darwin.mach.loader;
import dmd.backend.mach;
import dmd.root.string : fTuple;

nothrow:

Expand All @@ -45,7 +44,7 @@ void scanMachObjModule(void delegate(const(char)[] name, int pickAny) nothrow pA

void corrupt(int reason)
{
eSink.error(Loc.initial, "corrupt Mach-O object `%.*s` module `%s` %d", filename.fTuple.expand, module_name, reason);
eSink.error(Loc.initial, "corrupt Mach-O object `%.*s` module `%s` %d", cast(int) filename.length, filename.ptr, module_name, reason);
}

const buf = base.ptr;
Expand Down
3 changes: 1 addition & 2 deletions compiler/src/dmd/lib/scanmscoff.d
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@

import dmd.errorsink;
import dmd.location;
import dmd.root.string : fTuple;

nothrow:

Expand All @@ -45,7 +44,7 @@

void corrupt(int reason)
{
eSink.error(Loc.initial, "corrupt MS-Coff object `%.*s` module `%s` %d", filename.fTuple.expand, module_name, reason);
eSink.error(Loc.initial, "corrupt MS-Coff object `%.*s` module `%s` %d", cast(int) filename.length, filename.ptr, module_name, reason);

Check warning on line 47 in compiler/src/dmd/lib/scanmscoff.d

View check run for this annotation

Codecov / codecov/patch

compiler/src/dmd/lib/scanmscoff.d#L47

Added line #L47 was not covered by tests
}

const buf = &base[0];
Expand Down
13 changes: 1 addition & 12 deletions compiler/src/dmd/root/string.d
Original file line number Diff line number Diff line change
Expand Up @@ -20,24 +20,13 @@ inout(char)[] toDString (inout(char)* s) pure nothrow @nogc
return s ? s[0 .. strlen(s)] : null;
}

private struct FTuple(T...)
{
T expand;
Copy link
Contributor

Choose a reason for hiding this comment

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

does alias expand this; work here? if so we should use it and give FTuple a less cryptic name.

Copy link
Contributor

Choose a reason for hiding this comment

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

I tried, but they won't auto expand in C-style variadic argument lists

Copy link
Contributor

Choose a reason for hiding this comment

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

Perhaps str.lengthPtr.expand is clearer?

}

/// Returns: a (length, ptr) tuple for passing a D string to `printf`-style functions with the format string `%.*s`
auto fTuple(const(char)[] str)
{
return FTuple!(int, const(char)*)(cast(int) str.length, str.ptr);
}

///
unittest
{
import core.stdc.stdio: snprintf;
char[6] buf = '.';
const(char)[] str = "cutoff"[0..4];
snprintf(buf.ptr, buf.length, "%.*s", str.fTuple.expand);
Copy link
Contributor

Choose a reason for hiding this comment

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

This entire unittest should be removed, without fTuple it's moot

snprintf(buf.ptr, buf.length, "%.*s", cast(int) str.length, str.ptr);
assert(buf[] == "cuto\0.");
}

Expand Down
Loading