Re: @safe std.file.read

2020-01-06 Thread Jonathan M Davis via Digitalmars-d-learn
On Monday, January 6, 2020 8:52:01 AM MST Steven Schveighoffer via Digitalmars-d-learn wrote: > On 1/6/20 5:07 AM, WebFreak001 wrote: > > I was wondering, how are you supposed to use std.file : read in @safe > > code when it returns a void[] but you want to get all bytes in the file? > > > > Is vo

Re: @safe std.file.read

2020-01-06 Thread Steven Schveighoffer via Digitalmars-d-learn
On 1/6/20 5:07 AM, WebFreak001 wrote: Or should void[] actually be castable to ubyte[] in @safe code? No, because you can implicitly cast anything to void[], including pointer arrays. Possibly const(ubyte[]). -Steve

Re: @safe std.file.read

2020-01-06 Thread Steven Schveighoffer via Digitalmars-d-learn
On 1/6/20 5:07 AM, WebFreak001 wrote: I was wondering, how are you supposed to use std.file : read in @safe code when it returns a void[] but you want to get all bytes in the file? Is void[] really the correct type it should be returning instead of ubyte[] when it just reads a (binary) file to

Re: @safe std.file.read

2020-01-06 Thread Dominikus Dittes Scherkl via Digitalmars-d-learn
On Monday, 6 January 2020 at 10:07:37 UTC, WebFreak001 wrote: I was wondering, how are you supposed to use std.file : read in @safe code when it returns a void[] but you want to get all bytes in the file? Is void[] really the correct type it should be returning instead of ubyte[] when it just

Re: @safe std.file.read

2020-01-06 Thread Dennis via Digitalmars-d-learn
I would say it should return a ubyte[]. On Monday, 6 January 2020 at 10:07:37 UTC, WebFreak001 wrote: Or should void[] actually be castable to ubyte[] in @safe code? Definitely not with the current semantics, since a void[] can alias pointers in @safe code. See: https://issues.dlang.org/show

@safe std.file.read

2020-01-06 Thread WebFreak001 via Digitalmars-d-learn
I was wondering, how are you supposed to use std.file : read in @safe code when it returns a void[] but you want to get all bytes in the file? Is void[] really the correct type it should be returning instead of ubyte[] when it just reads a (binary) file to memory? Or should void[] actually be

Re: std.file.read returns void[] why?

2014-04-20 Thread Andrej Mitrovic via Digitalmars-d-learn
On 4/18/14, monarch_dodra via Digitalmars-d-learn wrote: > Yeah... "static assert(void.sizeof == 1);" passes :/ Note that you can even have static void arrays. E.g.: https://issues.dlang.org/show_bug.cgi?id=9691 I'm not sure whether this is an oversight (accepts-invalid) or something else. But

Re: std.file.read returns void[] why?

2014-04-18 Thread monarch_dodra via Digitalmars-d-learn
On Friday, 18 April 2014 at 13:08:04 UTC, Steven Schveighoffer wrote: I admit, I didn't think C's void had a size ;) I'm pretty sure it doesn't in D, but then again... -Steve Yeah... "static assert(void.sizeof == 1);" passes :/ So in any case, long story short: "void[]": This is an un-typed

Re: std.file.read returns void[] why?

2014-04-18 Thread Steven Schveighoffer via Digitalmars-d-learn
On Fri, 18 Apr 2014 02:04:16 -0400, monarch_dodra wrote: On Thursday, 17 April 2014 at 21:27:44 UTC, Steven Schveighoffer wrote: On Thu, 17 Apr 2014 17:04:25 -0400, monarch_dodra wrote: void[] will only make sense once you've accepted that "void.sizeof == 1". It is already accepted tha

Re: std.file.read returns void[] why?

2014-04-17 Thread monarch_dodra via Digitalmars-d-learn
On Thursday, 17 April 2014 at 21:27:44 UTC, Steven Schveighoffer wrote: On Thu, 17 Apr 2014 17:04:25 -0400, monarch_dodra wrote: void[] will only make sense once you've accepted that "void.sizeof == 1". It is already accepted that when we talk about length in a void[], it's the number of byt

Re: std.file.read returns void[] why?

2014-04-17 Thread Steven Schveighoffer via Digitalmars-d-learn
On Thu, 17 Apr 2014 17:04:25 -0400, monarch_dodra wrote: On Thursday, 17 April 2014 at 12:59:20 UTC, Steven Schveighoffer wrote: It was never possible. You must explicitly cast to void[]. void[] makes actually little sense as the result of whole-file read that allocates. byte[] is at leas

Re: std.file.read returns void[] why?

2014-04-17 Thread monarch_dodra via Digitalmars-d-learn
On Thursday, 17 April 2014 at 12:59:20 UTC, Steven Schveighoffer wrote: It was never possible. You must explicitly cast to void[]. void[] makes actually little sense as the result of whole-file read that allocates. byte[] is at least usable and more accurate. In fact, it's a little dangerous t

Re: std.file.read returns void[] why?

