Re: How to implement Canceleable spawn() from parent

2020-07-01 Thread aberba via Digitalmars-d-learn
On Tuesday, 30 June 2020 at 14:43:40 UTC, Steven Schveighoffer wrote: On 6/30/20 10:15 AM, Simen Kjærås wrote: [...] My thinking is I don't want regular consumers using the package to think about the technicality of thread_joinAll() at all. Thinking about putting it in a mixin like: mixin

Re: How to implement Canceleable spawn() from parent

2020-07-01 Thread Ali Çehreli via Digitalmars-d-learn
On 7/1/20 2:41 AM, aberba wrote: On Tuesday, 30 June 2020 at 14:43:40 UTC, Steven Schveighoffer wrote: On 6/30/20 10:15 AM, Simen Kjærås wrote: [...] My thinking is I don't want regular consumers using the package to think about the technicality of thread_joinAll() at all. Thinking about

Re: Why is this allowed

2020-07-01 Thread psycha0s via Digitalmars-d-learn
On Tuesday, 30 June 2020 at 16:22:57 UTC, JN wrote: Why does such code compile? I don't think this should be permitted, because it's easy to make a mistake (when you wanted foo[index] but forgot the []). If someone wants to assign a value to every element they could do foo[] = 5; instead which

Re: idiomatic output given -preview=nosharedaccess ,

2020-07-01 Thread Bruce Carneal via Digitalmars-d-learn
On Tuesday, 30 June 2020 at 20:43:00 UTC, Bruce Carneal wrote: On Tuesday, 30 June 2020 at 20:12:59 UTC, Stanislav Blinov wrote: On Tuesday, 30 June 2020 at 20:04:33 UTC, Steven Schveighoffer wrote: The answer is -- update Phobos so it works with -nosharedaccess :) Yeah... and dip1000. And

Re: Why is this allowed

2020-07-01 Thread Steven Schveighoffer via Digitalmars-d-learn
On 7/1/20 11:57 AM, Nathan S. wrote: On Tuesday, 30 June 2020 at 16:22:57 UTC, JN wrote: Spent some time debugging because I didn't notice it at first, essentially something like this: int[3] foo = [1, 2, 3]; foo = 5; writeln(foo);   // 5, 5, 5 Why does such code compile? I don't think this

Re: Why is this allowed

2020-07-01 Thread Nathan S. via Digitalmars-d-learn
On Tuesday, 30 June 2020 at 16:22:57 UTC, JN wrote: Spent some time debugging because I didn't notice it at first, essentially something like this: int[3] foo = [1, 2, 3]; foo = 5; writeln(foo); // 5, 5, 5 Why does such code compile? I don't think this should be permitted, because it's

Re: Why is this allowed

