Re: FreeBSD 13 : wrong kernel version and size of kevent_t

2021-12-21 Thread rempas via Digitalmars-d-learn

On Tuesday, 21 December 2021 at 21:09:14 UTC, eugene wrote:


* The ldc installed by 'pkg install ldc' (the old one), does 
not have config module
* Most resent ldc (link you indicated), does have condig 
module, and it is exactly the same as condig in most recent dmd


Cool! Makes sense! I thought you didn't tried the latest LDC2 at 
all so it seemed weird to me. Great job man!


Re: FreeBSD 13 : wrong kernel version and size of kevent_t

2021-12-21 Thread Johan via Digitalmars-d-learn

On Tuesday, 21 December 2021 at 21:09:14 UTC, eugene wrote:

On Tuesday, 21 December 2021 at 21:02:21 UTC, rempas wrote:

On Tuesday, 21 December 2021 at 19:55:13 UTC, eugene wrote:


core/sys/freebsd/config.d and core/sys/freebsd/sys/event.d
are the same as in fresh dmd, so there is not much sense to 
try it.

dmd (including phobos) is a reference, and I do not think,
that ldc is ahead of dmd with it's stdlib.


Oh, that was in the next page and I didn't saw it when I 
replied. So to continue from my last comment (and answer on 
this one), I thought you said that LDC does not include 
"core.sys.freebsd.config" 
[here](https://forum.dlang.org/post/sjausqwudtujswpom...@forum.dlang.org) or is

there something I didn't understand right?


* The ldc installed by 'pkg install ldc' (the old one), does 
not have config module
* Most resent ldc (link you indicated), does have condig 
module, and it is exactly the same as condig in most recent dmd


Hi Eugene,
  When you run `ldc2 -v test.d` (some arbitrary d file), you 
should see "predefs" at the top, followed by a bunch of 
predefined versions by the compiler. FreeBSD_xx should be on that 
list, and the number should correspond to your OS version. If it 
does not, then that's a bug in LDC.
I was wrong: LDC is using its own code to determine the OS 
version, and it should already do that correctly.


cheers,
  Johan



Re: How to properly use variadic templates (functions)?

2021-12-21 Thread russhy via Digitalmars-d-learn
On Tuesday, 21 December 2021 at 18:51:38 UTC, Stanislav Blinov 
wrote:

On Tuesday, 21 December 2021 at 15:42:59 UTC, russhy wrote:
Please keep us updated, that'll be interesting to see how a 
pure D printf would look like!


It already exists, it's called std.format.write.formattedWrite, 
in terms of which things like std.stdio.writef are implemented.


I took a look and to be honest, it's the same story as everything 
in the STD, they try to do everything at the same time, so they 
up end calling each other, you end up lost in multiple 8k LOC 
modules, not understanding what the function is doing anymore, 
it's a rotten place


Plus they are not nogc

OP's attempt is clean, you know what's up, you can read the code, 
free of dependencies (for now), and hopefully nogc



i want to encourage more code like that


Re: Thread exits immediately with no reason.

2021-12-21 Thread solidstate1991 via Digitalmars-d-learn
On Tuesday, 21 December 2021 at 19:00:01 UTC, solidstate1991 
wrote:
Well, it seems like it's an error on the WASAPI side. I totally 
disabled error handling (including the switch-case thingy), 
then GetBuffer returns with an error code indicating buffer is 
too large.


The solution was to call `ResetEvent()` on the event handle, then 
to tinker a little bit with destructors, etc.


Re: FreeBSD 13 : wrong kernel version and size of kevent_t

2021-12-21 Thread eugene via Digitalmars-d-learn

On Tuesday, 21 December 2021 at 21:02:21 UTC, rempas wrote:

On Tuesday, 21 December 2021 at 19:55:13 UTC, eugene wrote:


core/sys/freebsd/config.d and core/sys/freebsd/sys/event.d
are the same as in fresh dmd, so there is not much sense to 
try it.

dmd (including phobos) is a reference, and I do not think,
that ldc is ahead of dmd with it's stdlib.


Oh, that was in the next page and I didn't saw it when I 
replied. So to continue from my last comment (and answer on 
this one), I thought you said that LDC does not include 
"core.sys.freebsd.config" 
[here](https://forum.dlang.org/post/sjausqwudtujswpom...@forum.dlang.org) or is

there something I didn't understand right?


* The ldc installed by 'pkg install ldc' (the old one), does not 
have config module
* Most resent ldc (link you indicated), does have condig module, 
and it is exactly the same as condig in most recent dmd





Re: FreeBSD 13 : wrong kernel version and size of kevent_t

2021-12-21 Thread rempas via Digitalmars-d-learn

On Tuesday, 21 December 2021 at 19:55:13 UTC, eugene wrote:


core/sys/freebsd/config.d and core/sys/freebsd/sys/event.d
are the same as in fresh dmd, so there is not much sense to try 
it.

dmd (including phobos) is a reference, and I do not think,
that ldc is ahead of dmd with it's stdlib.


Oh, that was in the next page and I didn't saw it when I replied. 
So to continue from my last comment (and answer on this one), I 
thought you said that LDC does not include 
"core.sys.freebsd.config" 
[here](https://forum.dlang.org/post/sjausqwudtujswpom...@forum.dlang.org) or is there something I didn't understand right? And WOW! We are making a big conversation here, lol


Re: FreeBSD 13 : wrong kernel version and size of kevent_t

2021-12-21 Thread rempas via Digitalmars-d-learn

On Tuesday, 21 December 2021 at 19:40:52 UTC, eugene wrote:


But i like to use software out of the box and
do not like compile it from source.

Me too! The link I gave you has a binary release with LDC2. You 
won't have to compile it yourself.




I do not see any reason for me to do this.
The "problem" (with dmd, not with ldc) is
that despite phobos does contain everthing for ver 12+,
the version itself is incorrect.


I agree tho what I was wondering was if the latest version LDC2 
will now have the missing definitions for freeBSD. The versioning 
will of course be wrong (as LDC2 uses DMD as a frontend from what 
I know) but if the other info isn't added then maybe we should 
add an issue in their Github. Of course if you don't care about 
LDC2 you should not spend your time


Re: FreeBSD 13 : wrong kernel version and size of kevent_t

2021-12-21 Thread eugene via Digitalmars-d-learn
On Tuesday, 21 December 2021 at 19:49:26 UTC, Steven 
Schveighoffer wrote:
If this is a compiler-supplied version, then I don't think you 
are allowed to set it explicitly.



moreover... commented out in condig.d like this:


```d
 version (FreeBSD_12) enum __FreeBSD_version = 1202000;
//else version (FreeBSD_11) enum __FreeBSD_version = 1104000;
//else version (FreeBSD_10) enum __FreeBSD_version = 1004000;
//else version (FreeBSD_9)  enum __FreeBSD_version = 903000;
//else version (FreeBSD_8)  enum __FreeBSD_version = 804000;
//else static assert(false, "Unsupported version of FreeBSD");
```

and...

```
@bsd:~/d> dmd freebsdver
/usr/include/d/dmd/core/sys/posix/sys/types.d(201): Error: 
undefined identifier `__FreeBSD_version`
/usr/include/d/dmd/core/sys/posix/stdio.d(393): Error: undefined 
identifier `__FreeBSD_version`
/usr/include/d/dmd/core/sys/freebsd/sys/event.d(42): Error: 
undefined identifier `__FreeBSD_version`
/usr/include/d/dmd/core/sys/freebsd/sys/event.d(173): Error: 
undefined identifier `__FreeBSD_version`

```




Re: FreeBSD 13 : wrong kernel version and size of kevent_t

2021-12-21 Thread eugene via Digitalmars-d-learn

On Tuesday, 21 December 2021 at 19:22:35 UTC, rempas wrote:
Yeah, don't use the "pkg" version as it is outdated. It is very 
hard to keep a whole OS (thousands of packages) up to date. So 
yeah, uninstall your current ldc and trying with the one from 
the link I gave you and tell me the output


core/sys/freebsd/config.d and core/sys/freebsd/sys/event.d
are the same as in fresh dmd, so there is not much sense to try 
it.

dmd (including phobos) is a reference, and I do not think,
that ldc is ahead of dmd with it's stdlib.



Re: FreeBSD 13 : wrong kernel version and size of kevent_t

2021-12-21 Thread Steven Schveighoffer via Digitalmars-d-learn

On 12/21/21 2:32 PM, eugene wrote:

On Tuesday, 21 December 2021 at 19:13:19 UTC, Steven Schveighoffer wrote:

On 12/21/21 1:50 PM, eugene wrote:

```d
 version (FreeBSD_12) enum __FreeBSD_version = 1202000;
else version (FreeBSD_11) enum __FreeBSD_version = 1104000;
else version (FreeBSD_10) enum __FreeBSD_version = 1004000;
else version (FreeBSD_9)  enum __FreeBSD_version = 903000;
else version (FreeBSD_8)  enum __FreeBSD_version = 804000;
else static assert(false, "Unsupported version of FreeBSD");
```

but __FreeBSD_version is 1104000 anyway.


Not sure how those versions are set. I have a hard time following the 
dmd code to see where it might check the current-running OS to check 
for the version.


I think, it'd be nice to set it in /etc/dmd.conf
Or.. is it bad idea?..



If this is a compiler-supplied version, then I don't think you are 
allowed to set it explicitly.


-Steve


Re: FreeBSD 13 : wrong kernel version and size of kevent_t

2021-12-21 Thread eugene via Digitalmars-d-learn

On Tuesday, 21 December 2021 at 19:22:35 UTC, rempas wrote:

On Tuesday, 21 December 2021 at 19:00:04 UTC, eugene wrote:


Well, I just installed it by

   pkg intstall ldc

Actually, this is my first experience with FreeBSD,
I did not have much to go deeper.


That's nice trying new things ;)


Yeah, but as I've already said, "new thing" for was kqueue.
That's all.



Oh, no, sorry. :)
It is the problem of FreeBSD maintainers to have fresh ldc in 
the distribution.


Yeah, don't use the "pkg" version as it is outdated.


But i like to use software out of the box and
do not like compile it from source.

It is very hard to keep a whole OS (thousands of packages) up 
to date. So yeah, uninstall your current ldc and trying with 
the one from the link I gave you and tell me the output


I do not see any reason for me to do this.
The "problem" (with dmd, not with ldc) is
that despite phobos does contain everthing for ver 12+,
the version itself is incorrect.



Re: FreeBSD 13 : wrong kernel version and size of kevent_t

2021-12-21 Thread eugene via Digitalmars-d-learn
On Tuesday, 21 December 2021 at 19:13:19 UTC, Steven 
Schveighoffer wrote:

On 12/21/21 1:50 PM, eugene wrote:

```d
     version (FreeBSD_12) enum __FreeBSD_version = 1202000;
else version (FreeBSD_11) enum __FreeBSD_version = 1104000;
else version (FreeBSD_10) enum __FreeBSD_version = 1004000;
else version (FreeBSD_9)  enum __FreeBSD_version = 903000;
else version (FreeBSD_8)  enum __FreeBSD_version = 804000;
else static assert(false, "Unsupported version of FreeBSD");
```

but __FreeBSD_version is 1104000 anyway.


Not sure how those versions are set. I have a hard time 
following the dmd code to see where it might check the 
current-running OS to check for the version.


I think, it'd be nice to set it in /etc/dmd.conf
Or.. is it bad idea?..



Re: FreeBSD 13 : wrong kernel version and size of kevent_t

2021-12-21 Thread rempas via Digitalmars-d-learn

On Tuesday, 21 December 2021 at 19:00:04 UTC, eugene wrote:


Well, I just installed it by

   pkg intstall ldc

Actually, this is my first experience with FreeBSD,
I did not have much to go deeper.


That's nice trying new things ;)



Oh, no, sorry. :)
It is the problem of FreeBSD maintainers to have fresh ldc in 
the distribution.


Yeah, don't use the "pkg" version as it is outdated. It is very 
hard to keep a whole OS (thousands of packages) up to date. So 
yeah, uninstall your current ldc and trying with the one from the 
link I gave you and tell me the output


Re: FreeBSD 13 : wrong kernel version and size of kevent_t

2021-12-21 Thread Steven Schveighoffer via Digitalmars-d-learn

On 12/21/21 1:50 PM, eugene wrote:

On Tuesday, 21 December 2021 at 17:00:06 UTC, Johan wrote:
I think the fix is needed here: 
https://github.com/dlang/dmd/blob/ad8412530e607ffebec36f2dbdff1a6f2798faf7/src/dmd/target.d#L362-L372 



looks like this.

it is a little bit strange, that in
/usr/include/d/dmd/core/sys/freebsd/config.d
there is ver 12:

```d
     version (FreeBSD_12) enum __FreeBSD_version = 1202000;
else version (FreeBSD_11) enum __FreeBSD_version = 1104000;
else version (FreeBSD_10) enum __FreeBSD_version = 1004000;
else version (FreeBSD_9)  enum __FreeBSD_version = 903000;
else version (FreeBSD_8)  enum __FreeBSD_version = 804000;
else static assert(false, "Unsupported version of FreeBSD");
```

but __FreeBSD_version is 1104000 anyway.


Not sure how those versions are set. I have a hard time following the 
dmd code to see where it might check the current-running OS to check for 
the version.


-Steve


Re: FreeBSD 13 : wrong kernel version and size of kevent_t

2021-12-21 Thread eugene via Digitalmars-d-learn

On Tuesday, 21 December 2021 at 17:00:06 UTC, Johan wrote:

On Tuesday, 21 December 2021 at 10:28:15 UTC, eugene wrote:

On Monday, 20 December 2021 at 21:19:43 UTC, rempas wrote:
I would recommend you to file an 
[issue](https://issues.dlang.org/) just so the developers 
themself can notice it.


filed an issue, see
https://issues.dlang.org/show_bug.cgi?id=22615


Please add which compiler(s) you have tried in the bug report.


done, added a couple of comments




Re: FreeBSD 13 : wrong kernel version and size of kevent_t

2021-12-21 Thread eugene via Digitalmars-d-learn

On Tuesday, 21 December 2021 at 18:42:10 UTC, rempas wrote:
I'm wondering what happens in the latest LDC2 version. Your 
version is from 1 year and 4 months ago.


Well, I just installed it by

   pkg intstall ldc

Actually, this is my first experience with FreeBSD,
I did not have much to go deeper.

The 
[latest](https://github.com/ldc-developers/ldc/releases/tag/v1.28.0) release offers pre built binaries from FreeBSD so can you grab one and test to see if there are any changes?


Oh, no, sorry. :)
It is the problem of FreeBSD maintainers to have fresh ldc in the 
distribution.




Re: Thread exits immediately with no reason.

2021-12-21 Thread solidstate1991 via Digitalmars-d-learn
Well, it seems like it's an error on the WASAPI side. I totally 
disabled error handling (including the switch-case thingy), then 
GetBuffer returns with an error code indicating buffer is too 
large.


Re: How to properly use variadic templates (functions)?

2021-12-21 Thread Stanislav Blinov via Digitalmars-d-learn

On Tuesday, 21 December 2021 at 15:42:59 UTC, russhy wrote:
Please keep us updated, that'll be interesting to see how a 
pure D printf would look like!


It already exists, it's called std.format.write.formattedWrite, 
in terms of which things like std.stdio.writef are implemented.


Re: FreeBSD 13 : wrong kernel version and size of kevent_t

2021-12-21 Thread eugene via Digitalmars-d-learn

On Tuesday, 21 December 2021 at 17:00:06 UTC, Johan wrote:
I think the fix is needed here: 
https://github.com/dlang/dmd/blob/ad8412530e607ffebec36f2dbdff1a6f2798faf7/src/dmd/target.d#L362-L372


looks like this.

it is a little bit strange, that in
/usr/include/d/dmd/core/sys/freebsd/config.d
there is ver 12:

```d
version (FreeBSD_12) enum __FreeBSD_version = 1202000;
else version (FreeBSD_11) enum __FreeBSD_version = 1104000;
else version (FreeBSD_10) enum __FreeBSD_version = 1004000;
else version (FreeBSD_9)  enum __FreeBSD_version = 903000;
else version (FreeBSD_8)  enum __FreeBSD_version = 804000;
else static assert(false, "Unsupported version of FreeBSD");
```

but __FreeBSD_version is 1104000 anyway.









Re: FreeBSD 13 : wrong kernel version and size of kevent_t

2021-12-21 Thread rempas via Digitalmars-d-learn

On Tuesday, 21 December 2021 at 18:35:43 UTC, eugene wrote:


LDC2 stdlib does not have correct struct event_t for 12+ in
/usr/local/include/d/core/sys/freebsd/sys/event.d at all,
only for earlier versions, ie without extension field.

DMD stdlib does have, the only problem is the OS version is 
wrong.


---
@bsd:~/d> ldc2 -v
binary/usr/local/bin/ldc2
version   1.23.0 (DMD v2.093.1, LLVM 10.0.1)


I'm wondering what happens in the latest LDC2 version. Your 
version is from 1 year and 4 months ago. The 
[latest](https://github.com/ldc-developers/ldc/releases/tag/v1.28.0) release offers pre built binaries from FreeBSD so can you grab one and test to see if there are any changes?


Re: FreeBSD 13 : wrong kernel version and size of kevent_t

2021-12-21 Thread eugene via Digitalmars-d-learn

On Tuesday, 21 December 2021 at 18:28:12 UTC, rempas wrote:
I would love to see more full (and correct) support for 
FreeBSD, OpenBSD and DragonflyBSD from Dlang! Maybe one day..


My interest was kqueue facility.
I use linux epoll facility a lot in my progs,
and just wanted to do some exersises with kqueue



Re: FreeBSD 13 : wrong kernel version and size of kevent_t

2021-12-21 Thread eugene via Digitalmars-d-learn

On Tuesday, 21 December 2021 at 17:32:44 UTC, rempas wrote:

Yeah, you are right! Please eugene use LDC2 and check confirm


LDC2 stdlib does not have correct struct event_t for 12+ in
/usr/local/include/d/core/sys/freebsd/sys/event.d at all,
only for earlier versions, ie without extension field.

DMD stdlib does have, the only problem is the OS version is wrong.

---
@bsd:~/d> ldc2 -v
binary/usr/local/bin/ldc2
version   1.23.0 (DMD v2.093.1, LLVM 10.0.1)



Re: FreeBSD 13 : wrong kernel version and size of kevent_t

2021-12-21 Thread rempas via Digitalmars-d-learn
I would love to see more full (and correct) support for FreeBSD, 
OpenBSD and DragonflyBSD from Dlang! Maybe one day..


Re: FreeBSD 13 : wrong kernel version and size of kevent_t

2021-12-21 Thread eugene via Digitalmars-d-learn

On Tuesday, 21 December 2021 at 17:32:44 UTC, rempas wrote:
Please eugene use LDC2 and check confirm that the behavior is 
the same there.


Phobos that shipped with LDC, does not have 
core.sys.freebsd.config

So

```d
import std.stdio;
//import core.sys.freebsd.config;
import core.sys.freebsd.sys.event;

void main(string[] args) {
//writefln("FreeBSD_version = %s", __FreeBSD_version);
writefln("sizeof(kevent_t) = %s", kevent_t.sizeof);
}
```

and

```
@bsd:~/d> ldc2 freebsdver.d
@bsd:~/d> ./freebsdver
sizeof(kevent_t) = 32
```

As you see, sizeof struct kevent_t is also wrong, must be 64:

exerpt from /usr/include/sys/event.h

```c
struct kevent {
__uintptr_t ident;  // identifier for this 
event

short   filter; // filter for event
unsigned short  flags;  // action flags for kqueue
unsigned intfflags; // filter flag value
__int64_t   data;   // filter data value
void*udata; // opaque user data 
identifier

__uint64_t  ext[4]; // extensions
};

#if defined(_WANT_FREEBSD11_KEVENT)
// Older structure used in FreeBSD 11.x and older.
struct kevent_freebsd11 {
__uintptr_t ident;  // identifier for this 
event

short   filter; // filter for event
unsigned short  flags;
unsigned intfflags;
__intptr_t  data;
void*udata; // opaque user data 
identifier

};
#endif
```



Re: Thread exits immediately with no reason.

2021-12-21 Thread Ali Çehreli via Digitalmars-d-learn

On 12/21/21 10:07 AM, solidstate1991 wrote:

> I couldn't add those lines unfortunately,

Perhaps I had typos? Or the code is not yours to modify? In any case, 
you should be able to introduce a top level thread entry function and 
put the try-catch in there.


> but I do get an exception in a
> destructor at line 218 of `wasapi.d`. It's access violation executing a
> location.

If garbage-collected objects are involved, it may be because destructors 
are executed at indeterminate times, potentially after their members are 
destroyed. I haven't studied the code to be sure but for example, 
eventHandle may have already been destroyed when executing the following 
line:



https://github.com/ZILtoid1991/iota/blob/main/source/iota/audio/wasapi.d#L218

A solution is to manage the destruction of objects at known times e.g. 
by calling destroy() explicitly.


Ali



Re: FreeBSD 13 : wrong kernel version and size of kevent_t

2021-12-21 Thread eugene via Digitalmars-d-learn

On Tuesday, 21 December 2021 at 17:32:44 UTC, rempas wrote:

On Tuesday, 21 December 2021 at 17:00:06 UTC, Johan wrote:


Please add which compiler(s) you have tried in the bug report.


Yeah, you are right! Please eugene use LDC2 and check confirm 
that the behavior is the same there.


I have. Same picture.

Yeah, I think it is very clear as there is no case for FreeBSD 
13. So probably this will be easily fixed


Yes, one need to let compiler see actual OS version.
I just do not know how to do it and do it correctly.



Re: Thread exits immediately with no reason.

2021-12-21 Thread solidstate1991 via Digitalmars-d-learn

On Tuesday, 21 December 2021 at 01:13:10 UTC, Ali Çehreli wrote:
I bet it's throwing an Error. Call your thread entry function 
from a try-catch wrapping function to see whether that's the 
case:


// Rename existing function:
protected void audioThreadImpl() @nogc nothrow {
  // ...
}

// New function
protected void audioThread() @nogc nothrow {
  try {
audioThreadImpl();

  } catch (Error err) {
stderr.writefln!"ERROR: %s"(err);
  }
}

That should print a call stack. You can catch Throwable instead 
of Error but with nothrow, it's guaranteed that it's not an 
Exception.


Note: nothrow means "does not throw Exception". Errors can 
still be thrown.


Ali


I couldn't add those lines unfortunately, but I do get an 
exception in a destructor at line 218 of `wasapi.d`. It's access 
violation executing a location.


Re: How to properly use variadic templates (functions)?

2021-12-21 Thread rempas via Digitalmars-d-learn
On Tuesday, 21 December 2021 at 17:33:09 UTC, Steven 
Schveighoffer wrote:


The reason your original isn't working is that indexing a list 
of differently-typed things cannot be done using a runtime 
index.


I'd say that an inner function + static foreach + switch is the 
best way to convert from runtime to compile-time values. And in 
general, I would say having function templates that handle each 
arg type are usually conducive to clean and easy code.


But in the case you are suggesting, as long as you don't need 
to iterate them out of order, what you can do is foreach the 
args tuple, and do something like:


```d
foreach(arg; args)
{
   writeUpToNextDelimeter(prompt); // updates prompt to point 
at next delimiter

   processArg(arg, prompt);
}
```

-Steve


Got that! Thanks a lot Steve!



Re: How to properly use variadic templates (functions)?

2021-12-21 Thread Steven Schveighoffer via Digitalmars-d-learn

On 12/21/21 4:28 AM, rempas wrote:

On Tuesday, 21 December 2021 at 08:42:35 UTC, vit wrote:


You can use switch + static foreach:

```d
import std.stdio;

    //this print args in reverse order:
    void print(T...)(string prompt, T args)
    {
    void print_arg(size_t index){
    switch(index){
    static foreach(i, a; args){
    case i:
    // handle your other types
    write(a);
    return;
    }
    default:
    assert(0, "no impl");
    }
    }

    write(prompt);
    size_t len = args.length;
    while(len --> 0)
    print_arg(len);
    }

    void main(){
    print("Prompt (ignored): ", "Hello", " world!\n", 123);
    }

```


Cool! That's probably what I wanted to do! It seems that when looping 
inside a "static foreach" and taking the index, then I can compare it 
with a value that is not calculated at compile time. This way I can also 
check for the type of the variables and do my original plan which will 
make the function even better! Thanks a lot for the help dude!!!


The reason your original isn't working is that indexing a list of 
differently-typed things cannot be done using a runtime index.


I'd say that an inner function + static foreach + switch is the best way 
to convert from runtime to compile-time values. And in general, I would 
say having function templates that handle each arg type are usually 
conducive to clean and easy code.


But in the case you are suggesting, as long as you don't need to iterate 
them out of order, what you can do is foreach the args tuple, and do 
something like:


```d
foreach(arg; args)
{
   writeUpToNextDelimeter(prompt); // updates prompt to point at next 
delimiter

   processArg(arg, prompt);
}
```

-Steve


Re: FreeBSD 13 : wrong kernel version and size of kevent_t

2021-12-21 Thread rempas via Digitalmars-d-learn

On Tuesday, 21 December 2021 at 17:00:06 UTC, Johan wrote:


Please add which compiler(s) you have tried in the bug report.



Yeah, you are right! Please eugene use LDC2 and check confirm 
that the behavior is the same there.


I think the fix is needed here: 
https://github.com/dlang/dmd/blob/ad8412530e607ffebec36f2dbdff1a6f2798faf7/src/dmd/target.d#L362-L372




Yeah, I think it is very clear as there is no case for FreeBSD 
13. So probably this will be easily fixed


Re: FreeBSD 13 : wrong kernel version and size of kevent_t

2021-12-21 Thread Johan via Digitalmars-d-learn

On Tuesday, 21 December 2021 at 10:28:15 UTC, eugene wrote:

On Monday, 20 December 2021 at 21:19:43 UTC, rempas wrote:
I would recommend you to file an 
[issue](https://issues.dlang.org/) just so the developers 
themself can notice it.


filed an issue, see
https://issues.dlang.org/show_bug.cgi?id=22615


Please add which compiler(s) you have tried in the bug report.

I think the fix is needed here: 
https://github.com/dlang/dmd/blob/ad8412530e607ffebec36f2dbdff1a6f2798faf7/src/dmd/target.d#L362-L372


-Johan



Re: How to properly use variadic templates (functions)?

2021-12-21 Thread rempas via Digitalmars-d-learn

On Tuesday, 21 December 2021 at 15:42:59 UTC, russhy wrote:
Please keep us updated, that'll be interesting to see how a 
pure D printf would look like!


Glad someone is interested! I'm actually planning to make a whole 
library ;)


Check my 
[thread](https://forum.dlang.org/thread/frjbgaymuxjqperis...@forum.dlang.org) were I'm asking about your opinion on formatting and what is my current approach.


Re: FreeBSD 13 : wrong kernel version and size of kevent_t

2021-12-21 Thread rempas via Digitalmars-d-learn

On Tuesday, 21 December 2021 at 10:28:15 UTC, eugene wrote:


filed an issue, see
https://issues.dlang.org/show_bug.cgi?id=22615


Nice! Hope they see and fix it soon! Love for open source 
Operating Systems!!


Re: How to properly use variadic templates (functions)?

2021-12-21 Thread russhy via Digitalmars-d-learn
Please keep us updated, that'll be interesting to see how a pure 
D printf would look like!


Re: FreeBSD 13 : wrong kernel version and size of kevent_t

2021-12-21 Thread eugene via Digitalmars-d-learn

On Monday, 20 December 2021 at 21:19:43 UTC, rempas wrote:
I would recommend you to file an 
[issue](https://issues.dlang.org/) just so the developers 
themself can notice it.


filed an issue, see
https://issues.dlang.org/show_bug.cgi?id=22615



Re: How to properly use variadic templates (functions)?

2021-12-21 Thread rempas via Digitalmars-d-learn

On Tuesday, 21 December 2021 at 08:42:35 UTC, vit wrote:


You can use switch + static foreach:

```d
import std.stdio;

//this print args in reverse order:
void print(T...)(string prompt, T args)
{
void print_arg(size_t index){
switch(index){
static foreach(i, a; args){
case i:
// handle your other types
write(a);
return; 
}
default:
assert(0, "no impl");
}
}

write(prompt);
size_t len = args.length;
while(len --> 0)
print_arg(len);
}

void main(){
print("Prompt (ignored): ", "Hello", " world!\n", 123);
}

```


Cool! That's probably what I wanted to do! It seems that when 
looping inside a "static foreach" and taking the index, then I 
can compare it with a value that is not calculated at compile 
time. This way I can also check for the type of the variables and 
do my original plan which will make the function even better! 
Thanks a lot for the help dude!!!


Re: Thread exits immediately with no reason.

2021-12-21 Thread Dennis via Digitalmars-d-learn

On Tuesday, 21 December 2021 at 07:08:53 UTC, bauss wrote:
It should at the very least warn people about functions that 
may throw errors.


What is "It"? I was looking to make a spec PR, but it already 
says here:


https://dlang.org/spec/function.html#nothrow-functions

Nothrow functions can only throw exceptions derived from class 
Error.




Re: How to properly use variadic templates (functions)?

2021-12-21 Thread vit via Digitalmars-d-learn

On Tuesday, 21 December 2021 at 08:26:17 UTC, rempas wrote:

On Tuesday, 21 December 2021 at 08:11:39 UTC, Anonymouse wrote:


I'm not certain I understand, but won't `foreach (i, a; args) 
{ /* ... */ }` in his example do that?


As in, if you necessarily must index `args` instead of using a 
foreach variable,


```d
import core.stdc.stdio : putc, stdout;

void print(T...)(string prompt, T args)
{
foreach (i, a; args)
{
alias A = typeof(args[i]);

static if (is(A : string))
{
for (int j = 0; j < args[i].length; j++)
{
putc(args[i][j], stdout);
}
}
else
{
// handle your other types
print("", A.stringof);
}
}
}

void main()
{
print("Prompt (ignored)", "Hello", " world!\n", 123);
}
```


No it will not. I will try to explain it the best way I can. 
When I say I want to index args, I mean that I want to index 
and choose which argument to use rather than use them 
continuously one after another inside a `foreach`. For example 
check the following call:


`print("Hello %s!%c", "world", '\n');`

In that case I want to first print print from "H" up to (but 
not include) "%s". Then I want to print the first argument. 
After that, I want to print the '!' character and then I want 
to print the second argument. So I need a way to keep track 
which argument was the last one I printed and manually choose 
which argument to use. So `foreach` will not do in that case 
because I don't want to continuously use the arguments one 
after another. Is is more clear now? "writef" exists in phobos 
so I'm pretty sure that there is a way to do that.


You can use switch + static foreach:

```d
import std.stdio;

//this print args in reverse order:
void print(T...)(string prompt, T args)
{
void print_arg(size_t index){
switch(index){
static foreach(i, a; args){
case i:
// handle your other types
write(a);
return; 
}
default:
assert(0, "no impl");
}
}

write(prompt);
size_t len = args.length;
while(len --> 0)
print_arg(len);
}

void main(){
print("Prompt (ignored): ", "Hello", " world!\n", 123);
}

```


Re: How to properly use variadic templates (functions)?

2021-12-21 Thread rempas via Digitalmars-d-learn

On Tuesday, 21 December 2021 at 08:11:39 UTC, Anonymouse wrote:


I'm not certain I understand, but won't `foreach (i, a; args) { 
/* ... */ }` in his example do that?


As in, if you necessarily must index `args` instead of using a 
foreach variable,


```d
import core.stdc.stdio : putc, stdout;

void print(T...)(string prompt, T args)
{
foreach (i, a; args)
{
alias A = typeof(args[i]);

static if (is(A : string))
{
for (int j = 0; j < args[i].length; j++)
{
putc(args[i][j], stdout);
}
}
else
{
// handle your other types
print("", A.stringof);
}
}
}

void main()
{
print("Prompt (ignored)", "Hello", " world!\n", 123);
}
```


No it will not. I will try to explain it the best way I can. When 
I say I want to index args, I mean that I want to index and 
choose which argument to use rather than use them continuously 
one after another inside a `foreach`. For example check the 
following call:


`print("Hello %s!%c", "world", '\n');`

In that case I want to first print print from "H" up to (but not 
include) "%s". Then I want to print the first argument. After 
that, I want to print the '!' character and then I want to print 
the second argument. So I need a way to keep track which argument 
was the last one I printed and manually choose which argument to 
use. So `foreach` will not do in that case because I don't want 
to continuously use the arguments one after another. Is is more 
clear now? "writef" exists in phobos so I'm pretty sure that 
there is a way to do that.


Re: How to properly use variadic templates (functions)?

2021-12-21 Thread Anonymouse via Digitalmars-d-learn

On Tuesday, 21 December 2021 at 06:44:36 UTC, rempas wrote:
This will not do for me because I want to do formatted output 
and I need the index. But thanks a lot for tying to help!


I'm not certain I understand, but won't `foreach (i, a; args) { 
/* ... */ }` in his example do that?


As in, if you necessarily must index `args` instead of using a 
foreach variable,


```d
import core.stdc.stdio : putc, stdout;

void print(T...)(string prompt, T args)
{
foreach (i, a; args)
{
alias A = typeof(args[i]);

static if (is(A : string))
{
for (int j = 0; j < args[i].length; j++)
{
putc(args[i][j], stdout);
}
}
else
{
// handle your other types
print("", A.stringof);
}
}
}

void main()
{
print("Prompt (ignored)", "Hello", " world!\n", 123);
}
```