2014-04-17 Thread sclytrack via Digitalmars-d-learn
Are you saying void[] *is* currently marked NOSCAN? import std.stdio; import core.memory; writeln("int* []", GC.query(cast(void *) arr2).attr);

Re: std.file.read returns void[] why?

2014-04-17 Thread sclytrack via Digitalmars-d-learn
On Thursday, 17 April 2014 at 14:05:50 UTC, Regan Heath wrote: On Thu, 17 Apr 2014 13:59:20 +0100, Steven Schveighoffer wrote: It was never possible. You must explicitly cast to void[]. to -> from? void[] makes actually little sense as the result of whole-file read that allocates. byte[] is

Re: std.file.read returns void[] why?

2014-04-17 Thread Steven Schveighoffer
On Thu, 17 Apr 2014 10:05:49 -0400, Regan Heath wrote: On Thu, 17 Apr 2014 13:59:20 +0100, Steven Schveighoffer wrote: It was never possible. You must explicitly cast to void[]. to -> from? Yes, sorry :) void[] makes actually little sense as the result of whole-file read that alloca

Re: std.file.read returns void[] why?

2014-04-17 Thread Regan Heath
On Thu, 17 Apr 2014 13:59:20 +0100, Steven Schveighoffer wrote: It was never possible. You must explicitly cast to void[]. to -> from? void[] makes actually little sense as the result of whole-file read that allocates. byte[] is at least usable and more accurate. In fact, it's a little d

Re: std.file.read returns void[] why?

2014-04-17 Thread Steven Schveighoffer
On Thu, 17 Apr 2014 07:57:35 -0400, Regan Heath wrote: On Wed, 16 Apr 2014 14:36:20 +0100, Spacen Jasset wrote: Why does the read function return void[] and not byte[] void[] read(in char[] name, size_t upTo = size_t.max); One one hand the data is always /actually/ going to be a load

Re: std.file.read returns void[] why?

2014-04-17 Thread Adam D. Ruppe
You can implicitly cast /to/ void[], but I don't think you could ever implicitly cast from it. Casting from it needs a bit more thought because you should ensure that it actually is what you are saying it is and the compiler can't help with that, so by prohibiting the automatic cast it at lea

Re: std.file.read returns void[] why?

2014-04-17 Thread Regan Heath
On Wed, 16 Apr 2014 14:36:20 +0100, Spacen Jasset wrote: Why does the read function return void[] and not byte[] void[] read(in char[] name, size_t upTo = size_t.max); One one hand the data is always /actually/ going to be a load of (u)bytes, but /conceptually/ it might be structs or som

std.file.read returns void[] why?

2014-04-16 Thread Spacen Jasset
Why does the read function return void[] and not byte[] void[] read(in char[] name, size_t upTo = size_t.max);

Re: std.file.read

2010-08-02 Thread bearophile
Dmitry Olshansky: > Dang, DMD does not even type check the unitest code when the compiler > option not passed. This is a small known problem of D newsgroups. To partially cope with it at the end of each module I add something like: unittest { printf(__FILE__ ~ " unittest performed."); } But am

Re: std.file.read

2010-08-02 Thread Dmitry Olshansky
On 02.08.2010 21:36, bearophile wrote: Pelle: Well, it magically converts to whatever array type you have. So this works: ubyte[] data = read("trash.txt"); This code does not work for me on dmd 2.047. AH, nor for me. Bye, bearophile Hm... it doesn't ... Ouch, I was very

Re: std.file.read

2010-08-02 Thread bearophile
Pelle: > > Well, it magically converts to whatever array type you have. So this works: > > ubyte[] data = read("trash.txt"); > > This code does not work for me on dmd 2.047. AH, nor for me. Bye, bearophile

Re: std.file.read

2010-08-02 Thread Pelle
On 08/02/2010 10:23 AM, Dmitry Olshansky wrote: On 02.08.2010 5:23, bearophile wrote: Can you tell me why std.file.read() returns a void[] instead of something like a ubyte[]? Well, it magically converts to whatever array type you have. So this works: ubyte[] data = read("trash.txt"

Re: std.file.read

2010-08-02 Thread bearophile
Dmitry Olshansky: > Well, it magically converts to whatever array type you have. So this works: > ubyte[] data = read("trash.txt"); In more than tree years of nearly daily usage of D I have not even tried to write that code :-) Thank you, bearophile

Re: std.file.read

2010-08-02 Thread Dmitry Olshansky
On 02.08.2010 5:23, bearophile wrote: Can you tell me why std.file.read() returns a void[] instead of something like a ubyte[]? Well, it magically converts to whatever array type you have. So this works: ubyte[] data = read("trash.txt"); It's interesting fact de

std.file.read

2010-08-01 Thread bearophile
Can you tell me why std.file.read() returns a void[] instead of something like a ubyte[]? (Performing a cast(ubyte[]) in SafeD can be a problem. I presume in SafeD I have to use other safer functions to load binary data, like slurp() or something similar.) Bye, bearophile