Skip to content

Commit

Permalink
Merge pull request #5409 from WalterBright/constFile
Browse files Browse the repository at this point in the history
more const in root
  • Loading branch information
yebblies committed Feb 6, 2016
2 parents 651c162 + f98d784 commit e126d3d
Show file tree
Hide file tree
Showing 6 changed files with 18 additions and 18 deletions.
2 changes: 1 addition & 1 deletion src/dmodule.d
Expand Up @@ -539,7 +539,7 @@ public:
Module parse()
{
//printf("Module::parse(srcfile='%s') this=%p\n", srcfile->name->toChars(), this);
char* srcname = srcfile.name.toChars();
const(char)* srcname = srcfile.name.toChars();
//printf("Module::parse(srcname = '%s')\n", srcname);
isPackageFile = (strcmp(srcfile.name.name(), "package.d") == 0);
char* buf = cast(char*)srcfile.buffer;
Expand Down
14 changes: 7 additions & 7 deletions src/root/file.d
Expand Up @@ -20,7 +20,7 @@ struct File
int _ref; // != 0 if this is a reference to someone else's buffer
ubyte* buffer; // data for our file
size_t len; // amount of data in buffer[]
FileName* name; // name of our file
const(FileName)* name; // name of our file

extern (D) this(const(char)* n)
{
Expand All @@ -40,7 +40,7 @@ struct File
_ref = 0;
buffer = null;
len = 0;
name = cast(FileName*)n;
name = n;
}

extern (C++) ~this()
Expand All @@ -59,7 +59,7 @@ struct File

extern (C++) char* toChars()
{
return name.toChars();
return cast(char*)name.toChars();
}

/*************************************
Expand All @@ -73,7 +73,7 @@ struct File
size_t size;
stat_t buf;
ssize_t numread;
char* name = this.name.toChars();
const(char)* name = this.name.toChars();
//printf("File::read('%s')\n",name);
int fd = open(name, O_RDONLY);
if (fd == -1)
Expand Down Expand Up @@ -126,7 +126,7 @@ struct File
{
DWORD size;
DWORD numread;
char* name = this.name.toChars();
const(char)* name = this.name.toChars();
HANDLE h = CreateFileA(name, GENERIC_READ, FILE_SHARE_READ, null, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL | FILE_FLAG_SEQUENTIAL_SCAN, null);
if (h == INVALID_HANDLE_VALUE)
goto err1;
Expand Down Expand Up @@ -173,7 +173,7 @@ struct File
version (Posix)
{
ssize_t numwritten;
char* name = this.name.toChars();
const(char)* name = this.name.toChars();
int fd = open(name, O_CREAT | O_WRONLY | O_TRUNC, (6 << 6) | (4 << 3) | 4);
if (fd == -1)
goto err;
Expand All @@ -192,7 +192,7 @@ struct File
else version (Windows)
{
DWORD numwritten;
char* name = this.name.toChars();
const(char)* name = this.name.toChars();
HANDLE h = CreateFileA(name, GENERIC_WRITE, 0, null, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL | FILE_FLAG_SEQUENTIAL_SCAN, null);
if (h == INVALID_HANDLE_VALUE)
goto err;
Expand Down
12 changes: 6 additions & 6 deletions src/root/filename.d
Expand Up @@ -31,7 +31,7 @@ struct FileName
this.str = mem.xstrdup(str);
}

extern (C++) bool equals(RootObject obj)
extern (C++) bool equals(const RootObject obj) const
{
return compare(obj) == 0;
}
Expand All @@ -41,7 +41,7 @@ struct FileName
return compare(name1, name2) == 0;
}

extern (C++) int compare(RootObject obj)
extern (C++) int compare(const RootObject obj) const
{
return compare(str, (cast(FileName*)obj).str);
}
Expand Down Expand Up @@ -114,7 +114,7 @@ struct FileName
}
}

extern (C++) const(char)* ext()
extern (C++) const(char)* ext() const
{
return ext(str);
}
Expand Down Expand Up @@ -176,7 +176,7 @@ struct FileName
}
}

extern (C++) const(char)* name()
extern (C++) const(char)* name() const
{
return name(str);
}
Expand Down Expand Up @@ -422,7 +422,7 @@ struct FileName
/******************************
* Return !=0 if extensions match.
*/
extern (C++) bool equalsExt(const(char)* ext)
extern (C++) bool equalsExt(const(char)* ext) const
{
return equalsExt(str, ext);
}
Expand Down Expand Up @@ -675,7 +675,7 @@ struct FileName
mem.xfree(cast(void*)str);
}

extern (C++) char* toChars()
extern (C++) const(char)* toChars() const
{
return cast(char*)str; // toChars() should really be const
}
Expand Down
2 changes: 1 addition & 1 deletion src/root/filename.h
Expand Up @@ -53,7 +53,7 @@ struct FileName
static const char *canonicalName(const char *name);

static void free(const char *str);
char *toChars();
const char *toChars() const;
};

#endif
2 changes: 1 addition & 1 deletion src/root/outbuffer.d
Expand Up @@ -276,7 +276,7 @@ struct OutBuffer
offset += 4;
}

extern (C++) void write(OutBuffer* buf)
extern (C++) void write(const OutBuffer* buf)
{
if (buf)
{
Expand Down
4 changes: 2 additions & 2 deletions src/root/stringtable.d
Expand Up @@ -86,12 +86,12 @@ struct StringValue
return cast(char*)(&this + 1);
}

extern (C++) const(size_t) len()
extern (C++) size_t len() const
{
return length;
}

extern (C++) const(const(char)*) toDchars()
extern (C++) const(char)* toDchars() const
{
return cast(const(char)*)(&this + 1);
}
Expand Down

0 comments on commit e126d3d

Please sign in to comment.