Re: LDC 0.15.0 alpha1 released! Please help test!
I notice that there's no mingw based windows version with his release. Does this msvc based build output gdb-compatible debugging symbols?
Re: LDC 0.15.0 alpha1 released! Please help test!
Does this msvc based build output gdb-compatible debugging symbols? No DWARFs in there.
Re: LDC 0.15.0 alpha1 released! Please help test!
On Saturday, 25 October 2014 at 09:38:45 UTC, E.S. Quinn wrote: I notice that there's no mingw based windows version with his release. That's just an issue with building the packages for the alpha, the release will have a MinGW version. David
Re: [OT] Re: Final version of dlang-fr released
reminds me of the cold war era: Turkish population favored the Americans to the neighboring Soviets to the extent that rus salatası (a mayonnaise-based salad) has started to be called amerikan salatası by the public. _ Pakistan
Re: CUDA bindings
On Tuesday, 21 October 2014 at 08:31:03 UTC, ponce wrote: On Thursday, 16 October 2014 at 21:18:15 UTC, ponce wrote: Dear D users, I'd like to announce DerelictCUDA, dynamic bindings to the CUDA library. https://github.com/derelictorg/derelictcuda For now, only the CUDA Driver API is exposed, providing most of the warp control. For a visual explanation of the different APIs in CUDA, see http://stackoverflow.com/questions/242894/cuda-driver-api-vs-cuda-runtime More APIs could be implemented if the interest happens to be non-null. CUDA Runtime API added. This is great! I know that C++ uses and to enclose kernel calls and thus create the link between CPU and GPU code when NVCC rips things apart. How is this done in your bindings?
Re: Linux 64bit Calling Convention
On Thursday, 28 February 2013 at 01:03:08 UTC, Maxime Chevalier wrote: I did some further testing: void foo(int a, int b) { writefln(a: %s, a); writefln(b: %s, b); } unittest { foo(1, 2); asm { mov RDI, 1; mov RSI, 2; call foo; } } Produces: a: 1 b: 2 a: 2 b: 1 Unless I'm mistaken, DMD does not respect the C calling convention on Linux/AMD64. True. For extern(D) dmd passes parameters in reverse order on Win64 and Linux64! What the heck?
Re: Linux 64bit Calling Convention
On Thursday, 28 February 2013 at 02:02:09 UTC, Walter Bright wrote: On 2/27/2013 5:03 PM, Maxime Chevalier wrote: Unless I'm mistaken, DMD does not respect the C calling convention on Linux/AMD64. To use the C calling convention, specify extern (C) for the function. This is about extern(D).
Re: Linux 64bit Calling Convention
Looking at the code extern(D) is in the _revfunc list in optabgen. Which seems to cause params to be reversed independent of the architecture in FuncDeclaration::toObjFile // Reverse params[] entries. Meaning Linux x32 would also be affected. This totally smells like a remnant as the code matches the initial custom Win32 D ABI.
Re: Linux 64bit Calling Convention
On Saturday, 25 October 2014 at 15:20:53 UTC, Trass3r wrote: This totally smells like a remnant as the code matches the initial custom Win32 D ABI. Yep. I thought the D calling convention matched the C calling convention on 64-bit. Didn't Walter even state this explicitly at some point?
Re: Linux 64bit Calling Convention
Yes it's clearly stated on the ABI page (and sane). Nobody ever noticed cause it's hard to spot this in assembly. But it was very salient and disturbing in llvm IR.
Re: std.experimental.logger formal review round 3
Jut for the reference, my position on current state of things as review manager is this: I agree with some of mentioned concerns and would like to see those fixed. However, I don't think any of those are truly critical and this proposal has been hanging there for just too long. In my opinion it will be more efficient to resolve any remainining issues in follow-up pull requests on case by case basis then forcing Robert to do it himself - there will be some time left before next release to break a thing or two before public statement is made. Because of that I am going to start voting despite some arguments being still in process. I hope that won't cause any tension.
function pointer bug?
I am trying to store a function pointer in a class in a generic way(works with all member/non-member/global functions). In the main() function below, there are two cases(A, B). If case B is commented out, this code complies/runs fine. Otherwise, I get these errors, and the compiler pointing at dg.funcptr = T[0]; in TestClas.invoke(void*). Error: this for instanceMethod needs to be type TestClass not type main.FuncPtr!(instanceMethod).FuncPtr Error: cannot implicitly convert expression ((__error).instanceMethod) of type void delegate() to void function() Error: template instance main.FuncPtr!(instanceMethod) error instantiating Am I missing something here or is this a bug? class TestClass { void instanceMethod() { writeln(Instance Method!); } static void staticMethod() { writeln(Static Method!); } } void GlobalMethod() { writeln(Global Method!); } void invokeFunction(T...)(void *instance){ alias typeof(T[0]) method_type; alias ReturnType!method_type return_type; alias ParameterTypeTuple!method_type param_types; alias return_type delegate(param_types) delegate_type; delegate_type dg; dg.ptr = instance; dg.funcptr = T[0]; dg(); } class FuncPtr(T...) { void invoke(void *instance) { alias typeof(T[0]) method_type; alias ReturnType!method_type return_type; alias ParameterTypeTuple!method_type param_types; alias return_type delegate(param_types) delegate_type; delegate_type dg; dg.ptr = instance; dg.funcptr = T[0]; dg(); } } void main() { TestClass testClass = new TestClass(); // case A invokeFunction!(TestClass.instanceMethod)(cast(void*)testClass); invokeFunction!(TestClass.staticMethod)(null); invokeFunction!(GlobalMethod)(null); // case B auto fp1 = new FuncPtr!(TestClass.instanceMethod); auto fp2 = new FuncPtr!(TestClass.staticMethod); auto fp3 = new FuncPtr!(GlobalMethod); fp1.invoke(cast(void*)testClass); fp2.invoke(null); fp3.invoke(null); }
Re: D in my trashbin
On Friday, 24 October 2014 at 02:42:13 UTC, frustrated wrote: Two days later and I still cant get a 'Hello World' to compile. It is far beyond me how a project can exist for so many years and still not have a straightforward installation that works out of the box. Yes.. read the forums and search google for solutions that may or may not work depending on the phases of the moon, I have to ask you: Why bother ? Why would anybody trust a compiler written by people who regard making it run out of the box an after-thought ? Sorry, actually it was a joke from me and I laught a lot while reading your answers during 3 days. The setup is just fine, although if you've started a nice think-tank about the problem... Sorry. My bad.
Re: D in my trashbin
On Saturday, 25 October 2014 at 19:33:45 UTC, Jkpl wrote: Sorry, actually it was a joke from me and I laught a lot while reading your answers during 3 days. The setup is just fine, although if you've started a nice think-tank about the problem... Sorry. My bad. :/
Deimos library interfaces needed for these
https://github.com/D-Programming-Deimos http://en.docsity.com/news/programming-2/free-libraries-for-everyday-work-in-popular-languages/ These appear to have C interfaces, so should be tractable for D without too much effort.
Algorithms to solve programming contest problems
http://www.quora.com/What-are-the-algorithms-required-to-solve-all-problems-using-C++-in-any-competitive-coding-contest Anyone want to review these and see what we should add to Phobos?
Re: D in my trashbin
On Saturday, 25 October 2014 at 19:33:45 UTC, Jkpl wrote: On Friday, 24 October 2014 at 02:42:13 UTC, frustrated wrote: Two days later and I still cant get a 'Hello World' to compile. It is far beyond me how a project can exist for so many years and still not have a straightforward installation that works out of the box. Yes.. read the forums and search google for solutions that may or may not work depending on the phases of the moon, I have to ask you: Why bother ? Why would anybody trust a compiler written by people who regard making it run out of the box an after-thought ? Sorry, actually it was a joke from me and I laught a lot while reading your answers during 3 days. The setup is just fine, although if you've started a nice think-tank about the problem... Sorry. My bad. Regardless of me believing you or not, by what means was it a joke? OP complains about technical difficulties, several people offer assistance, then you arrive claim you laughed about the whole thing and apologize. I find it hard to believe there was any humor amongst any of that, aside from the few jokes a couple people made.
Arduino and D
Has anybody tapped the massive Arduino programming explosion using D instead of C++ ? I got started on Arduino a few years back and it has taken the microprocessor popularity through the roof . Unfortunately you download the IDE (Integrated Development Environment) from Arduino.cc direct and then using a $3 development board with a 328p chip on it ,proceed to program the chip to do pretty much whatever you can think of including turning stuff on with your mobile from anywhere in the world and much much more . I wondered if someone could adapt it to D ?
Re: D in my trashbin
On Friday, 24 October 2014 at 02:42:13 UTC, frustrated wrote: Two days later and I still cant get a 'Hello World' to compile. It is far beyond me how a project can exist for so many years and still not have a straightforward installation that works out of the box. Yes.. read the forums and search google for solutions that may or may not work depending on the phases of the moon, I have to ask you: Why bother ? Why would anybody trust a compiler written by people who regard making it run out of the box an after-thought ? What error are you getting? dmd easier to install as tcc compiler. I used to download a .zip file but now I use the setup in .exe format so it install everything for me 1-click only. It ask me to install dmd/dmc/visual D and so on. I select what I need to and then it's done. After downloaed I just path the dmd's path in my Windows' PATH variable to use it from command line or an IDE invoke dmd command and run successfully. It's on Windows. Other than Windows such as Linux isn't such a hard.
Re: D in my trashbin
I see only one post from Frustrated the OP You guys won't learn will you .
Re: D in my trashbin
On Saturday, 25 October 2014 at 21:24:14 UTC, Kyoji Klyden wrote: On Saturday, 25 October 2014 at 19:33:45 UTC, Jkpl wrote: On Friday, 24 October 2014 at 02:42:13 UTC, frustrated wrote: Two days later and I still cant get a 'Hello World' to compile. It is far beyond me how a project can exist for so many years and still not have a straightforward installation that works out of the box. Yes.. read the forums and search google for solutions that may or may not work depending on the phases of the moon, I have to ask you: Why bother ? Why would anybody trust a compiler written by people who regard making it run out of the box an after-thought ? Sorry, actually it was a joke from me and I laught a lot while reading your answers during 3 days. The setup is just fine, although if you've started a nice think-tank about the problem... Sorry. My bad. Regardless of me believing you or not, by what means was it a joke? OP complains about technical difficulties, several people offer assistance, then you arrive claim you laughed about the whole thing and apologize. I find it hard to believe there was any humor amongst any of that, aside from the few jokes a couple people made. Just ask to Vlad. He seems to be the forum maintainer. He'll check the IP. Even if I'm not the OP, the message is clear: why the hell do you care about this ? DMD setup is fine. It works. dot.
Re: D in my trashbin
On Saturday, 25 October 2014 at 22:17:35 UTC, Jkpl wrote: Just ask to Vlad. He seems to be the forum maintainer. He'll check the IP. Even if I'm not the OP, the message is clear: why the hell do you care about this ? DMD setup is fine. It works. dot. Haha, why would anyone go check your IP? Should we tell everyone who has trouble with DMD: the setup is fine. It works. dot.? It has a very reassuring ring to it. Melts my troubles away. :P Once you're ready to take on Hello World or to show us your next great skit, feel free to post in D.Learn.
Re: Arduino and D
On Saturday, 25 October 2014 at 21:49:53 UTC, Ty Tower wrote: Has anybody tapped the massive Arduino programming explosion using D instead of C++ ? I got started on Arduino a few years back and it has taken the microprocessor popularity through the roof . Unfortunately you download the IDE (Integrated Development Environment) from Arduino.cc direct and then using a $3 development board with a 328p chip on it ,proceed to program the chip to do pretty much whatever you can think of including turning stuff on with your mobile from anywhere in the world and much much more . I wondered if someone could adapt it to D ? Well it is ARM so it should be possible.
Re: D in my trashbin
On Saturday, 25 October 2014 at 22:41:59 UTC, Kyoji Klyden wrote: On Saturday, 25 October 2014 at 22:17:35 UTC, Jkpl wrote: Just ask to Vlad. He seems to be the forum maintainer. He'll check the IP. Even if I'm not the OP, the message is clear: why the hell do you care about this ? DMD setup is fine. It works. dot. Haha, why would anyone go check your IP? Should we tell everyone who has trouble with DMD: the setup is fine. It works. dot.? It has a very reassuring ring to it. Melts my troubles away. :P Once you're ready to take on Hello World or to show us your next great skit, feel free to post in D.Learn. But the setup is fine.. and when it isn't you can see from just how fast the community replies, that people do care, and will endeavour to fix it! There is also the option to use DMD without the installer, its not rocket science. In fact all this thread has really served is to prove just how much people do care for D.
Re: Arduino and D
On Saturday, 25 October 2014 at 21:49:53 UTC, Ty Tower wrote: Has anybody tapped the massive Arduino programming explosion using D instead of C++ ? I got started on Arduino a few years back and it has taken the microprocessor popularity through the roof . Unfortunately you download the IDE (Integrated Development Environment) from Arduino.cc direct and then using a $3 development board with a 328p chip on it ,proceed to program the chip to do pretty much whatever you can think of including turning stuff on with your mobile from anywhere in the world and much much more . I wondered if someone could adapt it to D ? As far as I know, none of the main D compilers (DMD, LDC, GDC) can generate code for 8-bit MCUs. I remember reading somewhere that GDC has turned on a flag that specifically disables it. However, I think it would be cool if a motivated individual would actually flip this flag and see how far they can get. I don't now if avr-gcc is part of the mainline GCC branch, though. In summary, the Atmel ATmega needs some infrastructure first. The ARM Cortex-M based Arduino boards (Arduino Due for example) can already be programmed with D using either the LDC compiler (with ARM Thumb backend) or the GDC compiler. I've encountered several bugs trying to get a bare-bones druntime compiled with the LDC compiler, but the LDC folks have been attentive and appear to be addressing them (Thank you!). A minimal Hello World how-to was created on the D Wiki [1] to help users get started with this. There are also instructions for building a GDC cross-compiler on a Linux host [2] (Thank you, GDC!). A presentation was also given at DConf 2014 providing an introduction to some work done on this platform [3]. Most of my work has stalled as I try to find a way to make the experience more polished, and less like patchwork. Bottom line, though, is druntime has not been ported to the ARM Cortex-M platform, so that is the barrier. The good news is that it's not necessary to have the entire druntime ported to do basic C-style programming in D. In fact, a simple object.d file with a few dummy implementations will get you quite far [4]. The current druntime isn't suited very well to bare-metal programming, and really expects an operating system to exist underneath. There have been efforts to try an change that, but they've mostly met resistance. All work on this platform currently exists outside of the main D programming language repositories. There also appears to be a more mature implementation of druntime for an STM32 MCU (ARM Cortex-M4) in minlibd [5]. I hope that gives you some of the information you were looking for. Mike [1] http://wiki.dlang.org/Minimal_semihosted_ARM_Cortex-M_%22Hello_World%22 [2] http://wiki.dlang.org/Bare_Metal_ARM_Cortex-M_GDC_Cross_Compiler [3] https://www.youtube.com/watch?v=o5m0m_ZG9e8 [4] https://github.com/JinShil/D_Runtime_ARM_Cortex-M_study/wiki/1.3-Structs [5] https://bitbucket.org/timosi/minlibd
Re: D in my trashbin
On Saturday, 25 October 2014 at 22:41:59 UTC, Kyoji Klyden wrote: On Saturday, 25 October 2014 at 22:17:35 UTC, Jkpl wrote: Just ask to Vlad. He seems to be the forum maintainer. He'll check the IP. Even if I'm not the OP, the message is clear: why the hell do you care about this ? DMD setup is fine. It works. dot. Haha, why would anyone go check your IP? Should we tell everyone who has trouble with DMD: the setup is fine. It works. dot.? It has a very reassuring ring to it. Melts my troubles away. :P Once you're ready to take on Hello World or to show us your next great skit, feel free to post in D.Learn. Initially i was just trying to solve the thing by saying: dont bother it 's a joke, you can setup dmd and compile a simple hello world. But...it seems that's some people cant accept the perfect explanation. I mean: stop being stuck on this, the OP has made an error. He won't reply. Even if now he has compiled his hello world, do you really think, in your own soul, that he will come saying it's ok now, I get it, it works fine. Seriously.
Re: Arduino and D
On Saturday, 25 October 2014 at 22:55:12 UTC, Israel wrote: Well it is ARM so it should be possible. There is a significant difference between ARM and ARM Thumb. ARM (which shares the name of ARM Ltd.) is the architecture primarily used for devices like smartphones, credit card PCs (Raspberry Pi, BeagleBone Black, etc...) and other portable consumer devices. ARM Thumb, on the other hand, is the architecture used for microcontroller programming like the Arduino. ARM is a 32-bit instructions set, and ARM Thumb is 16-bit or a mixture of 16-bit and 32-bit instructions. I've only done ARM Thumb programming, so I can't elaborate on the differences well, but I also believe the two have a different exception model and many other differences. I believe the mainline druntime has pretty good support for ARM, but nothing at all for ARM Thumb. One could probably use D pretty well for the Raspberry Pi, but they're going to have to make their own druntime to program the Arduino. Mike
Re: D in my trashbin
On Saturday, 25 October 2014 at 23:44:04 UTC, Jkpl wrote: On Saturday, 25 October 2014 at 22:41:59 UTC, Kyoji Klyden wrote: On Saturday, 25 October 2014 at 22:17:35 UTC, Jkpl wrote: Just ask to Vlad. He seems to be the forum maintainer. He'll check the IP. Even if I'm not the OP, the message is clear: why the hell do you care about this ? DMD setup is fine. It works. dot. Haha, why would anyone go check your IP? Should we tell everyone who has trouble with DMD: the setup is fine. It works. dot.? It has a very reassuring ring to it. Melts my troubles away. :P Once you're ready to take on Hello World or to show us your next great skit, feel free to post in D.Learn. Initially i was just trying to solve the thing by saying: dont bother it 's a joke, you can setup dmd and compile a simple hello world. But...it seems that's some people cant accept the perfect explanation. I mean: stop being stuck on this, the OP has made an error. He won't reply. Even if now he has compiled his hello world, do you really think, in your own soul, that he will come saying it's ok now, I get it, it works fine. Seriously. it's ok now, I get it, it works fine. I managed to compile a hello world. Stop the hostilities. Plz.
Re: Algorithms to solve programming contest problems
On Saturday, 25 October 2014 at 20:51:04 UTC, Walter Bright wrote: http://www.quora.com/What-are-the-algorithms-required-to-solve-all-problems-using-C++-in-any-competitive-coding-contest Anyone want to review these and see what we should add to Phobos? I have enormous respect for Walter, this has me betting my company on D. But how I wish this said: hey, anyone know of what we can remove from D or move to downstream? JRE has Oracle and 100 devs, CLR has MS and 100 dec, there are 7 for D, and it should be narrow, like LUA. It should have 7% of their platform. Majority of scared cows must be killed, the sooner leaders realize the better.
D's New GC and Object Allocation Pools
Hello, I was wondering if there have been updates regarding Andrei's announcement that he would rewrite the D garbage collector. Is there any kind of timeline for when a new version of the GC can be expected? I also wanted to ask if there was an implementation of an object pool in the standard library. If not, I'm wondering what the best way to implement this is. Is there any way to overload new and destroy? I was thinking of using the templated emplace operator from std.conv to allocate class objects into a large flat array, and to derive pool-allocated classes from a PoolObject base class. This base class would contain linked list pointers to implement a free list, as well as templated static methods to allocate and free the objects. Any advice welcome.
Re: D's New GC and Object Allocation Pools
On Sunday, 26 October 2014 at 03:37:47 UTC, Maxime Chevalier-Boisvert wrote: I also wanted to ask if there was an implementation of an object pool in the standard library. If not, I'm wondering what the best way to implement this is. Is there any way to overload new and destroy? I'm not an authority on the subject, but I believe all you need to do is provide alternate implementations for _d_newclass[1] and destroy[2]. I experimented with this a little bit about a year ago, and it worked well for me. I modified druntime for my experiments, but there may be a way to link in your implementations instead of the defaults at link time, thus giving you an override effect. I was thinking of using the templated emplace operator from std.conv to allocate class objects into a large flat array, and to derive pool-allocated classes from a PoolObject base class. This base class would contain linked list pointers to implement a free list, as well as templated static methods to allocate and free the objects. Any advice welcome. If you haven't already, check out the Memory Management article on the D Wiki [3]. It's a nice article that was written some time ago by an unknown author and migrated to the wiki last year to help keep it maintained. I particularly like Explicit Class Allocation[4], Mark/Release[5], and Free Lists[6] as alternatives. Mike [1] - https://github.com/D-Programming-Language/druntime/blob/master/src/rt/lifetime.d#L60 [2] - https://github.com/D-Programming-Language/druntime/blob/master/src/object_.d#L2379 [3] - http://wiki.dlang.org/Memory_Management [4] - http://wiki.dlang.org/Memory_Management#Explicit_Class_Instance_Allocation [5] - http://wiki.dlang.org/Memory_Management#Mark.2FRelease [6] - http://wiki.dlang.org/Memory_Management#Free_Lists
Re: D's New GC and Object Allocation Pools
On Sunday, 26 October 2014 at 03:37:47 UTC, Maxime Chevalier-Boisvert wrote: Hello, I was wondering if there have been updates regarding Andrei's announcement that he would rewrite the D garbage collector. Is there any kind of timeline for when a new version of the GC can be expected? I also wanted to ask if there was an implementation of an object pool in the standard library. If not, I'm wondering what the best way to implement this is. Is there any way to overload new and destroy? I was thinking of using the templated emplace operator from std.conv to allocate class objects into a large flat array, and to derive pool-allocated classes from a PoolObject base class. This base class would contain linked list pointers to implement a free list, as well as templated static methods to allocate and free the objects. Any advice welcome. Regarding the GC, the last I heard Andrei didn't have it at the top of his to do list. He seems to be putting most of his effort right now into completing the C++ integration. However, work on the GC is still in high demand it would seem. (I don't have any helpful answers for your other questions, though.. sry!)
Re: D in my trashbin
great stuff frustrated I hope you enjoy it . Its worth the time investment
Compatibility with D regexp constructor
Where I can find compatibility with D online regexp constructor?
Two cases for improving error messages
Hello. Please see the following and say whether they're OK to submit as bugs for improving the error messages. Thanks. ref int foo(ref int x) { return x ; } void main () { foo(3) ; // Error: function rvalue_argument.foo (ref int x) is not callable using argument types (int) // Comment: argument ref int x of function rvalue_argument.foo cannot bind to an rvalue would be clearer IMO int i ; ref ir = i ; // Error: variable ref_type.main.ir only parameters or foreach declarations can be ref // Comment: add , return values after parameters } -- Shriramana Sharma ஶ்ரீரமணஶர்மா श्रीरमणशर्मा
Re: Dynamically Loading a D DLL From a C Program in Linux
// MGW 05.01.14 // We model in D object C ++ QByteArray from Qt. // // Windows: dmd st1.d // Linux: dmd st1.d -L-ldl import core.runtime; // Load DLL for Win import std.stdio;// writeln version(linux) { import core.sys.posix.dlfcn; // declare dlopen() и dlsym() // On Linux these functions are not defined in core.runtime, here and it was necessary to add. extern (C) void* rt_loadLibrary(const char* name) { return dlopen(name, RTLD_GLOBAL || RTLD_LAZY); } void* GetProcAddress(void* hLib, string nameFun) { return dlsym(hLib, nameFun.ptr);} } version(Windows) { import std.c.windows.windows; // GetProcAddress для Windows } //it is important!!! //At definition constructs and functions of members the attribute extern (C) is obligatory! alias extern (C) void function(void*, char*) t_QByteArray_QByteArray; t_QByteArray_QByteArray QByteArray_QByteArray; alias extern (C) void* function(void*, char, int) t_QByteArray_fill;t_QByteArray_fill QByteArray_fill; // Struct QByteArray from qbytearray.h in include directory. // inline char *QByteArray::data() { detach(); return d-data; } где d есть Data* struct Data { void* rref; int alloc; int size; char* data; // Here actually behind what it is necessary for us, the index on a file of bytes char array[1]; } // == Experimental class DQByteArray == class DQByteArray { Data* QtObj; // Object: QtObj - its size of 4 bytes (32 digit version) // -- // class D, call class C++ this(char* buf) { QByteArray_QByteArray(QtObj, buf); } ~this() { // It is possible to find ~this and here it to register, but it is routine } // inline char *QByteArray::data() { detach(); return d-data; } где d есть Data* char* data() { return (*QtObj).data; } // D: Data** == C++: QByteArray Here also it became clear, that such object With ++, looking at it from D void* fill(char ch, int resize=-1) { return QByteArray_fill(QtObj, ch, resize); } } int main(string[] args) { // Files with QByteArray C++ version(linux) {auto nameQtCore = libQtCore.so; } version(Windows) {auto nameQtCore = QtCore4.dll; } auto h = Runtime.loadLibrary(nameQtCore); // Load dll или so // It is QByteArray::QByteArray(char*); QByteArray_QByteArray = cast(t_QByteArray_QByteArray)GetProcAddress(h, _ZN10QByteArrayC1EPKc); // QByteArray::fill(char*, int); QByteArray_fill = cast(t_QByteArray_fill)GetProcAddress(h, _ZN10QByteArray4fillEci); // Create my class DQByteArray ba = new DQByteArray(cast(char*)ABC.ptr); printf(\n ba.data() = %s, ba.data()); // Test fill() from C++ ba.fill('Z', 5); printf(\n ba.data() = %s, ba.data()); return 0; }
Re: Two cases for improving error messages
Shriramana Sharma: int i ; ref ir = i ; // Error: variable ref_type.main.ir only parameters or foreach declarations can be ref // Comment: add , return values after parameters } I like this. Bye, bearophile
Type name shadowing
T shadow(T = int)(T a) { alias T = string; T b = hi; T c = 1; // Error writeln(typeof(a).stringof); // int writeln(typeof(b).stringof); // string return a; } Are there uses for this shadowing of type names? It seems a little dangerous, for example ulong T could be shadowed by uint T. Is there a reason to allow it?
Pragma mangle and D shared objects
I haven't been able to find much about pragma mangle. I'd like to do the following: http://forum.dlang.org/thread/hznsrmviciaeirqkj...@forum.dlang.org#post-zhxnqqubyudteycwudzz:40forum.dlang.org The part I find ugly is this: void* vp = dlsym(lib, _D6plugin11getInstanceFZC2bc2Bc\0.ptr); I want to write a framework that stores a dynamic library name and symbol to execute, and downloads the dynamic library if it's not available. This would be in a long-running server/networking application, and needs to be simple to use. The mangling makes it less obvious for the programmer writing a plugin. Does mangle make it possible to change this to dlsym(lib, myOwnMangledName), or would it still have strange symbols? Also, I've never seen the thunkEBX change merged from here: http://forum.dlang.org/thread/hznsrmviciaeirqkj...@forum.dlang.org?page=2#post-lg2lqi:241ga3:241:40digitalmars.com
Generating code based on UDA
Hello everyone, I am trying to understand UDA traits scoping while mixing in code. Aiming to generate code based on UDA I wonder if the following is possible: class A { @Inject Logger logger; @Inject SomeOtherClass dependency; mixin injections!(A) ... } In injections function I want to iterate through members annotated with the @Inject attribute and generate some specific code. So far in my attempts the compiler complains about unknown identifier A. Should the A class be available to the compiler at the time of the mixin invocation? Thanks for your help, Rares
Re: Generating code based on UDA
On Saturday, 25 October 2014 at 13:37:56 UTC, Rares Pop wrote: Aiming to generate code based on UDA I wonder if the following is possible: Yes, and copy/pasting that works for me...
Re: Generating code based on UDA
Thanks for the quick response. What do you mean by copy/pasting ? On Saturday, 25 October 2014 at 13:40:56 UTC, Adam D. Ruppe wrote: On Saturday, 25 October 2014 at 13:37:56 UTC, Rares Pop wrote: Aiming to generate code based on UDA I wonder if the following is possible: Yes, and copy/pasting that works for me...
Re: Generating code based on UDA
On 2014-10-25 13:37:54 +, Rares Pop said: Hello everyone, I am trying to understand UDA traits scoping while mixing in code. Aiming to generate code based on UDA I wonder if the following is possible: class A { @Inject Logger logger; @Inject SomeOtherClass dependency; mixin injections!(A) ... } In injections function I want to iterate through members annotated with the @Inject attribute and generate some specific code. So far in my attempts the compiler complains about unknown identifier A. Should the A class be available to the compiler at the time of the mixin invocation? Thanks for your help, Rares Very much possible. Since I don't see what your template is doing, I'm going to give it a guess: class A{ mixin injections; } template injections { typeof(this); // e.g. foreach( tra; __traits(getAttributes, typeof(this))) } typeof(this) will be A.
Re: Generating code based on UDA
On Saturday, 25 October 2014 at 13:45:29 UTC, Rares Pop wrote: What do you mean by copy/pasting ? I literally copied the code in your post (and fixed a missing semicolon) and got it to compile. Passing A as an argument to injections should work. You can also use this and typeof(this) inside the injections template code to access the class. It should all work.
Re: Two cases for improving error messages
On Sat, Oct 25, 2014 at 05:14:31PM +0530, Shriramana Sharma via Digitalmars-d-learn wrote: Hello. Please see the following and say whether they're OK to submit as bugs for improving the error messages. Thanks. ref int foo(ref int x) { return x ; } void main () { foo(3) ; // Error: function rvalue_argument.foo (ref int x) is not callable using argument types (int) // Comment: argument ref int x of function rvalue_argument.foo cannot bind to an rvalue would be clearer IMO int i ; ref ir = i ; // Error: variable ref_type.main.ir only parameters or foreach declarations can be ref // Comment: add , return values after parameters } [...] I agree with submitting both of these as enhancement requests. Please tag them with diagnostic in the keywords field. T -- To provoke is to call someone stupid; to argue is to call each other stupid.
Re: Type name shadowing
On Sat, Oct 25, 2014 at 12:28:39PM +, ixid via Digitalmars-d-learn wrote: T shadow(T = int)(T a) { alias T = string; T b = hi; T c = 1; // Error writeln(typeof(a).stringof); // int writeln(typeof(b).stringof); // string return a; } Are there uses for this shadowing of type names? It seems a little dangerous, for example ulong T could be shadowed by uint T. Is there a reason to allow it? The problem gets worse than that. For example: external_library.d module external_library; alias T = string; main.d module main; void func(T = int)(T i) { import external_library; pragma(msg, T.stringof); // prints 'string' } void main() { func(1); } Imagine that the 'alias T' was not present in an earlier version of the library, but now has been added by the library author. Suddenly, user code breaks without warning. T -- Error: Keyboard not attached. Press F1 to continue. -- Yoon Ha Lee, CONLANG
Re: Generating code based on UDA
On Saturday, 25 October 2014 at 13:53:35 UTC, Adam D. Ruppe wrote: On Saturday, 25 October 2014 at 13:45:29 UTC, Rares Pop wrote: What do you mean by copy/pasting ? I literally copied the code in your post (and fixed a missing semicolon) and got it to compile. Passing A as an argument to injections should work. You can also use this and typeof(this) inside the injections template code to access the class. It should all work. Taking this one step further, it looks like the attributes are not available at the mixin scope. Here is my code: -- struct Inject { // immutable Scope scoped; } static string injections(T)() { pragma(msg, injections for : , T); string result; foreach(member; __traits(allMembers,T)) { enum fullName = format(%s.%s, T.stringof, member); pragma(msg, member: , fullName); auto attributes = __traits(getAttributes, fullName); enum dbg_msg = format (%s attributes are %s, fullName, attributes.stringof); pragma(msg, dbg_msg); foreach(attr;attributes){ pragma(msg, Checking attribute, attr); } } return result; } class A { this(){ } } class B { @Inject A a; mixin(injections!(B)); } --- when compiling this code this is the output I get: Compiling using dmd... injections for : B member: B.a B.a attributes are tuple() member: B.toString B.toString attributes are tuple() member: B.toHash B.toHash attributes are tuple() member: B.opCmp B.opCmp attributes are tuple() member: B.opEquals B.opEquals attributes are tuple() member: B.Monitor B.Monitor attributes are tuple() member: B.factory B.factory attributes are tuple() -- B.a attributes are an empty tuple even though the member is annotated with @Inject. Any ideas why?
Re: Pragma mangle and D shared objects
On Sat, Oct 25, 2014 at 09:20:33AM -0400, Etienne Cimon via Digitalmars-d-learn wrote: I haven't been able to find much about pragma mangle. I'd like to do the following: http://forum.dlang.org/thread/hznsrmviciaeirqkj...@forum.dlang.org#post-zhxnqqubyudteycwudzz:40forum.dlang.org The part I find ugly is this: void* vp = dlsym(lib, _D6plugin11getInstanceFZC2bc2Bc\0.ptr); I want to write a framework that stores a dynamic library name and symbol to execute, and downloads the dynamic library if it's not available. This would be in a long-running server/networking application, and needs to be simple to use. Perhaps the .mangleof built-in property might help you here? For instance: ---plugin.d--- class MyClass; MyClass getInstance(); ---test.d--- import std.stdio; import plugin; void main() { writeln(plugin.getInstance.mangleof); } Output: _D6plugin11getInstanceFZC6plugin7MyClass Granted, it's a bit ugly (you have to actually create a module called 'plugin' in order to get the right mangling), but at least it doesn't require the user to learn how D's mangling scheme works. You just write a function prototype for the function you're trying to lookup, and call .mangleof on it. The mangling makes it less obvious for the programmer writing a plugin. Does mangle make it possible to change this to dlsym(lib, myOwnMangledName), or would it still have strange symbols? [...] What you *could* do, is to use .mangleof and clever regex'ing to make it possible to do that. For example, something along these lines: ---dl_support.d--- alias ReturnType = ... /* whatever type you want */; private ReturnType pluginFuncStubName(... /* arguments here */); auto loadPluginFunction(string library, string funcName) { auto r = regex(`pluginFuncStubName`); auto mangledName = pluginFuncStubName.mangleof.replace(r, funcName); ... /* mangledName should now be the mangled string you need * to find the symbol */ } Basically, use an unambiguous blatantly long name for your function prototype, and do a search-and-replace to substitute that with the desired function name. Note that you still need to have a separate stub per function signature; so if you want users to be able to load functions of arbitrary signature, you probably need to make that a template parameter and have the user pass in the desired function signature. For example: auto loadPluginFunction(Signature)(string library, string funcName) { import std.traits : ReturnType, ParameterTypeTuple; import std.regex : regex, replaceFirst; // Declare a static function with the user-desired // signature, with a nicely-substitutable name static ReturnType!Signature pluginFuncStubName(ParameterTypeTuple!Signature); auto r = regex(`pluginFuncStubName`); auto symbol = pluginFuncStubName.mangleof.replaceFirst(r, funcName); // Proof of concept import std.stdio; writeln(symbol); // ... Call dlsym to find function here // Just to make this compile, replace with real function pointer in // your code here. return null; } void main() { auto f1 = loadPluginFunction!(int function(string,int))(mylib, func1); auto f2 = loadPluginFunction!(void function(float))(mylib, func2); } Output: _D4test33__T18loadPluginFunctionTPFAyaiZiZ18loadPluginFunctionFAyaAyaZ18func1FAyaiZi _D4test30__T18loadPluginFunctionTPFfZvZ18loadPluginFunctionFAyaAyaZ18func2FfZv This example isn't complete yet (you need to do something about the loadPluginFunction component in the mangled name), but you should be able to work out a way of producing the correct mangled name from here. But at least it demonstrates how you can have a very nice API for your users -- they just pass in the function prototype of the function they want, and the library code takes care of deriving the correct mangled names. Hope this helps. T -- Just because you can, doesn't mean you should.
Re: Generating code based on UDA
On 10/25/2014 07:45 AM, Rares Pop wrote: On Saturday, 25 October 2014 at 13:53:35 UTC, Adam D. Ruppe wrote: On Saturday, 25 October 2014 at 13:45:29 UTC, Rares Pop wrote: What do you mean by copy/pasting ? I literally copied the code in your post (and fixed a missing semicolon) and got it to compile. Passing A as an argument to injections should work. You can also use this and typeof(this) inside the injections template code to access the class. It should all work. Taking this one step further, it looks like the attributes are not available at the mixin scope. Here is my code: -- struct Inject { //immutable Scope scoped; } static string injections(T)() { pragma(msg, injections for : , T); string result; foreach(member; __traits(allMembers,T)) { import std.string; enum fullName = format(%s.%s, T.stringof, member); pragma(msg, member: , fullName); auto attributes = __traits(getAttributes, fullName); You must mixin fullName: auto attributes = __traits(getAttributes, mixin(fullName)); enum dbg_msg = format (%s attributes are %s, fullName, attributes.stringof); pragma(msg, dbg_msg); foreach(attr;attributes){ Replace the body of this foreach with the following: pragma(msg, Checking attribute of type, typeof(attr)); static if (is (typeof(attr) == Inject)) { pragma(msg, Found one); // Let's inject something: result ~= q{ int foo() { return 42; } }; } pragma(msg, Checking attribute, attr); } } return result; } class A { this(){ } } class B { @Inject A a; For an unknown reason to me, that UDA wants an Inject object, not the type itself: @Inject() A a; I am puzzled with that... mixin(injections!(B)); } Then it works with the following main: void main() { auto b = new B(); assert(b.foo() == 42);// It worked! :) } Here is the complete program: struct Inject { //immutable Scope scoped; } static string injections(T)() { pragma(msg, injections for : , T); string result; foreach(member; __traits(allMembers,T)) { import std.string; enum fullName = format(%s.%s, T.stringof, member); pragma(msg, member: , fullName); auto attributes = __traits(getAttributes, mixin(fullName)); enum dbg_msg = format (%s attributes are %s, fullName, attributes.stringof); pragma(msg, dbg_msg); foreach(attr;attributes){ pragma(msg, Checking attribute of type, typeof(attr)); static if (is (typeof(attr) == Inject)) { pragma(msg, Found one); // Let's inject something: result ~= q{ int foo() { return 42; } }; } } } return result; } class A { this(){ } } class B { @Inject() A a; mixin(injections!(B)); } void main() { auto b = new B(); assert(b.foo() == 42);// It worked! :) } Ali
Re: Generating code based on UDA
Ali, Many thanks for your help. What is the rationale for mixin(fullName) ?
Re: Pragma mangle and D shared objects
That looks like exactly the solution I need, very clever. It'll take some time to wrap my head around it :-P
Re: Generating code based on UDA
Ali, Many thanks for your help. Indeed it worked. What is the rationale behind the mixin(fullName) ? However, in my project the injections function, the @Inject UDA struct and some other dependencies are defined in a library (libinfuse). In this format the compiler gives the undefined identifier error I was mentioning in my first post. source/infuse/injector.d-mixin-148(148): Error: undefined identifier B From what I read in the documentation, source mixins should have the instantiation scope. Is this a dmd compiler bug? Thanks again for your input guys, Rares
Re: Generating code based on UDA
I've uploaded the code here: https://github.com/fusionbeam/infuse
Re: Two cases for improving error messages
On Sat, Oct 25, 2014 at 8:00 PM, H. S. Teoh via Digitalmars-d-learn digitalmars-d-learn@puremagic.com wrote: I agree with submitting both of these as enhancement requests. Please tag them with diagnostic in the keywords field. Done: https://issues.dlang.org/show_bug.cgi?id=13655 https://issues.dlang.org/show_bug.cgi?id=13656 You did say *requests* in the plural so I filed them separately. -- Shriramana Sharma ஶ்ரீரமணஶர்மா श्रीरमणशर्मा
Re: Pragma mangle and D shared objects
On 2014-10-25 11:56, Etienne Cimon wrote: That looks like exactly the solution I need, very clever. It'll take some time to wrap my head around it :-P Just brainstorming here, but I think every dynamic library should hold a utility container (hash map?) that searches for and returns the mangled names in itself using regex match. This container would always be in the same module/function name in every dynamic library. The mangling list would load itself using introspection through a `shared static this()`. For each module, for each class, insert mangling in the hashmap... This seems ideal because then you basically have libraries that document themselves at runtime. Of course, the return type and arguments would have to be decided in advance, but otherwise it allows loading and use of (possibly remote and unknown) DLLs, in a very simple way.
Re: Generating code based on UDA
On Saturday, 25 October 2014 at 16:01:29 UTC, Rares Pop wrote: I've uploaded the code here: https://github.com/fusionbeam/infuse compiling with ldc2 exhibits the same behaviour. 'Error: undefined identifier B'
Does it make sense to add attribute to operator overload functions ?
Everything is in the Q. I ask this because those functions are hidden behind symbols and keywords (+=, ~, in, etc.). It's not that obvious for a user who would write a custom type. e.g: --- struct myType { @safe nothrow opIndexAssign(t1 paramValue,t2 paramIndex){} } --- are the attributes necessary ? Are opXXX functions handled just like any other functs ? (traversal compat. of the attribs)
Re: Does it make sense to add attribute to operator overload functions ?
On Saturday, 25 October 2014 at 17:14:51 UTC, Jkpl wrote: Everything is in the Q. I ask this because those functions are hidden behind symbols and keywords (+=, ~, in, etc.). It's not that obvious for a user who would write a custom type. e.g: --- struct myType { @safe nothrow opIndexAssign(t1 paramValue,t2 paramIndex){} } --- are the attributes necessary ? Are opXXX functions handled just like any other functs ? (traversal compat. of the attribs) In every aspect they are ordinary functions, except they each have an additional unique way of being called (the relevant operator syntax). In short, yes.
Re: Pragma mangle and D shared objects
On Sat, Oct 25, 2014 at 12:15:19PM -0400, Etienne Cimon via Digitalmars-d-learn wrote: On 2014-10-25 11:56, Etienne Cimon wrote: That looks like exactly the solution I need, very clever. It'll take some time to wrap my head around it :-P It's not that complicated, really. It's basically putting together 3 things: 1) .mangleof to extract a mangled symbol from some function declaration 2) regex to replace the function name in the mangled symbol 3) compile-time introspection to build a function declaration out of a user-specified signature. Just brainstorming here, but I think every dynamic library should hold a utility container (hash map?) that searches for and returns the mangled names in itself using regex match. This container would always be in the same module/function name in every dynamic library. Actually, the object file (library) itself should already have a list of exported symbols; you could then use core.demangle to extract the function signatures from the mangled symbols and construct a hash of all exported symbols and their types. The only thing is, I don't know of any cross-platform method of retrieving the list of exported symbols -- the Posix dlsym() family of functions only allow lookup by explicit symbol name, no iteration primitives are specified. But the information is definitely there, since that's how the OS's dynamic linker figures out how to link dynamic libraries in the first place! [...] Of course, the return type and arguments would have to be decided in advance, but otherwise it allows loading and use of (possibly remote and unknown) DLLs, in a very simple way. Well, generally, in order to make use of the functions in the first place, you'd need some kind of pre-determined return type and parameter types, otherwise the program couldn't possibly know how to pass arguments or interpret the return value! But if you could extract the list of exported symbols from a library, then you could demangle them to determine their signatures, and thereby find all symbols matching some given signature. T -- Curiosity kills the cat. Moral: don't be the cat.
Re: Two cases for improving error messages
On 10/25/14 7:44 AM, Shriramana Sharma via Digitalmars-d-learn wrote: Hello. Please see the following and say whether they're OK to submit as bugs for improving the error messages. Thanks. ref int foo(ref int x) { return x ; } void main () { foo(3) ; // Error: function rvalue_argument.foo (ref int x) is not callable using argument types (int) // Comment: argument ref int x of function rvalue_argument.foo cannot bind to an rvalue would be clearer IMO int i ; ref ir = i ; // Error: variable ref_type.main.ir only parameters or foreach declarations can be ref // Comment: add , return values after parameters } I think both are clearer, please submit bugs! BTW, don't be shy about submitting bugs, most of the devs watch the bug list and pick up on things that are just not going to happen. Worst case is that your bug just gets closed as wontfix. -Steve
Re: Does it make sense to add attribute to operator overload functions ?
On Saturday, 25 October 2014 at 18:38:12 UTC, John Colvin wrote: On Saturday, 25 October 2014 at 17:14:51 UTC, Jkpl wrote: Everything is in the Q. I ask this because those functions are hidden behind symbols and keywords (+=, ~, in, etc.). It's not that obvious for a user who would write a custom type. e.g: --- struct myType { @safe nothrow opIndexAssign(t1 paramValue,t2 paramIndex){} } --- are the attributes necessary ? Are opXXX functions handled just like any other functs ? (traversal compat. of the attribs) In every aspect they are ordinary functions, except they each have an additional unique way of being called (the relevant operator syntax). In short, yes. Thx, A bit less confused by them now.
HTML Parsing lib
I found only https://github.com/Bystroushaak/DHTMLParser But I can't get it work: C:\Users\Dima\Downloads\DHTMLParser-master\DHTMLParser-masterdmd find_links.d OPTLINK (R) for Win32 Release 8.00.15 Copyright (C) Digital Mars 1989-2013 All rights reserved. http://www.digitalmars.com/ctg/optlink.html find_links.obj(find_links) Error 42: Symbol Undefined _D11dhtmlparser11parseStringFAyaZC11dhtmlparser11HTM LElement find_links.obj(find_links) Error 42: Symbol Undefined _D11dhtmlparser12__ModuleInfoZ --- errorlevel 2 Is there any other HTML parsing lib, or maybe someone do know how to get it's work. Look like it's not compatible with current version of DMD
Re: HTML Parsing lib
On Saturday, 25 October 2014 at 19:46:01 UTC, MrSmith wrote: On Saturday, 25 October 2014 at 19:44:25 UTC, Suliman wrote: I found only https://github.com/Bystroushaak/DHTMLParser But I can't get it work: C:\Users\Dima\Downloads\DHTMLParser-master\DHTMLParser-masterdmd find_links.d OPTLINK (R) for Win32 Release 8.00.15 Copyright (C) Digital Mars 1989-2013 All rights reserved. http://www.digitalmars.com/ctg/optlink.html find_links.obj(find_links) Error 42: Symbol Undefined _D11dhtmlparser11parseStringFAyaZC11dhtmlparser11HTM LElement find_links.obj(find_links) Error 42: Symbol Undefined _D11dhtmlparser12__ModuleInfoZ --- errorlevel 2 Is there any other HTML parsing lib, or maybe someone do know how to get it's work. Look like it's not compatible with current version of DMD You need to pass a library to compiler as well (all its files or .lib/.a file) if it is compiled as static library You can try dmd find_links.d dhtmlparser.d quote_escaper.d
Re: HTML Parsing lib
On Saturday, 25 October 2014 at 19:44:25 UTC, Suliman wrote: I found only https://github.com/Bystroushaak/DHTMLParser But I can't get it work: C:\Users\Dima\Downloads\DHTMLParser-master\DHTMLParser-masterdmd find_links.d OPTLINK (R) for Win32 Release 8.00.15 Copyright (C) Digital Mars 1989-2013 All rights reserved. http://www.digitalmars.com/ctg/optlink.html find_links.obj(find_links) Error 42: Symbol Undefined _D11dhtmlparser11parseStringFAyaZC11dhtmlparser11HTM LElement find_links.obj(find_links) Error 42: Symbol Undefined _D11dhtmlparser12__ModuleInfoZ --- errorlevel 2 Is there any other HTML parsing lib, or maybe someone do know how to get it's work. Look like it's not compatible with current version of DMD You need to pass a library to compiler as well (all its files or .lib/.a file) if it is compiled as static library
Re: HTML Parsing lib
You need to pass a library to compiler as well (all its files or .lib/.a file) if it is compiled as static library You can try dmd find_links.d dhtmlparser.d quote_escaper.d C:\Users\Dima\Downloads\DHTMLParser-master\DHTMLParser-masterdmd find_links.d quote_escaper.d OPTLINK (R) for Win32 Release 8.00.15 Copyright (C) Digital Mars 1989-2013 All rights reserved. http://www.digitalmars.com/ctg/optlink.html find_links.obj(find_links) Error 42: Symbol Undefined _D11dhtmlparser11parseStringFAyaZC11dhtmlparser11HTM LElement find_links.obj(find_links) Error 42: Symbol Undefined _D11dhtmlparser12__ModuleInfoZ --- errorlevel 2
Re: HTML Parsing lib
On Saturday, 25 October 2014 at 19:51:48 UTC, Suliman wrote: You need to pass a library to compiler as well (all its files or .lib/.a file) if it is compiled as static library You can try dmd find_links.d dhtmlparser.d quote_escaper.d C:\Users\Dima\Downloads\DHTMLParser-master\DHTMLParser-masterdmd find_links.d quote_escaper.d OPTLINK (R) for Win32 Release 8.00.15 Copyright (C) Digital Mars 1989-2013 All rights reserved. http://www.digitalmars.com/ctg/optlink.html find_links.obj(find_links) Error 42: Symbol Undefined _D11dhtmlparser11parseStringFAyaZC11dhtmlparser11HTM LElement find_links.obj(find_links) Error 42: Symbol Undefined _D11dhtmlparser12__ModuleInfoZ --- errorlevel 2 Sorry I missed dhtmlparser.d
Re: HTML Parsing lib
How I can build such App with DUB?
Re: HTML Parsing lib
On Saturday, 25 October 2014 at 19:55:10 UTC, Suliman wrote: How I can build such App with DUB? Unfortunately that library has no dub package. But you can include it in your project. See info here http://code.dlang.org/package-format
Re: Pragma mangle and D shared objects
On Saturday, 25 October 2014 at 18:40:23 UTC, H. S. Teoh via Digitalmars-d-learn wrote: Actually, the object file (library) itself should already have a list of exported symbols; you could then use core.demangle to extract the function signatures from the mangled symbols and construct a hash of all exported symbols and their types. The only thing is, I don't know of any cross-platform method of retrieving the list of exported symbols -- the Posix dlsym() family of functions only allow lookup by explicit symbol name, no iteration primitives are specified. But the information is definitely there, since that's how the OS's dynamic linker figures out how to link dynamic libraries in the first place! T I wonder what nm uses. AFAIK it works on everything posix.
Re: HTML Parsing lib
Another option for html is my dom.d https://github.com/adamdruppe/arsd get dom.d and characterencodings.d in your project directory. compile with dmd yourfile.d dom.d characterencodings.d here's an example: import arsd.dom; void main() { auto document = new Document(); // The example document will be defined inline here // We could also load the string from a file with // std.file.readText or the web with std.net.curl.get document.parseGarbage(`htmlhead meta name=author content=Adam D. Ruppe titleTest Document/title /head body pThis is the first paragraph of our a href=test.htmltest document/a. pThis second paragraph also has a a href=test2.htmllink/a. p id=custom-paragraphOld text/p /body /html`); import std.stdio; // retrieve and print some meta information writeln(document.title); writeln(document.getMeta(author)); // show a paragraphâs text writeln(document.requireSelector(p).innerText); // modify all links document[a[href]].setValue(source, your-site); // change some html document.requireElementById(custom-paragraph).innerHTML = New bHTML/b!; // show the new document writeln(document.toString()); } You can replace the html string with something like std.file.readText(yourfile.html); too My library is meant to give an api similar to javascript. I don't use dub so idk about how to use that, I just recommend adding my files to your project if you wanna try it.
Re: Generating code based on UDA
On 10/25/2014 08:56 AM, Rares Pop wrote: Indeed it worked. What is the rationale behind the mixin(fullName) ? __traits(getAttributes) requires a symbol but fullName is a string. Mixing it in as code fulfills the requirement. However, in my project the injections function, the @Inject UDA struct and some other dependencies are defined in a library (libinfuse). I am afraid it needs to be changed. :-/ In this format the compiler gives the undefined identifier error I was mentioning in my first post. source/infuse/injector.d-mixin-148(148): Error: undefined identifier B I found two solutions: a) Do not define 'attributes' at all and use __traits(getAttributes) directly in the foreach loop: foreach (attr; __traits(getAttributes, mixin(fullName))) { b) Define attributes as a typeof of __traits(getAttributes) and use that in the foreach loop: alias attributes = typeof(__traits(getAttributes, mixin(fullName))); foreach (attr; attributes) { I think what happens in both cases is that the entity that we iterate over maintains its TypeTuple'ness without trying to produce a value out of its members. Is this a dmd compiler bug? I don't know but it is very confusing. Ali
Where is a variable declared in a module allocated?
Where is a variable declared in a module allocated? is it same as a C's global? for example: module foo; int myvar;
Re: Where is a variable declared in a module allocated?
On Saturday, 25 October 2014 at 21:52:13 UTC, MachineCode wrote: Where is a variable declared in a module allocated? is it same as a C's global? for example: module foo; int myvar; that is in thread local storage. __shared, shared or immutable cause the variable to be in classic global storage like in C. See: http://dlang.org/migrate-to-shared.html
Re: Pragma mangle and D shared objects
On Sat, Oct 25, 2014 at 08:05:18PM +, John Colvin via Digitalmars-d-learn wrote: On Saturday, 25 October 2014 at 18:40:23 UTC, H. S. Teoh via Digitalmars-d-learn wrote: Actually, the object file (library) itself should already have a list of exported symbols; you could then use core.demangle to extract the function signatures from the mangled symbols and construct a hash of all exported symbols and their types. The only thing is, I don't know of any cross-platform method of retrieving the list of exported symbols -- the Posix dlsym() family of functions only allow lookup by explicit symbol name, no iteration primitives are specified. But the information is definitely there, since that's how the OS's dynamic linker figures out how to link dynamic libraries in the first place! T I wonder what nm uses. AFAIK it works on everything posix. Not sure what nm uses, but a lot of posix tools for manipulating object files are based on binutils, which understands the local system's object file format and deal directly with the binary representation. The problem is, I don't know of any *standard* system functions that can do this, so you'd have to rely on OS-specific stuff to make it work, which is less than ideal. T -- Indifference will certainly be the downfall of mankind, but who cares? -- Miquel van Smoorenburg
Re: Pragma mangle and D shared objects
On 2014-10-25 21:26, H. S. Teoh via Digitalmars-d-learn wrote: Not sure what nm uses, but a lot of posix tools for manipulating object files are based on binutils, which understands the local system's object file format and deal directly with the binary representation. The problem is, I don't know of any *standard* system functions that can do this, so you'd have to rely on OS-specific stuff to make it work, which is less than ideal. Which makes it better to export the mangling into a container at compile-time! That way, you can build a standard interface into DLLs so that other D application know what they can call =)
Re: Pragma mangle and D shared objects
On Sat, Oct 25, 2014 at 10:54:53PM -0400, Etienne Cimon via Digitalmars-d-learn wrote: On 2014-10-25 21:26, H. S. Teoh via Digitalmars-d-learn wrote: Not sure what nm uses, but a lot of posix tools for manipulating object files are based on binutils, which understands the local system's object file format and deal directly with the binary representation. The problem is, I don't know of any *standard* system functions that can do this, so you'd have to rely on OS-specific stuff to make it work, which is less than ideal. Which makes it better to export the mangling into a container at compile-time! That way, you can build a standard interface into DLLs so that other D application know what they can call =) Hmm. You can probably use __traits(getAllMembers...) to introspect a library module at compile-time and build a hash based on that, so that it's completely automated. If you have this available as a mixin, you could just mixin(exportLibrarySymbols()) in your module to produce the hash. T -- Holy war is an oxymoron. -- Lazarus Long
Re: Generating code based on UDA
I think it is a bug. Executing linked code from a mixin statement should not reduce the scope of the mixin, IMHO. I will file a bug report. On Saturday, 25 October 2014 at 21:35:44 UTC, Ali Çehreli wrote: On 10/25/2014 08:56 AM, Rares Pop wrote: Indeed it worked. What is the rationale behind the mixin(fullName) ? __traits(getAttributes) requires a symbol but fullName is a string. Mixing it in as code fulfills the requirement. However, in my project the injections function, the @Inject UDA struct and some other dependencies are defined in a library (libinfuse). I am afraid it needs to be changed. :-/ In this format the compiler gives the undefined identifier error I was mentioning in my first post. source/infuse/injector.d-mixin-148(148): Error: undefined identifier B I found two solutions: a) Do not define 'attributes' at all and use __traits(getAttributes) directly in the foreach loop: foreach (attr; __traits(getAttributes, mixin(fullName))) { b) Define attributes as a typeof of __traits(getAttributes) and use that in the foreach loop: alias attributes = typeof(__traits(getAttributes, mixin(fullName))); foreach (attr; attributes) { I think what happens in both cases is that the entity that we iterate over maintains its TypeTuple'ness without trying to produce a value out of its members. Is this a dmd compiler bug? I don't know but it is very confusing. Ali
[Issue 1317] Document suggested means of overlapping array copy
https://issues.dlang.org/show_bug.cgi?id=1317 github-bugzi...@puremagic.com changed: What|Removed |Added Status|NEW |RESOLVED Resolution|--- |FIXED --
[Issue 1317] Document suggested means of overlapping array copy
https://issues.dlang.org/show_bug.cgi?id=1317 --- Comment #6 from github-bugzi...@puremagic.com --- Commits pushed to master at https://github.com/D-Programming-Language/dlang.org https://github.com/D-Programming-Language/dlang.org/commit/2387953b9a67b6d7945c87106c42c9a07ba22cce Fix Issue 1317 - Document suggested means of overlapping array copy https://github.com/D-Programming-Language/dlang.org/commit/633f65606181d1e7c821420e72d59d6806b54ecc Merge pull request #680 from ntrel/array-overlap Fix Issue 1317 - Document suggested means of overlapping array copy --
[Issue 1448] UTF-8 output to console is seriously broken
https://issues.dlang.org/show_bug.cgi?id=1448 Sum Proxy sum.pr...@gmail.com changed: What|Removed |Added CC||sum.pr...@gmail.com Hardware|x86_64 |x86 --- Comment #12 from Sum Proxy sum.pr...@gmail.com --- The issue still exists in DMD32 D Compiler v2.065, Windows 7 == Code: == import std.stdio; import std.c.windows.windows; extern(Windows) BOOL SetConsoleOutputCP( UINT ); void main() { SetConsoleOutputCP( 65001 ); // or use chcp 65001 instead stderr.write(STDERR:Output utf-8 accented char \u00e9\n... and the rest is cut off!\n); stderr.write(end_STDERR.\n); } == Output: == STDERR:Output utf-8 accented char é ... and the rest is cut off! == end_STDERR.\n is not written --
[Issue 12990] utf8 string not read/written to windows console
https://issues.dlang.org/show_bug.cgi?id=12990 --- Comment #11 from Sum Proxy sum.pr...@gmail.com --- I tried the new version of the compiler with the issue you referred to, but alas - no luck. Please see https://issues.dlang.org/show_bug.cgi?id=1448#c12 SetConsoleCP(65001) and SetConsoleOutputCP(65001) didn't help either. Thanks. --
[Issue 12990] utf8 string not read/written to windows console
https://issues.dlang.org/show_bug.cgi?id=12990 Vladimir Panteleev thecybersha...@gmail.com changed: What|Removed |Added Hardware|x86_64 |All --- Comment #12 from Vladimir Panteleev thecybersha...@gmail.com --- Indeed. Happens with both DMC and MSVC runtime. --
[Issue 12990] utf8 string not read/written to windows console
https://issues.dlang.org/show_bug.cgi?id=12990 --- Comment #13 from Vladimir Panteleev thecybersha...@gmail.com --- scanf misbehaves in the same way. Not a D bug, I think. --
[Issue 13652] New: 2D Static Array Init produces wrong result (-m64/-m32)
https://issues.dlang.org/show_bug.cgi?id=13652 Issue ID: 13652 Summary: 2D Static Array Init produces wrong result (-m64/-m32) Product: D Version: D2 Hardware: x86_64 OS: All Status: NEW Severity: enhancement Priority: P1 Component: DMD Assignee: nob...@puremagic.com Reporter: shammah.chancel...@gmail.com Created attachment 1448 -- https://issues.dlang.org/attachment.cgi?id=1448action=edit Test case The attached code produces an array which is initialized improperly when compiled with: dmd64 -m32 test.d or dmd32 -m64 test.d --
[Issue 13652] 2D Static Array Init produces wrong result (-m64/-m32)
https://issues.dlang.org/show_bug.cgi?id=13652 Shammah Chancellor shammah.chancel...@gmail.com changed: What|Removed |Added Priority|P1 |P5 CC||shammah.chancel...@gmail.co ||m Severity|enhancement |critical --
[Issue 12990] utf8 string not read/written to windows console
https://issues.dlang.org/show_bug.cgi?id=12990 --- Comment #14 from Sum Proxy sum.pr...@gmail.com --- Do you find it necessary to report the issue elsewhere, or the guys in charge of https://issues.dlang.org/show_bug.cgi?id=1448 will do it? --
[Issue 13652] 2D Static Array Init produces wrong result (-m64/-m32)
https://issues.dlang.org/show_bug.cgi?id=13652 bearophile_h...@eml.cc changed: What|Removed |Added CC||bearophile_h...@eml.cc --- Comment #1 from bearophile_h...@eml.cc --- This seems a reduced test case: void main() { uint[9][5] arr = [ [0, 0, 0, 0, 1, 5, 8, 0, 7], [0, 3, 8, 0, 2, 0, 0, 6, 0], [0, 0, 7, 0, 6, 8, 9, 4, 0], [0, 0, 0, 0, 0, 1, 2, 9, 0], [9, 7, 0, 0, 0, 0, 0, 8, 3]]; import std.stdio: writeln; arr.writeln; } --
[Issue 13653] New: Better error messages for mismatched array literals
https://issues.dlang.org/show_bug.cgi?id=13653 Issue ID: 13653 Summary: Better error messages for mismatched array literals Product: D Version: D2 Hardware: x86 OS: Windows Status: NEW Severity: enhancement Priority: P1 Component: DMD Assignee: nob...@puremagic.com Reporter: bearophile_h...@eml.cc void main() { uint[1][2] arr1 = [[0, 0]]; int[2] arr2 = [1.5, 2.5]; } DMD 2.067alpha gives a strange error messages: test.d(2,23): Error: cannot implicitly convert expression ([[0, 0]]) of type int[][] to uint[] test.d(3,19): Error: cannot implicitly convert expression ([1.5, 2.5]) of type double[] to int[] But I suggest to give more clear error message, something like: test.d(2,23): Error: array sizes mismatch, cannot implicitly convert array literal of shape (2, 1) to shape (1, 2) test.d(3,19): Error: cannot implicitly convert expression ([1.5, 2.5]) of type double[] to int[2] --
[Issue 12990] utf8 string not read/written to windows console
https://issues.dlang.org/show_bug.cgi?id=12990 --- Comment #15 from Vladimir Panteleev thecybersha...@gmail.com --- Report it where? To Microsoft? Figuring out why scanf is failing would probably be the next step to resolving this. --
[Issue 12990] utf8 string not read/written to windows console
https://issues.dlang.org/show_bug.cgi?id=12990 --- Comment #16 from Sum Proxy sum.pr...@gmail.com --- Are you referring to C's scanf? Is it consistently reproducible in a small chunk of C code? --
[Issue 13522] Let's use '_' underscore as official ignore value
https://issues.dlang.org/show_bug.cgi?id=13522 --- Comment #5 from bearophile_h...@eml.cc --- There are plans to totally disallow the use of _ as variable name in Java: http://openjdk.java.net/jeps/213 In addition, using underscore (_) as an identifier, which generates a warning as of Java SE 8, should be turned into an error in Java SE 9. --
[Issue 12990] utf8 string not read/written to windows console
https://issues.dlang.org/show_bug.cgi?id=12990 --- Comment #17 from Vladimir Panteleev thecybersha...@gmail.com --- Yep: /// test.c /// void main() { char buf[1024]; SetConsoleCP(65001); SetConsoleOutputCP(65001); scanf(%s, buf); printf(%d, strlen(buf)); } // --
[Issue 13654] New: @nogc std.algorithm.enumerate
https://issues.dlang.org/show_bug.cgi?id=13654 Issue ID: 13654 Summary: @nogc std.algorithm.enumerate Product: D Version: D2 Hardware: x86 OS: Windows Status: NEW Keywords: rejects-valid Severity: enhancement Priority: P1 Component: Phobos Assignee: nob...@puremagic.com Reporter: bearophile_h...@eml.cc void main() @nogc { import std.algorithm: enumerate; int[1] arr; auto r = arr[].enumerate; } DMD 2.067alpha gives: test.d(4,19): Error: @nogc function 'D main' cannot call non-@nogc function 'std.range.enumerate!(uint, int[]).enumerate' --
[Issue 13655] New: clarify that a ref parameter cannot bind to an rvalue
https://issues.dlang.org/show_bug.cgi?id=13655 Issue ID: 13655 Summary: clarify that a ref parameter cannot bind to an rvalue Product: D Version: D2 Hardware: x86_64 OS: Linux Status: NEW Keywords: diagnostic Severity: enhancement Priority: P1 Component: DMD Assignee: nob...@puremagic.com Reporter: samj...@gmail.com Hello. The following code: ref int foo(ref int x) { return x ; } void main () { foo(3) ; } produces the error message: function rvalue_argument.foo (ref int x) is not callable using argument types (int) It would be more meaningful if this could be clarified on the lines of: argument ref int x of function rvalue_argument.foo cannot bind to an rvalue --
[Issue 13656] New: clarify error message upon trying to declare a variable of type ref
https://issues.dlang.org/show_bug.cgi?id=13656 Issue ID: 13656 Summary: clarify error message upon trying to declare a variable of type ref Product: D Version: D2 Hardware: x86_64 OS: Linux Status: NEW Keywords: diagnostic Severity: enhancement Priority: P1 Component: DMD Assignee: nob...@puremagic.com Reporter: samj...@gmail.com Hello. The following code: void main () { int i ; ref ir = i ; } produces the following error message: variable ref_type.main.ir only parameters or foreach declarations can be ref The sentence is unclear variable x only ... can be ref. What is meant is Attempt to declare variable of type ref. Please clarify this. Also, please add , return values after parameters in the above error message since code like: ref int foo(ref int x) { return x ; } is permitted. --
[Issue 13657] New: Bidirectional File.byLine range
https://issues.dlang.org/show_bug.cgi?id=13657 Issue ID: 13657 Summary: Bidirectional File.byLine range Product: D Version: D2 Hardware: x86 OS: Windows Status: NEW Severity: enhancement Priority: P1 Component: Phobos Assignee: nob...@puremagic.com Reporter: bearophile_h...@eml.cc Currently this works as expected with dmd 2.067alpha: void main() { import std.stdio: writeln, File, stdin; import std.range: retro; import std.array: array; test.d.File.byLine.array.retro.writeln; } But this: void main() { import std.stdio: writeln, File, stdin; import std.range: retro; test.d.File.byLine.retro.writeln; } test.d(4,25): Error: template std.range.retro cannot deduce function from argument types !()(ByLine!(char, char)), candidates are: ...\dmd2\src\phobos\std\range.d(1966,6):std.range.retro(Range)(Range r) if (isBidirectionalRange!(Unqual!Range)) Perhaps File.byLine and File.byLineCopy can support reverse iteration of the lines of a file. --
[Issue 12990] utf8 string not read/written to windows console
https://issues.dlang.org/show_bug.cgi?id=12990 --- Comment #18 from Sum Proxy sum.pr...@gmail.com --- From what I know this program will work incorrectly for any non-ascii unicode input, which I have confirmed through simple tests. scanf and strlen rely on '\0' to indicate string termination, but I don't think this goes well with unicode strings. I believe the right way to do something similar (without buffer length) is this: #include stdio.h #include fcntl.h #include io.h int main( void ) { wchar_t buf[1024]; _setmode( _fileno( stdin ), _O_U16TEXT ); _setmode( _fileno( stdout ), _O_U16TEXT ); wscanf( L%ls, buf ); wprintf( L%s, buf ); } For further info please refer to http://www.siao2.com/2008/03/18/8306597.aspx and http://msdn.microsoft.com/en-us/library/tw4k6df8%28v=vs.120%29.aspx HTH, Thanks. --
[Issue 12990] utf8 string not read/written to windows console
https://issues.dlang.org/show_bug.cgi?id=12990 --- Comment #19 from Vladimir Panteleev thecybersha...@gmail.com --- (In reply to Sum Proxy from comment #18) scanf and strlen rely on '\0' to indicate string termination, but I don't think this goes well with unicode strings. Not true. At least, not true with UTF-8, which is what we set the CP to. I believe the right way to do something similar (without buffer length) is this: I would not say that's the right way. That's the way to read wchar_t text, but we need UTF-8 text. --
[Issue 13658] New: Array length type is not size_t
https://issues.dlang.org/show_bug.cgi?id=13658 Issue ID: 13658 Summary: Array length type is not size_t Product: D Version: D2 Hardware: All OS: Windows Status: NEW Severity: normal Priority: P1 Component: DMD Assignee: nob...@puremagic.com Reporter: marki...@umich.edu According to the language reference at: http://dlang.org/arrays, the .length property of an array is meant to return a value with type size_t. That is not the case on Windows with dmd 2.066. This issue is more widespread than just the .length property; I discovered this by trying to index an array with a ulong (same type as size_t) and found dmd yelling about implicit conversions to uint. The problematic code was of the form: myArray[thingThatReturnsULong() - 1 - 1]; For reference, the precise line of code that breaks: https://github.com/facebook/flint/blob/master/Checks.d#L3016 I confirmed the types of size_t, myArray.length, and a few other things using pragma(msg, typeof(thing)); For what it's worth, if you pointed me at roughly the write part of the code that needed fixing, I would gladly make the change; I wasn't able to find the relevant code in druntime and the dmd repo is a mystery to me. --
[Issue 12447] variadic template functions hijack all eponymous enum and alias template overloads
https://issues.dlang.org/show_bug.cgi?id=12447 Kenji Hara k.hara...@gmail.com changed: What|Removed |Added Keywords||pull, rejects-valid --- Comment #1 from Kenji Hara k.hara...@gmail.com --- https://github.com/D-Programming-Language/dmd/pull/4091 --