Re: GC seems to crash my C-code function

2021-09-16 Thread frame via Digitalmars-d-learn
On Thursday, 16 September 2021 at 18:02:44 UTC, Steven Schveighoffer wrote: Are you sure? Be very pedantic about what C functions do with the data you send it. Sometimes they store it somewhere to use later. Sometimes they expect it to be allocated by the C heap, etc. Without seeing how you

Re: Merge 2 structs together (into a single struct)?

2021-09-16 Thread jfondren via Digitalmars-d-learn
On Friday, 17 September 2021 at 05:01:36 UTC, james.p.leblanc wrote: Again, thanks to you and many of the D community with helping to learn and appreciate the capabilities of D. It is nice to be here. Yeah. The improved joinStruct is nice enough that I think it's probably a good thing to do.

Re: Merge 2 structs together (into a single struct)?

2021-09-16 Thread james.p.leblanc via Digitalmars-d-learn
On Friday, 17 September 2021 at 00:36:42 UTC, ag0aep6g wrote: On 16.09.21 22:53, jfondren wrote: string joinstruct(A, B)(string name) { struct JoinStruct(Structs ...) { static foreach (S; Structs) { static foreach (i, alias f; S.tupleof) { mixin("typeof(f) "

Re: Merge 2 structs together (into a single struct)?

2021-09-16 Thread ag0aep6g via Digitalmars-d-learn
On 16.09.21 22:53, jfondren wrote: string joinstruct(A, B)(string name) {     string s = "struct " ~ name ~ " {";     alias memA = __traits(allMembers, A);     alias memB = __traits(allMembers, B);     alias initA = A.init.tupleof;     alias initB = B.init.tupleof;     static foreach (i; 0

Re: dub segfault and range error handling

2021-09-16 Thread jfondren via Digitalmars-d-learn
On Thursday, 16 September 2021 at 20:49:28 UTC, seany wrote: I compile with : `dub build -b release --compiler=ldc2` The result executing the compiled binary 'myproj' is is ( whether `writeln (a[1])` is uncommented, or the `test()` function is uncommented) some random number, usually negativ

Re: What is the meaning of @future ?

2021-09-16 Thread Stefan Koch via Digitalmars-d-learn
On Thursday, 16 September 2021 at 20:53:34 UTC, Elmar wrote: Hello D community. I was browsing the `__traits` keywords and I found `isFuture` whose descriptions says something about `@future`-annotated variables. [link](https://dlang.org/spec/traits.html#isFuture) I didn't find anything abo

What is the meaning of @future ?

2021-09-16 Thread Elmar via Digitalmars-d-learn
Hello D community. I was browsing the `__traits` keywords and I found `isFuture` whose descriptions says something about `@future`-annotated variables. [link](https://dlang.org/spec/traits.html#isFuture) I didn't find anything about `@future` for the D programming language. I only found tha

Re: Merge 2 structs together (into a single struct)?

2021-09-16 Thread jfondren via Digitalmars-d-learn
On Thursday, 16 September 2021 at 20:12:03 UTC, james.p.leblanc wrote: Is there some obvious, and simple solution to this conundrum of mine? I would consider AAs. ```d struct A { int alpha; float x = 1.23; } struct B { int beta; float y = 4.4; string s = "this is fine."; }

Re: dub segfault and range error handling

2021-09-16 Thread seany via Digitalmars-d-learn
On Thursday, 16 September 2021 at 20:49:28 UTC, seany wrote: I create a new project with : `dub init myproj`. Then I change the source/app.d file with this : [...] PS :compiling with : `dub build -b release ` ( i.e. no ldc2) is a direct segfault of the code posted above. PPS : my system is

Re: Merge 2 structs together (into a single struct)?

2021-09-16 Thread Ali Çehreli via Digitalmars-d-learn
On 9/16/21 1:12 PM, james.p.leblanc wrote: > I really thought that this would be a simple enough > small project in meta programming/reflection. It should be doable. One question is how to resolve conflicting members of the two structs, which can be defaulted to one of the policies "cause comp

dub segfault and range error handling

2021-09-16 Thread seany via Digitalmars-d-learn
I create a new project with : `dub init myproj`. Then I change the source/app.d file with this : ` import std.stdio; import std.math; import std.stdio; import std.conv; import std.format; import std.math; import std.algorithm;

Re: Array permutations

2021-09-16 Thread Elmar via Digitalmars-d-learn
I also should discourage its current form with large `tupleSize`s. The computation is in O(exp(values.length)). Instead of `~=` I would suggest an `std.array.appender` of arrays instead of an 2D-array for the `choices`, if the `choices` become large. Most efficient is a preallocated array capac

Merge 2 structs together (into a single struct)?

2021-09-16 Thread james.p.leblanc via Digitalmars-d-learn
Dear All, I really thought that this would be a simple enough small project in meta programming/reflection. Consisely, merge two structures, which are coming from two different elements of the code base. (One contains standard input options for getopt, and the other is for user customization fo

Re: Array permutations

2021-09-16 Thread Elmar via Digitalmars-d-learn
On Saturday, 11 September 2021 at 19:37:42 UTC, Vino wrote: Hi All, Request your help on the below to print the below array as "Required output", Was able to get these values "[1,2],[2,3],[3,4],[4,5]" by using list.slide(2), need your help to get values "1,3],[1,4],[1,5],[2,4],[2,5],[3,5]"

Re: GC seems to crash my C-code function

2021-09-16 Thread Steven Schveighoffer via Digitalmars-d-learn
On 9/16/21 1:08 PM, frame wrote: On Thursday, 16 September 2021 at 15:34:25 UTC, Steven Schveighoffer wrote: `dup` is a GC allocation. Are you using that in your C code? the GC might be collecting that string. The compiler doesn't show that lines with -vgc. Maybe it knows that it is only sta

Re: GC seems to crash my C-code function

2021-09-16 Thread frame via Digitalmars-d-learn
On Thursday, 16 September 2021 at 15:34:25 UTC, Steven Schveighoffer wrote: `dup` is a GC allocation. Are you using that in your C code? the GC might be collecting that string. The compiler doesn't show that lines with -vgc. Maybe it knows that it is only stack allocated? Technically, the

Re: GC seems to crash my C-code function

2021-09-16 Thread Steven Schveighoffer via Digitalmars-d-learn
On 9/16/21 6:28 AM, frame wrote: I have C-code translated in D that acts sometimes incorrect if the GC has made some collect. I would like to know why. - Code runs correct if the GC collections are off - There are no allocations within the C-translated-code except `throw new` (but they are not

Re: GC seems to crash my C-code function

2021-09-16 Thread bauss via Digitalmars-d-learn
On Thursday, 16 September 2021 at 11:35:27 UTC, frame wrote: On Thursday, 16 September 2021 at 11:11:56 UTC, bauss wrote: On Thursday, 16 September 2021 at 11:06:04 UTC, frame wrote: On Thursday, 16 September 2021 at 10:48:19 UTC, bauss wrote: Use toStringz and not .ptr. Or append \0 to you

Re: GC seems to crash my C-code function

2021-09-16 Thread frame via Digitalmars-d-learn
On Thursday, 16 September 2021 at 11:11:56 UTC, bauss wrote: On Thursday, 16 September 2021 at 11:06:04 UTC, frame wrote: On Thursday, 16 September 2021 at 10:48:19 UTC, bauss wrote: Use toStringz and not .ptr. Or append \0 to your string. Stupid me should really know that already, thanks

Re: GC seems to crash my C-code function

2021-09-16 Thread bauss via Digitalmars-d-learn
On Thursday, 16 September 2021 at 11:06:04 UTC, frame wrote: On Thursday, 16 September 2021 at 10:48:19 UTC, bauss wrote: Use toStringz and not .ptr. Or append \0 to your string. Stupid me should really know that already, thanks =) Of course I have dup'ed the \0 from the string away... But

Re: GC seems to crash my C-code function

2021-09-16 Thread frame via Digitalmars-d-learn
On Thursday, 16 September 2021 at 10:48:19 UTC, bauss wrote: Use toStringz and not .ptr. Or append \0 to your string. Stupid me should really know that already, thanks =) Of course I have dup'ed the \0 from the string away... But still I don't know why it works if the GC is off?

Re: GC seems to crash my C-code function

2021-09-16 Thread bauss via Digitalmars-d-learn
On Thursday, 16 September 2021 at 10:48:19 UTC, bauss wrote: On Thursday, 16 September 2021 at 10:28:37 UTC, frame wrote: I have C-code translated in D that acts sometimes incorrect if the GC has made some collect. I would like to know why. - Code runs correct if the GC collections are off - T

Re: GC seems to crash my C-code function

2021-09-16 Thread bauss via Digitalmars-d-learn
On Thursday, 16 September 2021 at 10:28:37 UTC, frame wrote: I have C-code translated in D that acts sometimes incorrect if the GC has made some collect. I would like to know why. - Code runs correct if the GC collections are off - There are no allocations within the C-translated-code except `

GC seems to crash my C-code function

2021-09-16 Thread frame via Digitalmars-d-learn
I have C-code translated in D that acts sometimes incorrect if the GC has made some collect. I would like to know why. - Code runs correct if the GC collections are off - There are no allocations within the C-translated-code except `throw new` (but they are not called) - All allocations made in