2020-07-01 Thread tsbockman via Digitalmars-d-learn
On Tuesday, 30 June 2020 at 16:36:45 UTC, H. S. Teoh wrote: And on that note, this implicit static -> dynamic array conversion is seriously a nasty misfeature that ought to be killed with fire. It leads to bugs like this: struct Database { int[] data;

Re: Why is this allowed

2020-07-01 Thread tsbockman via Digitalmars-d-learn
On Wednesday, 1 July 2020 at 20:05:51 UTC, tsbockman wrote: If you want the compiler to stop you from accidentally keeping references to stack variables past the end of their scope, you need to annotate your functions @safe and compile with -preview=dip1000: https://run.dlang.io/is/3VdDaN

Re: Print only part of a stack trace

2020-07-01 Thread Stanislav Blinov via Digitalmars-d-learn
On Wednesday, 1 July 2020 at 18:30:15 UTC, Dennis wrote: I have a function that checks a global error constant of a C library (OpenGL) like this: ``` void assertNoOpenGLErrors() { if (glGetError() != GL_NO_ERROR) { assert(0); // stack trace points to here instead of caller }

Re: Print only part of a stack trace

2020-07-01 Thread Adam D. Ruppe via Digitalmars-d-learn
On Wednesday, 1 July 2020 at 17:44:45 UTC, Dennis wrote: On assertion failure, the default error handler prints a stack trace that looks like this My cgi.d does something just like that. It just does `exception.toString()` then `splitLines` on that string. Element

Re: Print only part of a stack trace

2020-07-01 Thread Dennis via Digitalmars-d-learn
On Wednesday, 1 July 2020 at 18:44:10 UTC, Stanislav Blinov wrote: void assertNoOpenGLErrors(string file = __FILE__, int line = __LINE__, string func = __PRETTY_FUNCTION__) { if (glGetError() != GL_NO_ERROR) { print(file, ":", line, ":", func, ": blah"); exit(); } } :)

Re: Print only part of a stack trace

2020-07-01 Thread Dennis via Digitalmars-d-learn
On Wednesday, 1 July 2020 at 18:54:55 UTC, Dennis wrote: It sort of works, but it seems it does not start at the right stack frame, the top item is this: ??:? void rt.dmain2._d_run_main2(char[][], ulong, extern (C) int function(char[][])*).runAll().__lambda1() [0x55c19a09c1fa] So dmd skips

Re: Print only part of a stack trace

2020-07-01 Thread Dennis via Digitalmars-d-learn
On Wednesday, 1 July 2020 at 18:05:09 UTC, Jacob Carlborg wrote: [1] https://dlang.org/phobos/core_runtime.html#.Runtime.traceHandler Thanks, but I don't want to re-implement the default trace handler, I want to use it on a specific location and capture its output. I'll be more specific in

Re: Why is this allowed

2020-07-01 Thread JN via Digitalmars-d-learn
On Wednesday, 1 July 2020 at 15:57:24 UTC, Nathan S. wrote: On Tuesday, 30 June 2020 at 16:22:57 UTC, JN wrote: Spent some time debugging because I didn't notice it at first, essentially something like this: int[3] foo = [1, 2, 3]; foo = 5; writeln(foo); // 5, 5, 5 Why does such code

Re: Print only part of a stack trace

2020-07-01 Thread Dennis via Digitalmars-d-learn
On Wednesday, 1 July 2020 at 19:33:08 UTC, JN wrote: Bit off-topic, but if you can use them, debug contexts offer much better OpenGL error-checking experience. https://www.khronos.org/opengl/wiki/Debug_Output . Instead of checking glGetError() after each call, you can setup a C callback that

Re: Print only part of a stack trace

2020-07-01 Thread Jacob Carlborg via Digitalmars-d-learn
On 2020-07-01 19:44, Dennis wrote: On assertion failure, the default error handler prints a stack trace that looks like this [library functions] [application functions] [druntime start-up functions] I'm only interested in application functions, the rest is noise. I could easily filter

Re: Print only part of a stack trace

2020-07-01 Thread JN via Digitalmars-d-learn
On Wednesday, 1 July 2020 at 18:30:15 UTC, Dennis wrote: I have a function that checks a global error constant of a C library (OpenGL) like this: ``` void assertNoOpenGLErrors() { if (glGetError() != GL_NO_ERROR) { assert(0); // stack trace points to here instead of caller } }

Re: Program exited with code -11 when calling

2020-07-01 Thread Anthony via Digitalmars-d-learn
On Wednesday, 1 July 2020 at 05:47:16 UTC, Anthony wrote: On Wednesday, 1 July 2020 at 05:33:48 UTC, H. S. Teoh wrote: On Wed, Jul 01, 2020 at 05:04:28AM +, Anthony via Digitalmars-d-learn wrote: [...] auto str_utf8 = str.toUTF8(); bson_error_t error auto bson =

Re: scope guard question

2020-07-01 Thread Simen Kjærås via Digitalmars-d-learn
On Tuesday, 30 June 2020 at 12:18:14 UTC, Steven Schveighoffer wrote: I can see where it would be confusing, and it could probably contain an example and clarification. https://issues.dlang.org/show_bug.cgi?id=20997

Print only part of a stack trace

2020-07-01 Thread Dennis via Digitalmars-d-learn
On assertion failure, the default error handler prints a stack trace that looks like this [library functions] [application functions] [druntime start-up functions] I'm only interested in application functions, the rest is noise. I could easily filter unwanted lines out if I had the stack trace

Generating struct members from c structs

2020-07-01 Thread Anthony via Digitalmars-d-learn
When doing interop with a c library, is there a way to automatically generate the fields that are needed for a struct? For example, when interfacing with the lwan c library: // lwan.h struct lwan { struct lwan_trie url_map_trie; struct lwan_connection *conns; struct lwan_strbuf

Progress printing with threads?

2020-07-01 Thread AB via Digitalmars-d-learn
Hello. I am unsure how to proceed about printing progress in my program. Suppose the program is processing a very big file and is iterating the file's bytes using a for loop. The processing takes several minutes and I want a progress percentage be printed every 2 seconds in this manner:

Re: Generating struct members from c structs

2020-07-01 Thread Simen Kjærås via Digitalmars-d-learn
On Wednesday, 1 July 2020 at 07:26:44 UTC, Anthony wrote: When doing interop with a c library, is there a way to automatically generate the fields that are needed for a struct? [snip] Is there an easier way though? Dstep is probably what you're looking for:

Re: Progress printing with threads?

2020-07-01 Thread Stanislav Blinov via Digitalmars-d-learn
On Wednesday, 1 July 2020 at 07:52:28 UTC, AB wrote: Hello. I am unsure how to proceed about printing progress in my program. Is it a good idea to std.concurrency.spawn a new thread?.. This example code shows my situation: MmFile input = new MmFile(/* ... */); ulong fileSize

Re: Progress printing with threads?

2020-07-01 Thread Simen Kjærås via Digitalmars-d-learn
On Wednesday, 1 July 2020 at 07:52:28 UTC, AB wrote: Hello. I am unsure how to proceed about printing progress in my program. Suppose the program is processing a very big file and is iterating the file's bytes using a for loop. The processing takes several minutes and I want a progress