-
-
Notifications
You must be signed in to change notification settings - Fork 593
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
more const in root #5409
more const in root #5409
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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) | ||
{ | ||
|
@@ -40,7 +40,7 @@ struct File | |
_ref = 0; | ||
buffer = null; | ||
len = 0; | ||
name = cast(FileName*)n; | ||
name = n; | ||
} | ||
|
||
extern (C++) ~this() | ||
|
@@ -59,7 +59,7 @@ struct File | |
|
||
extern (C++) char* toChars() | ||
{ | ||
return name.toChars(); | ||
return cast(char*)name.toChars(); | ||
} | ||
|
||
/************************************* | ||
|
@@ -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(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Just use There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I thought about that, and decided explicit was better when doing this conversion. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. That will mean we're going to have to go back and change them all again when There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It'll all have to be scrutinized line by line anyway, because of 0 termination, rewrite to toString, etc. It's not encapsulated well at all. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Eh |
||
//printf("File::read('%s')\n",name); | ||
int fd = open(name, O_RDONLY); | ||
if (fd == -1) | ||
|
@@ -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; | ||
|
@@ -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; | ||
|
@@ -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; | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@yebblies here's an example of as const use grows, the casts can be removed.