Re: Cool pattern or tragic?

2023-09-24 Thread cc via Digitalmars-d-learn

On Friday, 25 August 2023 at 21:00:08 UTC, Guillaume Piolat wrote:
The idea is to deliberately mark @system functions that need 
special scrutiny to use, regardless of their memory-safety. 
Function that would typically be named `assumeXXX`.

...
That way, @safe code will still need to manually @trust them.


I basically wanted some kind of functionality similar to this but 
with regards to the GC.  Like some way to annotate a function as 
@WillAllocate or something, and forbid calling it unless the 
caller function explicitly acknowledged the allocation (without 
having to wrap everything in @nogc).  Just for fun I experimented 
with a locking GC that used the struct/dtor model to open/re-lock.




Re: range shortened method not enabled, compile with compiler switch `-preview=shortenedMethods`

2023-09-24 Thread Joe--- via Digitalmars-d-learn
On Sunday, 24 September 2023 at 12:59:57 UTC, Steven 
Schveighoffer wrote:

On Sunday, 24 September 2023 at 10:00:31 UTC, Joe wrote:

For absolutely no reason I started getting this error.

Last night I compiled the project and it worked just fine. 
This morning I made a single insignificant change and tried to 
compile and got that error. Only possible thing is that for 
some reason some change in updating the compiler may have no 
propagated correctly till after the reboot.


[...]


This sounds like a compiler issue. Are you on the latest 
compiler? Which compiler? Is there a set of code you can post 
or upload which causes the problem?


-Steve


I accidentally deleted my D folder containing the compiler and 
other things. (It as a weird issue where I was trying to add a 
command to an app and because the %1 parameter didn't have quotes 
I guess it deleted the D folder as it shortened it to D) I had a 
backup and didn't change anything since then except for updating 
the compilers. Still had the same visual D version.


So I copied it over and updated dmd with visual D. Everything 
worked fine that day and I messed with the code several times. 
Woke up and wanted to make a simple change and code would not 
compile. The changes were insignificant. It gave me that error 
and when I added that switch then I got one about 
pragma(crt_constuctor) needing extern(C). Anyways, tried adding 
the extern(C) in the code but it wouldn't accept the changes.


BUT I just tried to compile it again and no issues.

Probably drive corruption issues or possibly some type of caching 
issue.


But I was able to make changes now and compile it like it should 
work.


