Re: Beta D 2.069.0-b2
On Wednesday, 14 October 2015 at 13:53:17 UTC, Martin Nowak wrote: Second beta for the 2.069.0 release. http://dlang.org/download.html#dmd_beta http://dlang.org/changelog/2.069.0.html Please report any bugs at https://issues.dlang.org -Martin Is there any reason that these fixes won't be merged for 2.069? https://github.com/D-Programming-Language/phobos/pull/3711 https://github.com/D-Programming-Language/phobos/pull/3688 https://github.com/D-Programming-Language/phobos/pull/3689 I'd prefer not having to maintain my own fork of the allocators code for another release.
Re: Beta D 2.069.0-b1
On 14.10.2015 15:26, Szymon Gatner wrote: To get compatible class layout, the D compiler has to omit it's class info entry in the vtable of C++ classes. In addition D doesn't know about C++ RTTI (I don't know if this is planned to add), so it cannot do the dynamic cast from Operation to Subtract. I have not tried, but calling the virtual destructor instead of destroy() might just work? Mint that this code comes from Adam Ruppe's book, and it is suppose to be working code. Also mind that Subtract is D class and instantiated on D side, it is only briefly passed to C++ for usage. Check the disassembly: the compiler is not even trying to do a conversion, it just loads null. There is no usable type information in a C++ interface. If you know the object "animal" is of type Subtract, you can get the object pointer by manually subtracting the pointer difference from the passed pointer: auto ptr = cast(void*)animal; ptr -= cast(void*)cast(Operation)cast(Subtract)ptr - ptr; auto cat = cast(Subtract) ptr;
Re: Fastest JSON parser in the world is a D project
On Wednesday, 14 October 2015 at 07:35:49 UTC, Marco Leise wrote: auto json = parseTrustedJSON(`{ "coordinates": [ { "x": 1, "y": 2, "z": 3 }, … ] }`); I assume parseTrustedJSON is not validating? Did you use it in the benchmark? And were the competitors non-validating as well?
Fastest JSON parser in the world is a D project
fast.json usage: UTF-8 and JSON validation of used portions by default: auto json = parseJSONFile("data.json"); Known good file input: auto json = parseTrustedJSONFile("data.json"); auto json = parseTrustedJSON(`{"x":123}`); Work with a single key from an object: json.singleKey!"someKey" json.someKey Iteration: foreach (key; json.byKey) // object by key foreach (idx; json)// array by index Remap member names: @JsonRemap(["clazz", "class"]) struct S { string clazz; } @JsonRemap(["clazz", "class"]) enum E { clazz; } Example: double x = 0, y = 0, z = 0; auto json = parseTrustedJSON(`{ "coordinates": [ { "x": 1, "y": 2, "z": 3 }, … ] }`); foreach (idx; json.coordinates) { // Provide one function for each key you are interested in json.keySwitch!("x", "y", "z")( { x += json.read!double; }, { y += json.read!double; }, { z += json.read!double; } ); } Features: - Loads double values in compliance with IEEE round-to-nearest (no precision loss in serialization->deserialization round trips) - UTF-8 validation of non-string input (file, ubyte[]) - Currently fastest JSON parser money can buy - Reads strings, enums, integral types, double, bool, POD structs consisting of those and pointers to such structs Shortcomings: - Rejects numbers with exponents of huge magnitude (>=10^28) - Only works on Posix x86/amd64 systems - No write capabilities - Data size limited by available contiguous virtual memory -- Marco
Re: Fastest JSON parser in the world is a D project
On Wednesday, 14 October 2015 at 07:01:49 UTC, Marco Leise wrote: https://github.com/kostya/benchmarks#json I can't find fast.json here. Where is it?
Semi-OT: Andrei's CppCon 2015 presentation is on Reddit
https://www.reddit.com/r/programming/comments/3oqfxk/the_comedian_andrei_alexandrescu_calls_the/ Ali
Re: Semi-OT: Andrei's CppCon 2015 presentation is on Reddit
On Wednesday, 14 October 2015 at 18:52:59 UTC, Ali Çehreli wrote: https://www.reddit.com/r/programming/comments/3oqfxk/the_comedian_andrei_alexandrescu_calls_the/ Ali And it is quite funny. Andrei is the only person that can get away with such bad puns about alligators :)
Re: Walter and I talk about D in Romania
On Monday, 5 October 2015 at 14:10:43 UTC, Vladimir Panteleev wrote: Not going to miss this opportunity! Since I was apparently the only forum regular in the audience, figured I should post a follow-up. First, the event was recorded. There was a professional A/V studio working with multiple cameras, additional lighting, the works (though they did have some audio problems in the beginning). Andrei confirmed that the recordings will be published. The audience was packed - 400 people in total. Quite amazing. I did not recognize anyone, which on the other hand is great because the event reached 399 people new to D :) Also the % of women was much higher than the past DConfs I've attended. There were a few people in the audience familiar with recent/untraditional programming languages (Rust, Nim, Haskell) so there was some nice dialogue at times (Andrei had to impose a budget on the first 5 rows to get the rest of the audience to participate). The event was organized very well considering the audience size and free attendance. There were free t-shirts, beverages, snacks, and even beer at the end - very nice of Siemens. The talks: The schedule was rearranged a bit, so it doesn't quite correspond to the one on the website (or I might be just misremembering). IIRC, the order was: welcome address, "Three cool things about D" by Andrei, "Interfacing D to legacy C++ code" by Walter, "Writing quick code, quickly" by Andrei, followed by the panel. Andrei's first talk was mainly concerning with "pure", its variants (strong/weak), rules and benefits, as well as a quick description of CTFE and the famous ctRegex benchmark where D beats everything else. I'm not sure if some slides were skipped over due to time constraints. Walter's talk was about how D was extended to gradually support more ways to interface with C++ (class/vtable layouts, namespaces, extern(C++), name mangling etc.) and how it helped DDMD. Andrei's second talk, "Writing quick code, quickly" was not related to D, but I enjoyed it immensely. It covers some interesting optimization problems with some surprising solutions. I highly recommend watching this. Finally, there was the panel with Scott Meyers. This included a book giveaway for the most embarrassing questions, of which there were many. A big part of the audience had left at this point though, as it was getting late. Many questions concerned D's ecosystem, e.g. whether we have good debugging GUIs for all platforms, which we don't for OS X. The books were TDPL (the rare edition with no author on the cover), Ali's D book, and a C++ book by either Andrei or Scott (unfortunately I do not remember), all signed by their authors. This was all for the conference. We took the rest of the weekend to tour Brașov and do some sightseeing. The most striking thing about the city is the number of roundabouts - probably 90% of intersections were replaced by them! If you're around, do make sure to make the climb to the mountain looming above the old city (or just take the cable car), the view is awesome.
Re: Beta D 2.069.0-b1
On Tuesday, 13 October 2015 at 20:10:22 UTC, Rainer Schuetze wrote: On 13.10.2015 21:44, ZombineDev wrote: [...] The library issues are the same for 32-bit and 64-bit. [...] Yes, but there is some magic involved when linking against the VS2015 CRT. To use symbols like snprintf and sscanf, you must also pass legacy_stdio_definitions.lib to the linker, which is done automatically if you use dmd as a frontend to the linker, but not cl. Symbols _minfo_beg, _minfo_end, _deh_beg and _deh_end are only emitted by the compiler if you compile main, WinMain or DllMain. Unfortunately, compiling D's main also generates a C-style main, so it's not so easy to get these symbols if you need main in C/C++. I would currently recommend to write main in D, and call into C/C++ from there. I am trying (as with every new release ;)) to link static D library to existing C++ project and I am having same issue: Error 2 error LNK2019: unresolved external symbol _snprintf referenced in function _D2gc6config13__T5parseHTfZ5parseFNbNiAxaKAxaKfZb C:\Users\Bravo\documents\visual studio 2012\Projects\ConsoleApplication1\ConsoleApplication1\phobos32mscoff.lib(config_48f_452.obj) ConsoleApplication1 _minfo_beg, _minfo_end problems were solved by adding main() to D library so this is only porblem left. I am using Visual Studio 2012
Re: Beta D 2.069.0-b1
On Tuesday, 13 October 2015 at 16:07:50 UTC, Kagamin wrote: What doesn't work for you? extern int f(); struct T(F){} T!f t; //Error: template instance T!(f) does not match template declaration T(F) struct A(alias F){} A!f a; //works I don't remember. I fixed the issues a few weeks ago using various hackarounds. The main area that problems pop up is in metaprogramming where you don't know what you're working with (could be a member function, free function, template function, etc.). It's very hard to deal with optional parens generically, and you have to take special care to ensure that the compiler doesn't think you're calling a function when that's not what you meant to do.
Re: Fastest JSON parser in the world is a D project
Am Wed, 14 Oct 2015 07:55:18 + schrieb Idan Arye: > On Wednesday, 14 October 2015 at 07:35:49 UTC, Marco Leise wrote: > > auto json = parseTrustedJSON(`{ "coordinates": [ { "x": 1, > > "y": 2, "z": 3 }, … ] }`); > > I assume parseTrustedJSON is not validating? Did you use it in > the benchmark? And were the competitors non-validating as well? That is correct. For the benchmark parseJSONFile was used though, which validates UTF-8 and JSON in the used portions. That probably renders your third question superfluous. I wouldn't know anyways, but am inclined to think they all validate the entire JSON and some may skip UTF-8 validation, which is a low cost operation in this ASCII file anyways. -- Marco
Re: Beta D 2.069.0-b2
On 10/14/2015 08:09 PM, Brian Schott wrote: > > Is there any reason that these fixes won't be merged for 2.069? Please target the stable branch when fixing something. Also tagging as 2.069 milestone helps (can you actually tag that yourself?). I don't examine PRs before branching or tagging a version and only take what has been finished. The dates are announced early enough to plan ahead, but it'll prolly take a few more cycles until everyone has the next release in mind. -Martin
Re: Beta D 2.069.0-b1
On Wednesday, 14 October 2015 at 11:46:27 UTC, ZombineDev wrote: 2) How can I workaround the problem that _minfo* and _deh* are not generated because my main is in C++? Just add a file with int main() in D library to fix this.
Re: Beta D 2.069.0-b1
On Wednesday, 14 October 2015 at 11:39:26 UTC, Szymon Gatner wrote: On Tuesday, 13 October 2015 at 20:10:22 UTC, Rainer Schuetze wrote: [...] I am trying (as with every new release ;)) to link static D library to existing C++ project and I am having same issue: Error 2 error LNK2019: unresolved external symbol _snprintf referenced in function _D2gc6config13__T5parseHTfZ5parseFNbNiAxaKAxaKfZb C:\Users\Bravo\documents\visual studio 2012\Projects\ConsoleApplication1\ConsoleApplication1\phobos32mscoff.lib(config_48f_452.obj) ConsoleApplication1 _minfo_beg, _minfo_end problems were solved by adding main() to D library so this is only porblem left. I am using Visual Studio 2012 Update: Linking with static D library under Visual Studio 2015 works fine (which is great). I do need to make it work under VS 2012 tho. Ideas?
Re: Beta D 2.069.0-b1
On 14.10.2015 13:39, Szymon Gatner wrote: On Tuesday, 13 October 2015 at 20:10:22 UTC, Rainer Schuetze wrote: On 13.10.2015 21:44, ZombineDev wrote: [...] The library issues are the same for 32-bit and 64-bit. [...] Yes, but there is some magic involved when linking against the VS2015 CRT. To use symbols like snprintf and sscanf, you must also pass legacy_stdio_definitions.lib to the linker, which is done automatically if you use dmd as a frontend to the linker, but not cl. Symbols _minfo_beg, _minfo_end, _deh_beg and _deh_end are only emitted by the compiler if you compile main, WinMain or DllMain. Unfortunately, compiling D's main also generates a C-style main, so it's not so easy to get these symbols if you need main in C/C++. I would currently recommend to write main in D, and call into C/C++ from there. I am trying (as with every new release ;)) to link static D library to existing C++ project and I am having same issue: Error2error LNK2019: unresolved external symbol _snprintf referenced in function _D2gc6config13__T5parseHTfZ5parseFNbNiAxaKAxaKfZb C:\Users\Bravo\documents\visual studio 2012\Projects\ConsoleApplication1\ConsoleApplication1\phobos32mscoff.lib(config_48f_452.obj) ConsoleApplication1 I just noticed that the magic symbol translation _snprintf -> __snprintf isn't included without linking the internal function init_msvc (which is normally done by d_run_main which is called by the generated C main). The current workaround here is to add extern "C" void __cdecl init_msvc(); to the C source and call it before rt_init. I think we should move it into rt_init inside druntime.
Re: Beta D 2.069.0-b1
On 14.10.2015 13:46, ZombineDev wrote: On Tuesday, 13 October 2015 at 20:10:22 UTC, Rainer Schuetze wrote: Yes, but there is some magic involved when linking against the VS2015 CRT. To use symbols like snprintf and sscanf, you must also pass legacy_stdio_definitions.lib to the linker, which is done automatically if you use dmd as a frontend to the linker, but not cl. Symbols _minfo_beg, _minfo_end, _deh_beg and _deh_end are only emitted by the compiler if you compile main, WinMain or DllMain. Unfortunately, compiling D's main also generates a C-style main, so it's not so easy to get these symbols if you need main in C/C++. I would currently recommend to write main in D, and call into C/C++ from there. Thanks for the answer. Just for the reference, under VS2015 x86 Native Tools Command Prompt I tried to link a C++ main function that only calls rt_init() and rt_term() like this: cl main.cpp C:\D\dmd2\windows\lib32mscoff\phobos32mscoff.lib "C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\lib\legacy_stdio_definitions.lib" I got: main.cpp phobos32mscoff.lib(sections_win64_6de_5a5.obj) : error LNK2019: unresolved external symbol __minfo_beg referenced in function _D2rt14sections_win6414getModuleInfosFZAyPS6object10ModuleInfo phobos32mscoff.lib(sections_win64_6de_5a5.obj) : error LNK2019: unresolved external symbol __minfo_end referenced in function _D2rt14sections_win6414getModuleInfosFZAyPS6object10ModuleInfo main.exe : fatal error LNK1120: 2 unresolved externals Which, based on your answer, is expected. I'm looking into integrating D into an existing C++ build and I need to statically link the D library. So my next questions are: 1) Where can I find legacy_stdio_definitions.lib? P.S.: It's included in VS (C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\lib\legacy_stdio_definitions.lib) Your C++ project should have the library paths setup correctly to find it if you just add it to the additional input libraries. 2) How can I workaround the problem that _minfo* and _deh* are not generated because my main is in C++? As Szymon noticed, you can compile an empty main into the static D library. The additional C main that is generated by DMD won't cause ambiguities as long as your C main is not also in a static library.
Re: Beta D 2.069.0-b1
On Wednesday, 14 October 2015 at 12:05:28 UTC, Szymon Gatner wrote: On Wednesday, 14 October 2015 at 11:39:26 UTC, Szymon Gatner wrote: On Tuesday, 13 October 2015 at 20:10:22 UTC, Rainer Schuetze wrote: [...] I am trying (as with every new release ;)) to link static D library to existing C++ project and I am having same issue: Error 2 error LNK2019: unresolved external symbol _snprintf referenced in function _D2gc6config13__T5parseHTfZ5parseFNbNiAxaKAxaKfZb C:\Users\Bravo\documents\visual studio 2012\Projects\ConsoleApplication1\ConsoleApplication1\phobos32mscoff.lib(config_48f_452.obj) ConsoleApplication1 _minfo_beg, _minfo_end problems were solved by adding main() to D library so this is only porblem left. I am using Visual Studio 2012 Update: Linking with static D library under Visual Studio 2015 works fine (which is great). I do need to make it work under VS 2012 tho. Ideas? Another Update: a bug I reported many moons ago is still there when mixing C++ with D. I updated the issue: https://issues.dlang.org/show_bug.cgi?id=14327
Re: Beta D 2.069.0-b1
On Wednesday, 14 October 2015 at 11:54:22 UTC, Szymon Gatner wrote: On Wednesday, 14 October 2015 at 11:46:27 UTC, ZombineDev wrote: 2) How can I workaround the problem that _minfo* and _deh* are not generated because my main is in C++? Just add a file with int main() in D library to fix this. Thanks! I didn't realize that I could add an empty main in D and force the linker to use the C++ main just by ordering the arguments to the linker :D For 32-bit under VS2015 x86 Native Tools Command Prompt: dmd -lib -m32mscoff my_d_lib.d cl main.cpp my_d_lib.lib C:\D\dmd2\windows\lib32mscoff\phobos32mscoff.lib "C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\lib\legacy_stdio_definitions.lib" And for 64-bit under VS2015 x64 Native Tools Command Prompt: dmd -lib -m64 my_d_lib.d cl main.cpp my_d_lib.lib C:\D\dmd2\windows\lib64\phobos64.lib "C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\lib\amd64\legacy_stdio_definitions.lib" Both works for me. Anyway, I still don't think that forcing the users to use this workaround is a great idea.
Re: Beta D 2.069.0-b1
On Wednesday, 14 October 2015 at 12:35:30 UTC, Rainer Schuetze wrote: I just noticed that the magic symbol translation _snprintf -> __snprintf isn't included without linking the internal function init_msvc (which is normally done by d_run_main which is called by the generated C main). The current workaround here is to add extern "C" void __cdecl init_msvc(); to the C source and call it before rt_init. I think we should move it into rt_init inside druntime. This indeed helps, thanks! There is new problem: creating a class instance on D side, then passing it to C++ and then back to D causes casting errors. My Example (based on Adam Ruppe's example): C++ file: #include #include extern "C" int rt_init(); extern "C" void rt_term(); extern "C++" int sumInD(int a, int b); extern "C++" void printHelloInD(); class Operation { public: virtual ~Operation() {} virtual int execute(int a, int b) = 0; }; class Add : public Operation { int execute(int a, int b) override { return a + b; } }; extern "C++" void useOperation(Operation* t); extern "C++" Operation* getSubtract(); extern "C++" void freeSubtract(Operation* cat); struct DRuntime { DRuntime() { if (!rt_init())\ { throw std::runtime_error("D Initialization failed"); } } ~DRuntime() { rt_term(); } }; void main() { DRuntime druntime; Add add; useOperation(); Operation* sub = getSubtract(); auto value = sub->execute(5, 3); freeSubtract(sub); } D library: module lib; import std.stdio; import core.stdc.stdlib; int main() { return 0; } extern(C++) interface Operation { void _destructorDoNotUse(); int execute(int a, int b); } class Subtract : Operation { extern(C++) void _destructorDoNotUse() {} extern(C++) int execute(int a, int b) {return a - b;} } extern(C++) Operation getSubtract() { import std.conv; enum size = __traits(classInstanceSize, Subtract); auto memory = malloc(size)[0 .. size]; return emplace!Subtract(memory); } extern (C++) int sumInD(int a, int b) { return a + b; } extern (C++) void printHelloInD() { writeln("Hello From D!"); << = throws exception (bug reported) } extern(C++) void freeSubtract(Operation animal) { auto cat = cast(Subtract) animal; <<== cast yields null if(cat !is null) { destroy(cat); free(cast(void*) cat); } } extern(C++) void useOperation(Operation t) { auto res = t.execute(1, 2); } Everything works fine except the marked line. Subtract instance seems to be created correctly on D side as it returns valid result in the execute() call on C++ side but then when trying to free the instance on D side again, downcast from Operation to Subtract fails resulting in null.
Re: Fastest JSON parser in the world is a D project
Am Wed, 14 Oct 2015 10:22:37 +0200 schrieb Rory McGuire via Digitalmars-d-announce: > Does this version handle real world JSON? > > I've keep getting problems with vibe and JSON because web browsers will > automatically make a "1" into a 1 which then causes exceptions in vibe. > > Does yours do lossless conversions automatically? No I don't read numbers as strings. Could the client JavaScript be fixed? I fail to see why the conversion would happen automatically when the code could explicitly check for strings before doing math with the value "1". What do I miss? -- Marco
Re: Fastest JSON parser in the world is a D project
Am Wed, 14 Oct 2015 08:19:52 + schrieb Per Nordlöw: > On Wednesday, 14 October 2015 at 07:01:49 UTC, Marco Leise wrote: > > https://github.com/kostya/benchmarks#json > > I can't find fast.json here. Where is it? »»» D Gdc Fast 0.34226.7 ««« C++ Rapid 0.79687.1 Granted if he wrote "D fast.json" it would have been easier to identify. -- Marco
Re: Walter and I talk about D in Romania
On 10/14/2015 04:15 PM, Vladimir Panteleev wrote: On Wednesday, 14 October 2015 at 23:06:14 UTC, Ali Çehreli wrote: Thank you very much for the summary! It was very informative. On 10/14/2015 03:54 PM, Vladimir Panteleev wrote: > Andrei's second talk, "Writing quick code, quickly" was not related to > D, but I enjoyed it immensely. It covers some interesting optimization > problems with some surprising solutions. I highly recommend watching this. Was it a version of the following talk by any chance? https://www.youtube.com/watch?v=Qq_WaiwzOtI Skimming through that, it looks like a completely different talk (also very interesting)! Will watch that too. Thanks. I should have searched properly before asking. "Writing Quick Code in C++, Quickly" is more promising: https://www.youtube.com/watch?v=ea5DiCg8HOY Ali
Re: Beta D 2.069.0-b2
On 10/15/15 3:05 AM, Vladimir Panteleev wrote: On Wednesday, 14 October 2015 at 23:44:34 UTC, Brian Schott wrote: On Wednesday, 14 October 2015 at 23:26:12 UTC, Martin Nowak wrote: Also tagging as 2.069 milestone helps (can you actually tag that yourself?). No. I would if I could. This one of the things I don't like about Github. (I can't tag pulls/issues even though I'm a member of the D-Programming-Language org) You're not in Team Phobos. Brian, should we add you? LMK. -- Andrei