Re: How to create dynamically sized objects
On Thursday, 29 September 2016 at 07:10:44 UTC, Straivers wrote: Hi, Say I wanted to create an object that has a string member, and I want the string to be allocated with the object contiguously instead of as a pointer to another location (as a constructor would do). For example: class C { this(int i, string s) { this.i = i; this.s = s.toUTF16z(); } int i; wstring s; } I want to allocate memory such that it looks like this: [32-bit int][s.length * wchar.sizeof bytes] I've considered using a separate function to create the class, but I don't know how setting the length of the string would behave. The only solution I can think of would be to have a constructor like this: this(int i, string s, void[] mem) { emplace!int(mem.ptr, i); auto t = cast(dchar[]) mem[int.sizeof .. $]; this.s.fill(s.byDChar()) } Is there a better way to do this? struct Foo { uint length; wchar[0] str; //this is the equivalent of wchar_t[] in C. i.e variable length. } auto newFoo(wstring s) { auto fooMem = new ubyte[ unit.sizeof + wchar.sizeof*s.length];// you may need trailing '\0' if you are trying to interoperate with C. auto ret = cast(Foo*) fooMem; ret.length = s.length; memcpy(,s.ptr, wchar.sizeof*s.length); return ret; }
Re: Reinstalled Mac
On Thursday, 29 September 2016 at 11:43:32 UTC, Jacob Carlborg wrote: Cool, what if I want to use different versions in different sessions, i.e. I have two tabs open in my terminal? Ummm... All the installed stuff is pretty well organised inside `/usr/local`, so this works... --- hw0062:~ pinver$ /usr/local/Cellar/dmd/2.071.2/bin/dmd --version DMD64 D Compiler v2.071.2 Copyright (c) 1999-2015 by Digital Mars written by Walter Bright hw0062:~ pinver$ /usr/local/Cellar/dmd/2.071./bin/dmd --version 2.071.0_1/ 2.071.1/ 2.071.2/ hw0062:~ pinver$ /usr/local/Cellar/dmd/2.071.0_1/bin/dmd --version DMD64 D Compiler v2.071.0 Copyright (c) 1999-2015 by Digital Mars written by Walter Bright --- /Paolo
Re: Reinstalled Mac
On Thursday, 29 September 2016 at 06:24:08 UTC, Jacob Carlborg wrote: On 2016-09-29 03:43, David Nadlinger wrote: Jacob is also the author of DVM, so he might be a bit biased. ;) And you would never recommend LDC? ;) More or less related: it would be nice if DVM supports LDC fetching and switching. The use case I see is that you often want one DMD and one LDC.
Re: Learning ddoc
On Thursday, 29 September 2016 at 11:50:26 UTC, bachmeier wrote: On Thursday, 29 September 2016 at 09:35:56 UTC, Antonio Corbi wrote: [...] They used https://github.com/economicmodeling/harbored Thanks! that's it. Antonio
Re: Learning ddoc
On Thursday, 29 September 2016 at 09:35:56 UTC, Antonio Corbi wrote: Hi, I'm in the process of learning how ddoc works. I've successfully created docs for my code and recently learned how to generate it using dub. Related to this and after seeing the announcement of the new release of the emsi-containers library, I had a look at its docs (http://economicmodeling.github.io/containers/index.html) but when I cloned the repo and generated it locally its appearance is completely different (no side-bar, different formatting for code examples, etc...), it's simpler, it must lack some css or whatever. My question is...is there some standard way to generate better-looking doc-pages with ddoc? Thanks! Antonio They used https://github.com/economicmodeling/harbored
Re: Learning ddoc
On 2016-09-29 11:35, Antonio Corbi wrote: Hi, I'm in the process of learning how ddoc works. I've successfully created docs for my code and recently learned how to generate it using dub. Related to this and after seeing the announcement of the new release of the emsi-containers library, I had a look at its docs (http://economicmodeling.github.io/containers/index.html) but when I cloned the repo and generated it locally its appearance is completely different (no side-bar, different formatting for code examples, etc...), it's simpler, it must lack some css or whatever. My question is...is there some standard way to generate better-looking doc-pages with ddoc? I'm pretty sure it's using a non standard Ddoc generator. I know there are several out there, you can have a look here [1] [1] http://code.dlang.org/ -- /Jacob Carlborg
Re: Reinstalled Mac
On 2016-09-29 10:29, Paolo Invernizzi wrote: It seems simple: --- hw0062:~ pinver$ brew info dmd dmd: stable 2.071.2 (bottled), HEAD D programming language compiler for OS X https://dlang.org/ /usr/local/Cellar/dmd/2.071.0_1 (561 files, 65.0M) Poured from bottle on 2016-06-23 at 14:51:10 /usr/local/Cellar/dmd/2.071.1 (561 files, 65.0M) Poured from bottle on 2016-07-06 at 09:48:40 /usr/local/Cellar/dmd/2.071.2 (561 files, 65.0M) * Poured from bottle on 2016-09-26 at 11:50:45 From: https://github.com/Homebrew/homebrew-core/blob/master/Formula/dmd.rb hw0062:~ pinver$ dmd --version DMD64 D Compiler v2.071.2 Copyright (c) 1999-2015 by Digital Mars written by Walter Bright hw0062:~ pinver$ brew switch dmd 2.071.0_1 Cleaning /usr/local/Cellar/dmd/2.071.0_1 Cleaning /usr/local/Cellar/dmd/2.071.1 Cleaning /usr/local/Cellar/dmd/2.071.2 13 links created for /usr/local/Cellar/dmd/2.071.0_1 hw0062:~ pinver$ dmd --version DMD64 D Compiler v2.071.0 Copyright (c) 1999-2015 by Digital Mars written by Walter Bright --- Cool, what if I want to use different versions in different sessions, i.e. I have two tabs open in my terminal? -- /Jacob Carlborg
Re: Proper way to work around `Invalid memory operation`?
On Sunday, 25 September 2016 at 16:07:12 UTC, Matthias Klumpp wrote: Hello! I have a class similar to this one: ``` class Dummy { private: string tmpDir; public: this (string fname) { tmpDir = buildPath ("/tmp", fname.baseName); std.file.mkdirRecurse (tmpDir); } ~this () { close (); } void close () { if (std.file.exists (tmpDir)) std.file.rmdirRecurse (tmpDir); } } ``` Another problem here is that tmpDir is GC-allocated, but by the time the constructor is called the string can be already collected, you can't read it. A possible solution would be to have a service which you would notify to delete the folder.
Re: How to debug (potential) GC bugs?
Does it crash only in rt_finalize2? It calls the class destructor, and the destructor must not allocate or touch GC in any way because the GC doesn't yet support allocation during collection.
struct to json/yaml/xml/whatever codegen
Is anyone aware of a tool which does something akin to the following: Given a C-like definition, automatically generate pure C code with no dependencies. Input c-struct: struct Person { int id; char* name; } Output minimal c-code: void dumpPerson(Person* p) { printf("%d%s", p->id, p->name); } It's easy to write in D... just want to avoid reinventing the wheel.
Learning ddoc
Hi, I'm in the process of learning how ddoc works. I've successfully created docs for my code and recently learned how to generate it using dub. Related to this and after seeing the announcement of the new release of the emsi-containers library, I had a look at its docs (http://economicmodeling.github.io/containers/index.html) but when I cloned the repo and generated it locally its appearance is completely different (no side-bar, different formatting for code examples, etc...), it's simpler, it must lack some css or whatever. My question is...is there some standard way to generate better-looking doc-pages with ddoc? Thanks! Antonio
Re: Reinstalled Mac
On Thursday, 29 September 2016 at 06:24:08 UTC, Jacob Carlborg wrote: On 2016-09-29 03:43, David Nadlinger wrote: I've had good experiences using Homebrew, although you sometimes have to wait a day or three for a new release to appear. — David DVM doesn't have that problem :). How easy is it to have multiple versions of DMD installed using Homebrew? It seems simple: --- hw0062:~ pinver$ brew info dmd dmd: stable 2.071.2 (bottled), HEAD D programming language compiler for OS X https://dlang.org/ /usr/local/Cellar/dmd/2.071.0_1 (561 files, 65.0M) Poured from bottle on 2016-06-23 at 14:51:10 /usr/local/Cellar/dmd/2.071.1 (561 files, 65.0M) Poured from bottle on 2016-07-06 at 09:48:40 /usr/local/Cellar/dmd/2.071.2 (561 files, 65.0M) * Poured from bottle on 2016-09-26 at 11:50:45 From: https://github.com/Homebrew/homebrew-core/blob/master/Formula/dmd.rb hw0062:~ pinver$ dmd --version DMD64 D Compiler v2.071.2 Copyright (c) 1999-2015 by Digital Mars written by Walter Bright hw0062:~ pinver$ brew switch dmd 2.071.0_1 Cleaning /usr/local/Cellar/dmd/2.071.0_1 Cleaning /usr/local/Cellar/dmd/2.071.1 Cleaning /usr/local/Cellar/dmd/2.071.2 13 links created for /usr/local/Cellar/dmd/2.071.0_1 hw0062:~ pinver$ dmd --version DMD64 D Compiler v2.071.0 Copyright (c) 1999-2015 by Digital Mars written by Walter Bright --- /Paolo
Re: How to create dynamically sized objects
Actually, would just passing the parameters and an allocator do it? You'd just need to allocate the string in the constructor, right?
How to create dynamically sized objects
Hi, Say I wanted to create an object that has a string member, and I want the string to be allocated with the object contiguously instead of as a pointer to another location (as a constructor would do). For example: class C { this(int i, string s) { this.i = i; this.s = s.toUTF16z(); } int i; wstring s; } I want to allocate memory such that it looks like this: [32-bit int][s.length * wchar.sizeof bytes] I've considered using a separate function to create the class, but I don't know how setting the length of the string would behave. The only solution I can think of would be to have a constructor like this: this(int i, string s, void[] mem) { emplace!int(mem.ptr, i); auto t = cast(dchar[]) mem[int.sizeof .. $]; this.s.fill(s.byDChar()) } Is there a better way to do this?
Re: Reinstalled Mac
On 2016-09-29 03:33, Joel wrote: Oops, I got confused and installed with homebrew. I was going to try DVM. You can install using DVM as well, it will take precedence. -- /Jacob Carlborg
Re: Reinstalled Mac
On 2016-09-29 03:43, David Nadlinger wrote: Jacob is also the author of DVM, so he might be a bit biased. ;) And you would never recommend LDC? ;) I've had good experiences using Homebrew, although you sometimes have to wait a day or three for a new release to appear. — David DVM doesn't have that problem :). How easy is it to have multiple versions of DMD installed using Homebrew? -- /Jacob Carlborg