E.g., it's possible that when I copied over the old D directory 
that it had an old compiler(I think it was from '22). I did 
update with visual D but maybe there was caching going on that 
was causing the conflict.


In any case everything seems to be back to normal. I really 
didn't do much to fix anything so it was probably all caused by 
deleting that D folder accidentally.




Re: range shortened method not enabled, compile with compiler switch `-preview=shortenedMethods`

2023-09-24 Thread Steven Schveighoffer via Digitalmars-d-learn

On Sunday, 24 September 2023 at 10:00:31 UTC, Joe wrote:

For absolutely no reason I started getting this error.

Last night I compiled the project and it worked just fine. This 
morning I made a single insignificant change and tried to 
compile and got that error. Only possible thing is that for 
some reason some change in updating the compiler may have no 
propagated correctly till after the reboot.


[...]


This sounds like a compiler issue. Are you on the latest 
compiler? Which compiler? Is there a set of code you can post or 
upload which causes the problem?


-Steve


Re: Vibe.d download function, how to get callback when done or error?

2023-09-24 Thread Christian Köstlin via Digitalmars-d-learn

On 24.09.23 12:01, j...@bloow.edu wrote:

On Saturday, 23 September 2023 at 20:20:31 UTC, Christian Köstlin wrote:

On 23.09.23 14:07, j...@bloow.edu wrote:

I'm using download(url, filename) to download files in vibe.d.

The issue is that I do not know when the download is finished or 
errors. There is a callback for the streaming side but not for the 
file download.


A small test program shows, that if the function return normally the 
transfer was done (and the file saved).
The function raises an exception if there is e,g, an http error status 
communicated.


I am not sure what happens if the download is interrupted in the 
middle. I guess there will be an exception, but the file might be 
written partially.




Kind regards,
Christian


I can't do any testing because overnight for no explicable reason the 
app will not compile any more.


If it is synchronous then I should be able to do what I need without 
issue. When I initially was using it and the way the app works it seemed 
like it was running in parallel because I didn't see it execute 
synchronously because the tasks were relatively short and I just thought 
it was asynchronous for some reason(I didn't give it any thought at the 
time until I got errors in the download and needed to make the code more 
robust but I can't do anything until I figure out why the code no longer 
compiles(I made a post about it but it's not showing up yet).




I recommend to use
`https://httpbin.org/drip?duration=20=100=200=0` as 
url to test vibes download.


Kind regards,
Christian



Re: Vibe.d download function, how to get callback when done or error?

2023-09-24 Thread Christian Köstlin via Digitalmars-d-learn

On 24.09.23 12:01, j...@bloow.edu wrote:

On Saturday, 23 September 2023 at 20:20:31 UTC, Christian Köstlin wrote:

On 23.09.23 14:07, j...@bloow.edu wrote:

I'm using download(url, filename) to download files in vibe.d.

The issue is that I do not know when the download is finished or 
errors. There is a callback for the streaming side but not for the 
file download.


A small test program shows, that if the function return normally the 
transfer was done (and the file saved).
The function raises an exception if there is e,g, an http error status 
communicated.


I am not sure what happens if the download is interrupted in the 
middle. I guess there will be an exception, but the file might be 
written partially.




Kind regards,
Christian


I can't do any testing because overnight for no explicable reason the 
app will not compile any more.


If it is synchronous then I should be able to do what I need without 
issue. When I initially was using it and the way the app works it seemed 
like it was running in parallel because I didn't see it execute 
synchronously because the tasks were relatively short and I just thought 
it was asynchronous for some reason(I didn't give it any thought at the 
time until I got errors in the download and needed to make the code more 
robust but I can't do anything until I figure out why the code no longer 
compiles(I made a post about it but it's not showing up yet).
minimal program to test the behavior (although with fibers it might be 
tricky to see whats really going on .. perhaps try to do two downloads 
after each other and see how the program behaves):



```d
import vibe.vibe;
import std.stdio : writeln;

void main(string[] args)
{
try {
download(args[1], args[2]);
} catch (Exception e)
{
writeln("puh: ", e);
}
}
```

Kind regards,
Christian


Re: Vibe.d download function, how to get callback when done or error?

2023-09-24 Thread Joe--- via Digitalmars-d-learn
On Saturday, 23 September 2023 at 20:20:31 UTC, Christian Köstlin 
wrote:

On 23.09.23 14:07, j...@bloow.edu wrote:

I'm using download(url, filename) to download files in vibe.d.

The issue is that I do not know when the download is finished 
or errors. There is a callback for the streaming side but not 
for the file download.


A small test program shows, that if the function return 
normally the transfer was done (and the file saved).
The function raises an exception if there is e,g, an http error 
status communicated.


I am not sure what happens if the download is interrupted in 
the middle. I guess there will be an exception, but the file 
might be written partially.




Kind regards,
Christian


I can't do any testing because overnight for no explicable reason 
the app will not compile any more.


If it is synchronous then I should be able to do what I need 
without issue. When I initially was using it and the way the app 
works it seemed like it was running in parallel because I didn't 
see it execute synchronously because the tasks were relatively 
short and I just thought it was asynchronous for some reason(I 
didn't give it any thought at the time until I got errors in the 
download and needed to make the code more robust but I can't do 
anything until I figure out why the code no longer compiles(I 
made a post about it but it's not showing up yet).





Re: Vibe.d download function, how to get callback when done or error?

2023-09-24 Thread Joe--- via Digitalmars-d-learn

On Saturday, 23 September 2023 at 15:09:13 UTC, Elias wrote:

On Saturday, 23 September 2023 at 12:07:38 UTC, Joe wrote:

I'm using download(url, filename) to download files in vibe.d.

The issue is that I do not know when the download is finished 
or errors. There is a callback for the streaming side but not 
for the file download.


You don’t need a callback for that. It’s done when the 
download() returns.


Pretty sure it is not synchronous. I'm running it many times. 
Maybe it is synchronous and I just didn't notice.




range shortened method not enabled, compile with compiler switch `-preview=shortenedMethods`

2023-09-24 Thread Joe--- via Digitalmars-d-learn

For absolutely no reason I started getting this error.

Last night I compiled the project and it worked just fine. This 
morning I made a single insignificant change and tried to compile 
and got that error. Only possible thing is that for some reason 
some change in updating the compiler may have no propagated 
correctly till after the reboot.


when I add the switch I then get.

function `core.time.TickDuration.time_initializer` must be 
`extern(C)` for `pragma(crt_constructor)`


dmd-2.105.2


EVERYTHING was working fine yesterday. All I did today was load 
up the project and change an integer value and I couldn't compile 
it ;/


Maybe corruption somewhere, I don't know.

Anyways, I added extern(C) to that method in the location it says 
the file exists but no change. I removed the pragma, no change. 
Doesn't seem to actually be using that file.


I have no idea what is going on. All I can do is try to reinstall 
the compiler and maybe redo the dub package. I'm using visual D + 
vibe.d + dub. Nothing fancy.


Re: Vibe.d download function, how to get callback when done or error?

2023-09-24 Thread Imperatorn via Digitalmars-d-learn

On Saturday, 23 September 2023 at 12:07:38 UTC, Joe wrote:

I'm using download(url, filename) to download files in vibe.d.

The issue is that I do not know when the download is finished 
or errors. There is a callback for the streaming side but not 
for the file download.


If you want an asynchronous download just create a task or use 
spawn. Apparently there's also this in vibe:

https://vibed.org/api/vibe.core.concurrency/async