Re: how to pass a malloc'd C string over to be managed by the GC

2019-02-27 Thread evilrat via Digitalmars-d-learn
On Thursday, 28 February 2019 at 04:26:47 UTC, Sam Johnson wrote: Update: it seems that all I need to do is GC.addRoot(output); and memory leak goes away. I think I have answered my own question. If you know what you are doing. Otherwise you just postpone troubles due to mixed

Re: how to pass a malloc'd C string over to be managed by the GC

2019-02-27 Thread Nicholas Wilson via Digitalmars-d-learn
On Thursday, 28 February 2019 at 03:33:25 UTC, Sam Johnson wrote: ``` string snappyCompress(const string plaintext) { import deimos.snappy.snappy : snappy_compress, snappy_max_compressed_length, SNAPPY_OK; import core.stdc.stdlib : malloc, free; import std.string :

Re: how to pass a malloc'd C string over to be managed by the GC

2019-02-27 Thread Adam D. Ruppe via Digitalmars-d-learn
On Thursday, 28 February 2019 at 03:33:25 UTC, Sam Johnson wrote: How can I get the GC to automatically garbage collect the `output` malloc call by tracking the returned `ret` reference? If you want it GC managed, just GC allocate it instead of mallocing it. char *output = cast(char *)

Re: how to pass a malloc'd C string over to be managed by the GC

2019-02-27 Thread Adam D. Ruppe via Digitalmars-d-learn
On Thursday, 28 February 2019 at 04:26:47 UTC, Sam Johnson wrote: Update: it seems that all I need to do is GC.addRoot(output); and memory leak goes away. I think I have answered my own question. That shouldn't have any effect at all. GC.addRoot makes the GC consider that pointer to always

Re: how to pass a malloc'd C string over to be managed by the GC

2019-02-27 Thread Adam D. Ruppe via Digitalmars-d-learn
On Thursday, 28 February 2019 at 03:35:45 UTC, Sam Johnson wrote: Ignore the `.clone()` call -- that wasn't supposed to be here -- I thought maybe string.clone() might exist but it turns out it does not. It is called `.dup` ( for a mutable copy) or `.idup` (for an immutable copy). Though

Re: how to pass a malloc'd C string over to be managed by the GC

2019-02-27 Thread Sam Johnson via Digitalmars-d-learn
On Thursday, 28 February 2019 at 03:35:45 UTC, Sam Johnson wrote: On Thursday, 28 February 2019 at 03:33:25 UTC, Sam Johnson wrote: [...] Ignore the `.clone()` call -- that wasn't supposed to be here -- I thought maybe string.clone() might exist but it turns out it does not. Update: it

Re: how to pass a malloc'd C string over to be managed by the GC

2019-02-27 Thread Sam Johnson via Digitalmars-d-learn
On Thursday, 28 February 2019 at 03:33:25 UTC, Sam Johnson wrote: ``` string snappyCompress(const string plaintext) { import deimos.snappy.snappy : snappy_compress, snappy_max_compressed_length, SNAPPY_OK; import core.stdc.stdlib : malloc, free; import std.string :

how to pass a malloc'd C string over to be managed by the GC

2019-02-27 Thread Sam Johnson via Digitalmars-d-learn
``` string snappyCompress(const string plaintext) { import deimos.snappy.snappy : snappy_compress, snappy_max_compressed_length, SNAPPY_OK; import core.stdc.stdlib : malloc, free; import std.string : fromStringz, toStringz; char *input = cast(char *)

Re: dcompute - Error: unrecognized `pragma(LDC_intrinsic)

2019-02-27 Thread Nicholas Wilson via Digitalmars-d-learn
On Wednesday, 27 February 2019 at 22:56:14 UTC, Michelle Long wrote: Trying to get dcompute to work... after a bunch of issues dealing with all the crap this is what I can't get past: Error: unrecognized `pragma(LDC_intrinsic) This is actually from the ldc.intrinsics file, which I had to

dcompute - Error: unrecognized `pragma(LDC_intrinsic)

2019-02-27 Thread Michelle Long via Digitalmars-d-learn
Trying to get dcompute to work... after a bunch of issues dealing with all the crap this is what I can't get past: Error: unrecognized `pragma(LDC_intrinsic) This is actually from the ldc.intrinsics file, which I had to rename from .di to d so it would be included in by VisualD. I upgraded

Re: My template tuple code does not compile

2019-02-27 Thread Victor Porton via Digitalmars-d-learn
I rewrote it again: https://github.com/vporton/struct-params-dlang/blob/f50f7e5919f90b1d06bf0cc08e3055548aad1797/source/struct_params.d But it does not work :-( What is my error? source/struct_params.d(43,60): Error: function expected before `()`, not `()` of type `()`

Re: How to attach function attributes to delegate type?

2019-02-27 Thread Alex via Digitalmars-d-learn
On Wednesday, 27 February 2019 at 20:03:15 UTC, Q. Schroll wrote: For any type constructors like const, I can use ConstOf!T to get `T` with const attached. For a delegate/function type DG, e.g. int delegate(int), how can I get the @safe version of that type, i.e. int delegate(int) @safe? I

How to attach function attributes to delegate type?

2019-02-27 Thread Q. Schroll via Digitalmars-d-learn
For any type constructors like const, I can use ConstOf!T to get `T` with const attached. For a delegate/function type DG, e.g. int delegate(int), how can I get the @safe version of that type, i.e. int delegate(int) @safe? I tried alias SafeOf(DG) = DG @safe; but it didn't compile. The

Re: My template tuple code does not compile

2019-02-27 Thread Q. Schroll via Digitalmars-d-learn
On Wednesday, 27 February 2019 at 03:53:35 UTC, Victor Porton wrote: After following your suggestion to rewrite it with Stride it does not work either. I assume the error is somehow related to allSatisfy!.

Re: Why is my @pure function @system when placed in a struct?

2019-02-27 Thread ag0aep6g via Digitalmars-d-learn
On 27.02.19 19:10, Dukc wrote: I tested a bit, and it appears that attribute inference is not done at all for templates inside structs -the attribute need not be a delegate: struct S     {     static int fImpl(Ret)() { return Ret.init; }     pragma(msg,

Re: Why is my @pure function @system when placed in a struct?

2019-02-27 Thread Dukc via Digitalmars-d-learn
On Wednesday, 27 February 2019 at 17:23:21 UTC, Q. Schroll wrote: For whatever reason, when I put the code in a struct, the @safe testing line tells me, it's @system now. I tested a bit, and it appears that attribute inference is not done at all for templates inside structs -the attribute

Re: Why is my @pure function @system when placed in a struct?

2019-02-27 Thread Dukc via Digitalmars-d-learn
On Wednesday, 27 February 2019 at 18:06:49 UTC, Stefan Koch wrote: the struct gets drawn into your delegate-context. and I guess that taints the function. Even if it did, it should not make the delegate @system. And it does not, since this manifest with static functions and function

Re: Why is my @pure function @system when placed in a struct?

2019-02-27 Thread Stefan Koch via Digitalmars-d-learn
On Wednesday, 27 February 2019 at 17:23:21 UTC, Q. Schroll wrote: I have a template function `fImpl` I whish to instantiate manually using the new name `f`. Reason is simple: `f` should not be a template, but overloading it makes it easier that way. Nothing's more simple in D: [...] the

Why is my @pure function @system when placed in a struct?

2019-02-27 Thread Q. Schroll via Digitalmars-d-learn
I have a template function `fImpl` I whish to instantiate manually using the new name `f`. Reason is simple: `f` should not be a template, but overloading it makes it easier that way. Nothing's more simple in D: int fImpl(T)(T value) { return cast(int) value; } alias f = fImpl!int;

Re: How to enumerate a sequence?

2019-02-27 Thread Simen Kjærås via Digitalmars-d-learn
On Wednesday, 27 February 2019 at 13:15:06 UTC, Victor Porton wrote: .enumerate does not work for compile-time sequences. Consider for the sake of discussion the following nonsense (I know it cannot be done without enumerate) code: import std.meta; import std.range; string join(Fields...)()

Re: How to enumerate a sequence?

2019-02-27 Thread Victor Porton via Digitalmars-d-learn
On Wednesday, 27 February 2019 at 13:15:06 UTC, Victor Porton wrote: .enumerate does not work for compile-time sequences. Consider for the sake of discussion the following nonsense (I know it cannot be done without enumerate) code: I want namely integer (or size_t) index!

How to enumerate a sequence?

2019-02-27 Thread Victor Porton via Digitalmars-d-learn
.enumerate does not work for compile-time sequences. Consider for the sake of discussion the following nonsense (I know it cannot be done without enumerate) code: import std.meta; import std.range; string join(Fields...)() { enum f(size_t i) = __traits(identifier, Fields[i]); return

Re: Disable dub from checking internet before building

2019-02-27 Thread 0xFFFFFFFF via Digitalmars-d-learn
On Monday, 25 February 2019 at 18:54:03 UTC, Jacob Carlborg wrote: On 2019-02-24 23:51, 0x wrote: How to disable dub from checking internet before building, it's slowing down build whenever it does this. I thought that was fixed [1]. Or is it doing something else? [1]

Re: Few questions about staticMap

2019-02-27 Thread Simen Kjærås via Digitalmars-d-learn
On Tuesday, 26 February 2019 at 18:50:39 UTC, Mitacha wrote: Hi everyone, I checked, just out of curiosity, what is staticMap's implementation. It's implemented using recursive, this made me think if there is way to use static foreach instead. I came out with following solution:

Re: My template tuple code does not compile

2019-02-27 Thread Simen Kjærås via Digitalmars-d-learn
On Wednesday, 27 February 2019 at 03:53:35 UTC, Victor Porton wrote: After following your suggestion to rewrite it with Stride it does not work either. I assume the error is somehow related to allSatisfy!.