Re: this is null
On Sunday, 10 March 2019 at 14:25:56 UTC, spir wrote: There is a typo in this instruction: T* ptr = this.list.getFisrtFreeOrAdd(memViewLen).getPtr!T(); ^^ rs (may this explain your null? the compiler should complain) diniz Good catch! But I have the same typo within the definition of the method. I believe DMD screams about undefined method if it happens.
Re: this is null
On Saturday, 9 March 2019 at 21:00:51 UTC, Ali Çehreli wrote: I haven't run the code but which pointer is null? Try adding I mean `this` by "this" word. You can see that `this` is null if you run gdb and before that line make `p/x this` [0] this check as well: auto node = this.list.getFisrtFreeOrAdd(memViewLen); assert(node !is null); I get segfault in `getFisrtFreeOrAdd` method. Before the line I have an assertion [1]. It looks like the program misses (I have no idea how) `list` object while calling its method `getFisrtFreeOrAdd`. [0] https://github.com/ANtlord/deadmemory/blob/master/src/deadmemory/freelist.d#L56 [1] https://github.com/ANtlord/deadmemory/blob/master/src/deadmemory/mem.d#L19
Re: this is null
On Saturday, 9 March 2019 at 20:04:53 UTC, Paul Backus wrote: struct S { bool isThisNull() { return is null; } } void main() { import.std.stdio; S* p = null; writeln((*p).isThisNull); // true } Interactive version: https://run.dlang.io/is/fgT2rS Anyway, thank you! I didn't know about the feature.
Re: this is null
On Saturday, 9 March 2019 at 20:04:53 UTC, Paul Backus wrote: You can end up with a null `this` reference if you dereference a null pointer to a struct and then call a method on the result. For example: I can but my reference is not null before calling. Take a look at the line of code [0]. There is a check before the line. https://github.com/ANtlord/deadmemory/blob/master/src/deadmemory/mem.d#L20 [0]
this is null
Hello everyone! I've encountered the problem which I already encountered before. Unfortunately, I had no time in the previous time to report and to talk about it. So I decided to play making my own "malloc" function in pure D (betterC) at this time. And I encountered the issue one more time. `this` can be null. How? Please take a look at my project [0]. It gets the current heap break and tries to increase via a free list. So the segfault I meet happens there [1]. Tell me, please. What do I wrong? [0] https://github.com/ANtlord/deadmemory [1] https://github.com/ANtlord/deadmemory/blob/master/src/deadmemory/freelist.d#L56
Get variables with call stack
Hello! I need to make a some sort of error report system for an application. I want to catch base Exception class instance and report call stack and with the call stack I want to report all variables with their values. There are a couple of services that make report using call stack and provides variables' values. Sentry.io, New Relic etc. I see how to get call stack, the book Adam Ruppe writes helps me. How to get all variables from every layer of call stack?
Re: Windows 7 x64. Prevent appearing of console with GUI application
On Tuesday, 24 July 2018 at 09:20:22 UTC, Mike Parker wrote: On Tuesday, 24 July 2018 at 08:09:33 UTC, ANtlord wrote: Anyway, if you are using OPTLINK or the MS Linker, try a test program without gtkD to make sure it works standalone for you. ``` import core.sys.windows.windows; void main() { MessageBoxA(null, "Look, Ma! No console!", "It works!", MB_OK); } ``` You partially are right, the issue is related to the application internals but not to GTKD. I forgot that I launch the second application inside. I recompiled both of the with -L/SUBSYSTEM:windows -L/ENTRY:mainCRTStartup and that's it. Thanks a lot everyone!
Windows 7 x64. Prevent appearing of console with GUI application
Hello! I'm trying run my GUI application getting a console hidden. The application is on top of GTKD, compiled with dmd 2.081.1 in Windows 7 x64. I read a few threads on the forum and StackOverflow and I got that I need to add a module definition file [1] or to add -L/SUBSYSTEM:WINDOWS -L/ENTRY:mainCRTStartup options to compiler [2] or to add only /SUBSYSTEM:WINDOWS [3] or use a command getting console hidden [4]. Actually no one case works properly. The first one doesn't affect, the second "unbinds" appeared console giving ability to close it without closing the application, the third one raises a linker error about unresolved symbol WinMain, the fourth one hides a console but it does it with delay. Also, I tried to use `editbin /SUBSYSTEM:windows myapp.exe` but I it doesn't affect anything. Here is my dub.json [5] So... how prevent appearing of console on the startup of the application? [1] https://wiki.dlang.org/D_for_Win32 [2] https://forum.dlang.org/post/bhswtzoklrzzslliq...@forum.dlang.org [3] https://forum.dlang.org/post/qcejigllwticykoiw...@forum.dlang.org [4] https://stackoverflow.com/a/2139903 [5] http://vpaste.net/mEy2P
GTKD release event in windows
Hello! Has somebody ever encountered continually triggering of key released event while the key is pressed with GTKD? I have the same issue for key pressed event but it's not so critical for me. The problem is occurred for all key keys except a key-modifier like alt, ctrl and shift. Also, it is occurred for Windows only, I don't see the problem using Linux. DMD 2.079 GTK 3.22.1 Windows 7 Unfortunately I can't find version of GTKD with windows Thanks in advance!
Re: DerelictVorbis and string pointer
On Sunday, 24 June 2018 at 01:54:52 UTC, Nicholas Wilson wrote: On Sunday, 24 June 2018 at 01:43:41 UTC, ANtlord wrote: On Sunday, 24 June 2018 at 01:26:48 UTC, ANtlord wrote: Actually I get it worked replacing `string filepath2` by `char[] filepath2` but filepath is string still and it works correctly. It doesn't work Vorbis is a C library, so you need to null terminate your string using toStringz. The reason why the one from the command line works is because it is already null terminate. It works! Thank you!
Re: DerelictVorbis and string pointer
On Sunday, 24 June 2018 at 01:26:48 UTC, ANtlord wrote: Actually I get it worked replacing `string filepath2` by `char[] filepath2` but filepath is string still and it works correctly. It doesn't work
DerelictVorbis and string pointer
Hello D community! I'm developing an application that must work on audio especially playback Ogg files. So I took library DerelictVorbis [0] testing basic functions like `ov_fopen`. The tests were successful so I decided to implement core components of the application using D and Derelict libraries. Today I encountered a problem, the `ov_fopen` returns -1 instead of 0. It means that something goes wrong and the file that is pointed by a string is not opened. I figured out it so there is the error is not occurred when a file path is pointed by a string variable from CLI input arguments but it is occurred when the path is pointed by a string variable filled dynamically (for example file path is read from another file). Here code goes public import derelict.vorbis; public import derelict.vorbis.file; void main(string[] args) { DerelictVorbis.load(); DerelictVorbisFile.load(); OggVorbis_File _ovFile; immutable filepath = args[1]; import std.file; import std.string; string filepath2 = "./name.txt".readText.strip; assert(filepath2 == filepath); int res = ov_fopen(filepath2.ptr, &_ovFile); // res == -1 // int res = ov_fopen(filepath.ptr, &_ovFile); // res == 0 assert(res == 0, "ov_fopen returns %d".format(res)); } Actually I get it worked replacing `string filepath2` by `char[] filepath2` but filepath is string still and it works correctly. So what detail The devil is in? Is there an issue in DerelictVorbis or in compiler. Don't I know something about implementation of strings or pointers in D? Thanks in advance! DMD 2.080 DerelictVorbis 2.0.0-beta.2 [0] https://github.com/DerelictOrg/DerelictVorbis
Re: UFCS syntax I never saw before.
On Monday, 21 May 2018 at 18:53:19 UTC, Jonathan M Davis wrote: On Monday, May 21, 2018 14:00:55 ANtlord via Digitalmars-d-learn wrote: If someone wrote an good DIP on the subject, I expect that things could be accelerated, but it's not much a real paint point in practice, and the chances of @property actually ever meaning anything like it was originally intended to mean are pretty much zero. UFCS killed that. - Jonathan M Davis First of all thanks a lot for the response. It cleans something for me. I need a few time to think.
Re: UFCS syntax I never saw before.
On Monday, 21 May 2018 at 11:38:12 UTC, SrMordred wrote: After all this time I saw this: writeln = iota = 5; what?? I never saw that before! This is interesting, there is something useful that i can do with this kind of call? What the hell is this? I don't figure out why are there so many syntax features? It doesn't make the language more easier. Is it any reason to support 2 additional cases of function calling? We have no literal for a tuple but we call a function via 3 cases. I'm frustrated. D has a lot cool features, I like D, but that is one of those which make me doubt the language future. I don't play a big role in the project but I talk to all my python co-workers: "You know... so there so cool language, it's called D. It can do this and that... It supports convenient static typing so you definitely know what happens in a piece of code.". But something like this make doubt about what happens in a piece of code. There is static typing so I know that type a variable has, but I look at a method calling and I ask: "Is it data field? No. Is it property? No. Is it method? No. It's UFCS! Okay." And now I see that UFCS can works the same way as a property!
Global hotkey with GTK based application under Windows
Hello! I implement a GTK-D based application for Windows and Linux. In case of Linux there isn't any problem, I use binding[1] for libkeybinder. In case of Windows I can't find convinient way to implement global shortcuts. There is a way to get it done is use of WinAPI but it's not convinient by a couple of things. WinAPI provides RegisterHotKey method[2] but I have no idea how to get HWND using GTK-D. If I get it done I get a problem to handle it. Design of WinAPI means handling of hotkey in a loop like so[3]. I could get the thing done using tick callback[4] but I use the callback for another stuff, and I don't know whether GTK-D supports multiple tick callbacks, I can't get it at least. If anyone has an idea, please tell me because I ran out. Thanks in advance! [1] https://github.com/dhasenan/keybinder [2] https://msdn.microsoft.com/en-us/library/windows/desktop/ms646309.aspx [3] http://vpaste.net/FwhMD [4] http://gtk-d.dpldocs.info/gtk.Widget.Widget.addTickCallback.1.html
importPaths option in dub
Hello! I work using Linux. Is it possible to use environment variables like $HOME in option importPaths of Dub project file? I tried it but dub concatenates the path and current path so I get something like this /develop/project/$HOME/.dub/packages/gtk-d/generated/gtkd or /develop/project/~/.dub/packages/gtk-d/generated/gtkd. I can use $HOME in lflags-posix so it work perfectly. Dub 1.8.0 DMD 2.079 Thanks in advance!
Re: Building Derelict based application under windows
On Friday, 23 March 2018 at 01:18:02 UTC, Mike Parker wrote: On Thursday, 22 March 2018 at 20:51:36 UTC, ANtlord wrote: Thanks in advance. Please feel free to ask any question Your errors with the derelict libs are linker errors, with the early ones being this one: "warning LNK4003: invalid library format; library ignored" At the top of the output, DUB is warning you that you've put -m64 in the package file and shouldn't do that. I would guess that's your problem. The libraries are being compiled as 32-bit OMF, which is default on the prepackaged DMD binaries on Windows, but the -m64 in your dflags is causing your app to compile as 64-bit. Try taking -m64 out of your package file and put -ax86_64 on your DUB command line instead. Thanks a lot. I tried it later but forgot to write about it to the forum. I fixed it adding --arch=x86_64 so a command for building is `dub build --arch=x86_64`
Building Derelict based application under windows
Hello! First of all I don't know what my problem is but please don't close the thread and give me a chance. I have been working on DMD under Linux since I met D. Short time ago I got a reason to make an application for Windows. I took DerelictAL[1], DerelictOgg[2] and DerelictVorbis[3] implementing basic prototype under Linux. So everything ok under Linux. Unfortunately I get a couple of issue under Windows 7. The Windows is launched under VirtualBox. The first one is target architecture the application is compiled for. I installed DMD 2.079 and Visual Studio 2015.2 so I corrected sc.ini consider the article[4] from the wiki. The file has the content that is available by the link [5]. But I'm not sure that dmd compiles code for 64 bit architecture because an address of any pointer consists of 6 symbols instead of 16. A pointer in C++ application consists of 16 symbols. There is D code [6]. The second one is warnings and errors during compilation of my application. Typical messages shows up inability of linker to recognize any direlict library so there are a couple of errors about unresolved symbols of direlict libraries. Full list of errors and warnings is available by the link [7]. Please help me to figure out how I can fix the issue. I don't want use another language to create the application. My environment Windows 7 64bit (under VirtualBox) DMD 2.079 Visual Studio 2015.2 [1] https://github.com/DerelictOrg/DerelictAL [2] https://github.com/DerelictOrg/DerelictVorbis [3] https://github.com/DerelictOrg/DerelictOgg [4] https://wiki.dlang.org/Installing_DMD [5] https://gist.github.com/ANtlord/0c78180f627eb544cc69770ecbe997a7 [6] https://gist.github.com/ANtlord/e0a7e183498095b2f8a8726f35e63803 [7] https://gist.github.com/ANtlord/e8a0cc6f20b2b46124ae3cd72ed04bed Thanks in advance. Please feel free to ask any question
Return value in BetterC mode.
Hello! Yesterday I found an interesting issue for myself while I was implementing unique pointer for my project in BetterC. When I was trying to return new instance from a `move` method I got calling of destructor the instance. When the instance is out of scope the calling is happens again. I also see that addresses of an instance that calls destructor are same. That thing doesn't happen when I don't use BetterC mode. Is that bug or feature? Please checkout code https://run.dlang.io/is/m1TRnT and try it in BetterC mode and in usual mode. But if I return result of a constructor directly instead of saving the result to variable and returning the variable from the `move` method I don't see double calling of the same destructor. I. e. ``` auto newObject = Box(this); return newObject; ``` is replaced by ``` return Box(this); ``` So... is that bug or feature?
How to use containers in lock based concurrency
Hello! I can't get how to use double linked list in concurrency. Please help. Providing code import std.stdio; import std.container; synchronized class SocksQueue { private shared(DList!string) _queue; public void f(string data) { this._queue.insertFront(data); } } void main(string[] args) { } I get a compile error onlineapp.d(8): Error: template std.container.dlist.DList!string.DList.insertFront cannot deduce function from argument types !()(string) shared, candidates are: /dlang/dmd/linux/bin64/../../src/phobos/std/container/dlist.d(441): std.container.dlist.DList!string.DList.insertFront(Stuff)(Stuff stuff) https://run.dlang.io/gist/3afff560fe3b2f439272c3ee3adcebd0?compiler=dmd
struct/class generation
Hello dear community! I've met a little issue. How can I generate struct or class copying some fields and methods from another struct or class? I've found methods to get fields. They are std.traits.FieldNameTuple and std.traits.FieldTypeTuple but I can't find a method allows getting methods from struct or class. Other words I want to get fields and methods by string values and copy them to my struct. Is it possible? Or do I want something strange? Thanks in advance. Sorry if my English is not clear.
Re: Create class on stack
On Sunday, 6 August 2017 at 15:47:43 UTC, Moritz Maxeiner wrote: If you use this option, do be aware that this feature has been > scheduled for future deprecation [1]. It's likely going to continue working for quite a while (years), though. [1] https://dlang.org/deprecate.html#scope%20for%20allocating%20classes%20on%20the%20stack I can't understand. Why is moved a scope allocation to a library. I'm pretty sure it should be a language feature.
Re: Exception handling
On Friday, 14 July 2017 at 20:22:21 UTC, Ali Çehreli wrote: On 07/14/2017 12:36 PM, ANtlord wrote: All you need is to catch Exception there as well: catch(Exception) { assert(false, "throwable_fn threw something unexpected"); } Ali Thank you, Ali! You answer for my question again. Again, this depends on the exact internals available at the semantic analysis time, but in theory, it should be possible that when a ThrowStatement is encountered, the surrounding scope aggregates the exception's type in it's aggregated exception set (ignoring things not inherited from Exception). Sounds good. It doesn't appear too hard for implementation. But I tried to understand dmd architecture at least 5 times. Unfortunaly I can't get it. If there is a thing for talking closer then it can help to ask mini questions. I mean something like Slack or Telegram.
Exception handling
Hello! I've tried to use nothrow keyword and I couldn't get a state of function satisfied the keyword. I have one more method that can throw an exception; it is called inside nothrow method. Every type of an exception from the throwable method is handled by the nothow method. ubyte throwable_fn(ubyte state) { if(state < 2) { return 1; } else if(state == 3) { throw new MyException1("qwe"); } else { throw new MyException2("asd"); } } void nothrowable_fn() nothrow { try { auto val = throwable_fn(3); // do success staff } catch(MyException1 e) { // handle error 1 } catch(MyException2 e) { // handle error 2 } } I can't compile this. I get an error says nothrowable_fn function can't be nothrow. I get the message until I handle Exception class. But it is not appropriate for me because I can get another exception of another type. I mean case when code will be updated and new exceptions will come with a new piece of code. How can I achieve nothrow statement without catching of an instance of Exception class? Thanks. Sorry if my English is not clear.
Re: Garbage collection and closures.
On Saturday, 17 June 2017 at 17:15:50 UTC, Adam D. Ruppe wrote: On Saturday, 17 June 2017 at 14:19:34 UTC, ANtlord wrote: Excuse me, I can't get what does it mean "deepest-referenced". What the deep you mean? The deep of a closure or deep of the function where the variable is defined. Can you give an example code? Where the variable is defined that is referenced in the closure. So: --- void uses(void delegate() dg); void foo() { int a; foreach(b; 0 .. 10) { uses( () { a++; } ); // #1 uses( () { b++; } ); // #2 } } --- In that case, #1 would only be allocated once, at the start of the foo() function. It only uses `a`, so it doesn't have to allocate again after the point a is defined. But #2 might allocate each time through the loop. (It currently doesn't, but this is filed as an open bug because it is supposed to.) Since it uses `b` which is defined inside the loop, it will have to allocate a new copy for each iteration. Is this function called every time when allocation happens in a heap? Not any allocation, it is just the function the compiler uses when it needs to make a closure. Thanks a lot, Adam! Everything is clear. Except for the bug. I've got an expected result of a value of the variable from #2. The value equals to number from sequence plus one in each iteration. There are ten iterations. What's wrong? Are there should be five iterations? It doesn't make sense for me due to the variable assigned value from the sequence 0..10. Or do I look at the wrong place? Can you give me a link to the bug? Thank you again!
Re: Garbage collection and closures.
On Saturday, 17 June 2017 at 13:13:17 UTC, Adam D. Ruppe wrote: On Saturday, 17 June 2017 at 13:03:28 UTC, ANtlord wrote: Is GC called every iteration of this loop? No, it will once on scope entry; where the deepest-referenced variable that is actually captured is defined. The compiler allocates heap space instead of stack space for the locals, then runs the function normally using that space. Excuse me, I can't get what does it mean "deepest-referenced". What the deep you mean? The deep of a closure or deep of the function where the variable is defined. Can you give an example code? It will only alloc once. You can prove this with a debugger btw, set a breakpoint on `_d_allocmemory`. Is this function called every time when allocation happens in a heap? Thank you. Sorry if my English is not clear.
Garbage collection and closures.
Hello! I can't understand one thing related to closures and calling of GC. I have the following demo snippet, where a closure is passed to `receive` function in a loop. bool isDone = false; while(!isDone) receive((bool val){ isDone = val }); Is GC called every iteration of this loop? I know that I can move the code to a method of a struct and make the closure and variable "isDone" as fields of the struct. It avoids GC calling definitely. But I want to get how many times GC is called in case of a closure in a loop. Thanks.
Re: Top level associative arrays
On Tuesday, 2 May 2017 at 16:34:15 UTC, H. S. Teoh wrote: On Tue, May 02, 2017 at 02:37:20PM +, ANtlord via Digitalmars-d-learn wrote: On Tuesday, 2 May 2017 at 12:41:01 UTC, Jacob Carlborg wrote: > > Note that when declared as "enum", all places it's > referenced, a new associative array will be allocated. If it is allocated at all places I can move initialization to module ctor as says evilrat but how can I make an immutable associative array? Just declare it immutable. The module ctor can still initialize it, because ctors are allowed to initialize immutables: -- immutable string[string] dict; static this() { dict = [ "abc": "def", "ghi": "lmn" ]; } void main() { import std.stdio; writeln(dict["abc"]); } -- T Thanks a lot!
Re: Top level associative arrays
On Tuesday, 2 May 2017 at 14:37:20 UTC, ANtlord wrote: On Tuesday, 2 May 2017 at 12:41:01 UTC, Jacob Carlborg wrote: Note that when declared as "enum", all places it's referenced, a new associative array will be allocated. If it is allocated at all places I can move initialization to module ctor as says evilrat but how can I make an immutable associative array? I think it will be more suitable to create singleton of structure.
Re: Top level associative arrays
On Tuesday, 2 May 2017 at 12:41:01 UTC, Jacob Carlborg wrote: Note that when declared as "enum", all places it's referenced, a new associative array will be allocated. If it is allocated at all places I can move initialization to module ctor as says evilrat but how can I make an immutable associative array?
Re: Top level associative arrays
On Tuesday, 2 May 2017 at 08:24:09 UTC, evilrat wrote: Making enum means that value should be available at compile time and AA's are fully dynamic. But if my memory serves me well, you can declare empty AA and delay initialization. So the closest solution is to move initialization of AA to shared module ctor(note that there is difference between shared and non-shared, refer to documentation) such as in this example: static shared this() // <-- module ctors run before main() { dict = [ "s": "q", "ss": "qq" ]; } string[string] dict; void main() { ... dict is already initialized ... } I know about D's enums and I know about module ctors but my question is about difference between array and associative array in case of definition in top level of module. Why DMD allows to define array and doesn't allow to define associative array.
Re: Top level associative arrays
On Tuesday, 2 May 2017 at 07:48:35 UTC, ANtlord wrote: Hello! Is it possible to define associative array on top level of module? I try to compile this code and I get message `Error: non-constant expression ["s":"q", "ss":"qq"]` import std.stdio; auto dict = [ "s": "q", "ss": "qq" ]; void main() { writeln(val); } I solved it by replacement of word `auto` by `enum`. It is acceptable for me. But I notice some inconsistency of logic. When I define simple array I don't get same compile error and it doesn't lead to define this array using enum. What is key difference between them in this case? Thanks. Sorry if my English is not clear. By the way I notice some strange compile error when I try to change associatove array defined using enum. import std.stdio; enum dict = [ "s": "q", "ss": "qq" ]; void main() { dict["sss"] = "qqq"; } Compilation of this code returns the error & el:0x3237ab4 cnt=0 cs=0 & TY* 0x3235794 el:0x3235794 cnt=0 cs=0 call TY* 0x3235744 0x32356f4 el:0x3235744 cnt=0 cs=0 var TYC func _d_assocarrayliteralTX el:0x32356f4 cnt=0 cs=0 param TYvoid 0x32356a4 0x3235654 el:0x32356a4 cnt=0 cs=0 param TYvoid 0x3234c44 0x3234d34 el:0x3234c44 cnt=0 cs=0 rpair TYucent 0x3234ba4 0x3234bf4 el:0x3234ba4 cnt=0 cs=0 relconst TY* 0+& _TMP8 el:0x3234bf4 cnt=0 cs=0 const TYuns long long 2LL el:0x3234d34 cnt=0 cs=0 rpair TYucent 0x3234c94 0x3234ce4 el:0x3234c94 cnt=0 cs=0 relconst TY* 0+& _TMP5 el:0x3234ce4 cnt=0 cs=0 const TYuns long long 2LL el:0x3235654 cnt=0 cs=0 var TY* _D16TypeInfo_HAyaAya6__initZ Internal error: backend/cgcs.c 352 But when I try to change simple array defined using enum import std.stdio; enum arr = [1, 2, 3]; void main() { arr ~= 4; } I get the clear error `Error: [1, 2, 3] is not an lvalue`
Re: Top level associative arrays
On Tuesday, 2 May 2017 at 07:48:35 UTC, ANtlord wrote: Hello! Is it possible to define associative array on top level of module? I try to compile this code and I get message `Error: non-constant expression ["s":"q", "ss":"qq"]` import std.stdio; auto dict = [ "s": "q", "ss": "qq" ]; void main() { writeln(val); } I solved it by replacement of word `auto` by `enum`. It is acceptable for me. But I notice some inconsistency of logic. When I define simple array I don't get same compile error and it doesn't lead to define this array using enum. What is key difference between them in this case? Thanks. Sorry if my English is not clear. Sorry. There is should be `writeln(dict["s"]);` instead `writeln(val);`
Top level associative arrays
Hello! Is it possible to define associative array on top level of module? I try to compile this code and I get message `Error: non-constant expression ["s":"q", "ss":"qq"]` import std.stdio; auto dict = [ "s": "q", "ss": "qq" ]; void main() { writeln(val); } I solved it by replacement of word `auto` by `enum`. It is acceptable for me. But I notice some inconsistency of logic. When I define simple array I don't get same compile error and it doesn't lead to define this array using enum. What is key difference between them in this case? Thanks. Sorry if my English is not clear.
Re: Understanding lvalue and rvalue
On Friday, 28 April 2017 at 05:21:26 UTC, ag0aep6g wrote: Instead of removing `in`/`const` from the ref overload, you can also add it to the non-ref overload. Again, the overloads will have the same match level ("match with conversion to const"), and the ref version will win. It works. I don't know why I've decided to make rvalue parameter non-const. It makes sense. It's clear answer. Thank you very much!
Re: Understanding lvalue and rvalue
On Friday, 28 April 2017 at 04:46:00 UTC, ANtlord wrote: Does make sense for me because it is more obvious in client code, but I want to understand reason of error pointed above. Typo fix. It makes sense for me*
Understanding lvalue and rvalue
Hello! Short time ago I've met strange thing at least for me. I have a non-copyable structure and two methods for it with same name. I mean that I use function overloading. First method takes rvalue of this structure. Second method takes constant lvalue structure. But when I try to use this function with instantiated object I get compile error. struct MyStruct { @disable this(this); int a; } void process(MyStruct obj) { writeln("incoming rvalue"); } void process(in ref MyStruct obj) { writeln("incoming lvalue"); } void main() { MyStruct obj = {a: 1}; process(obj); } Text of the error is "struct app.MyStruct is not copyable because it is annotated with @disable" Also I try to change word `in` by `const` and I get same result. But when I remove `in` program is compiled. Is this mug or feature. If feature, please help to understand it. Should I pass structure instances by pointer? Like void process(in MyStruct* obj) { writeln("incoming lvalue"); } void main() { MyStruct obj = {a: 1}; process(); } Does make sense for me because it is more obvious in client code, but I want to understand reason of error pointed above. Thanks. Sorry if my English is not clear.
Re: Creating Tuple or AliasSeq
On Friday, 7 April 2017 at 07:46:40 UTC, Ali Çehreli wrote: Here is a solution: auto objectFactory(ObjectType, Args...)(Args args) { import std.algorithm : cartesianProduct, map; import std.array : array; return cartesianProduct(args).map!(a => ObjectType(a.expand)).array; } struct Pair { int number; string name; } import std.stdio; void main() { auto pairKit = objectFactory!(Pair)([1, 2], ["qwe", "asd"]); auto pairSet = pairKit; writeln(pairSet); } Ali I can't understand. Documentation of cartesianProduct points out about finite arrays. At least one of arrays must be a inifinte array. As far as I know finite arrays is `int[3]` and infinite is `int[]` (https://dlang.org/library/std/range/primitives/is_infinite.html). Am I right? If I am then I can't understand why DMD return error about finite ranges compiling following code. struct Hay { int a; @disable this(this); @disable this(); this(int a){ this.a = a; } } Hay[] params = [ Hay(1), Hay(23) ]; auto products = cartesianProduct(params, params); Error text: static assert "cartesianProduct involving finite ranges must have at least one finite forward range" I noticed that removing disabling default constructors helps. Does that mean an array contains objects of a struct with disabled default constructor is finite?
Re: Creating Tuple or AliasSeq
On Friday, 7 April 2017 at 07:46:40 UTC, Ali Çehreli wrote: Here is a solution: auto objectFactory(ObjectType, Args...)(Args args) { import std.algorithm : cartesianProduct, map; import std.array : array; return cartesianProduct(args).map!(a => ObjectType(a.expand)).array; } struct Pair { int number; string name; } import std.stdio; void main() { auto pairKit = objectFactory!(Pair)([1, 2], ["qwe", "asd"]); auto pairSet = pairKit; writeln(pairSet); } Ali It's great! Thanks a lot!
Creating Tuple or AliasSeq
Hello! I've got an issue related to making a Tuple or AliasSeq using income template arguments. I want to create template makes an array of objects from array of arrays have different sizes and different types of values. I created temporary solution. It is a concatenation of strings that will be passed to mixin. But I just want to reorder parameters and pass them to ObjectType using AliasSeq or Tuple. Does it possible? import std.stdio; template objectFactory(ObjectType, Args...) { static string loopGen() { string code = (ObjectType[]).stringof ~ " res = []; "; foreach(i, _; Args) { enum level = to!string(i); code ~= "foreach(elem" ~ level ~ "; Args[" ~ level ~ "])"; } code ~= "res ~= " ~ ObjectType.stringof ~ "("; foreach(i, _; Args) { enum level = to!string(i); code ~= "elem" ~ level; static if(i + 1 < Args.length) { code ~= ", "; } } code ~= ");"; return code; } static ObjectType[] factory() in { static assert(Args.length > 0); foreach(argumentCases; Args) static assert(argumentCases.length > 0); } body { enum codeString = loopGen(); mixin(codeString); return res; } alias objectFactory = factory; } Example: struct Pair { int number; string name; } auto pairKit = objectFactory!(Pair, [1], ["qwe", "asd"]); auto pairSet = pairKit(); assert(pairSet.length == 2); writeln(pairSet[0]); // writes Pair(1, "qwe"); writeln(pairSet[1]); // writes Pair(1, "asd"); Thanks. Sorry if my english is not clear.
Re: Interfacing C++ to D
On Sunday, 2 April 2017 at 16:03:51 UTC, FreeSlave wrote: Funny thing: If I replace interface with abstract class, it works as it should. Also I noticed that removing inheritance in library and in application makes unexpected results. When I try to output field `field` I get incorrect random value. It looks like that the field is got by wrong address. For clearance I created branch `removed-inheritance`.
Re: Interfacing C++ to D
On Sunday, 2 April 2017 at 09:58:19 UTC, ANtlord wrote: On Saturday, 1 April 2017 at 16:39:28 UTC, FreeSlave wrote: This page has many examples. Which exactly do you try to run and how do you build it? Which compilers, OS? My bad. I've tested example under caption Using C++ Classes From D. I used several combinations of compilers, and no one works for me. OS: ArchLinux D compilers: DMD 2.073.2, LDC 1.1.0 C++ compiler: gcc 6.3.1, clang 3.9 Also I've created reposotory contains test project. Anyone can take a look on that for clearance. https://github.com/ANtlord/cpp_to_d_test I've tested also on Ubuntu 16.04 and DMD v2.073.1 with gcc 5.4.0
Re: Interfacing C++ to D
On Saturday, 1 April 2017 at 16:39:28 UTC, FreeSlave wrote: This page has many examples. Which exactly do you try to run and how do you build it? Which compilers, OS? My bad. I've tested example under caption Using C++ Classes From D. I used several combinations of compilers, and no one works for me. OS: ArchLinux D compilers: DMD 2.073.2, LDC 1.1.0 C++ compiler: gcc 6.3.1, clang 3.9 Also I've created reposotory contains test project. Anyone can take a look on that for clearance. https://github.com/ANtlord/cpp_to_d_test
Interfacing C++ to D
Hello! Can somebody give a relevant example shows how to use C++ classes in D? I've used the exmaple from https://dlang.org/spec/cpp_interface.html but I get a segmentation fault as result of D application. My application shows "Program exited with code -11" Thanks.
Re: Delay allocating class instance in stack.
On Wednesday, 22 March 2017 at 13:19:32 UTC, Nicholas Wilson wrote: On Wednesday, 22 March 2017 at 08:57:34 UTC, ANtlord wrote: You still have the buffer (the class has to go somewhere!), but it is implicit (you can't refer to it directly only through the class reference) and so is the destructor call, as opposed to the emplace + explicit buffer combo. In the latter case the class destructor will not be called automatically so you must do it yourself with `destroy`. My bad. It appears I need to clarify. I mean the case that I create object without delaying. I mean simple construction. scope myObj = MyClass(1); Answering own question: In this case object is allocated using stack (according documention https://wiki.dlang.org/Memory_Management#Allocating_Class_Instances_On_The_Stack). Function `destroy` used for cleanup object from heap (according documention https://wiki.dlang.org/Memory_Management#Explicit_Class_Instance_Allocation).
Re: Delay allocating class instance in stack.
On Wednesday, 22 March 2017 at 06:47:26 UTC, Ali Çehreli wrote: On 03/21/2017 09:57 PM, ANtlord wrote: > Thank you for clarification. But I have one more question. Do I have to > use destroy for deallocating object from stack? Yes because what is going out of scope are two things: - A buffer - A MyClass reference Oh I got it. I have to use `destroy` in this case. If I use `scope` I haven't buffer and MyClass reference then I can don't use `destroy`. Do I understand correctly?
Re: Delay allocating class instance in stack.
On Tuesday, 21 March 2017 at 12:30:57 UTC, Stefan Koch wrote: Try scope obj = new MyClass(flag ? 1 : 2); In essence you should never need to delay construction. Just construct the object as soon as you have everything to construct it. which includes conditions. Yes I know it. I prepare all input variables before construction of object usually. I just want to know possibilty of the case described above.
Re: Delay allocating class instance in stack.
On Tuesday, 21 March 2017 at 08:46:43 UTC, Ali Çehreli wrote: Another option is std.conv.emplace: import std.conv : emplace; class MyClass { this(int) @nogc { } ~this() @nogc { } } void method(bool flag) @nogc { void[__traits(classInstanceSize, MyClass)] buffer = void; MyClass obj; if(flag) { obj = emplace!MyClass(buffer, 1); } else { obj = emplace!MyClass(buffer, 2); } // Unfortunately, destroy() is not @nogc // scope(exit) destroy(obj); Thank you for clarification. But I have one more question. Do I have to use destroy for deallocating object from stack?
Re: Delay allocating class instance in stack.
On Tuesday, 21 March 2017 at 08:12:36 UTC, rikki cattermole wrote: You probably want[0] to allocate a class on the stack instead of doing this. [0] http://dlang.org/phobos/std_typecons.html#.scoped If I will use it I won't use @nogc. Is the only one case?
Delay allocating class instance in stack.
Hello! I read documentation about memory management and can't find description about delay allocation of instance. I have a method marked by @nogc. This method takes boolean variable. If this variable is true I want to construct object with one set of parameters else I want to construct object with another set of parameters. Take a look at code for clearance. void method(bool flag) @nogc { scope MyClass obj; if(flag) { obj = new MyClass(1); } else { obj = new MyClass(2); } // using obj } But this code CAN'T be compiled. How should I declare object for delay construction. Thanks.
DMD JSON output
Hello! I've encroutered intresting tool of DMD. It is dump of AST in JSON format (dmd -X main.d). But I it contains only declaration of methods, templates and structs. It doesn't contain statements like a variables or nested functions inside function's body. Is it possible to make dump with statements inside function's body? If yes, how can I do this? Thanks.
Re: About debugging (again)
On Monday, 17 October 2016 at 19:17:25 UTC, Basile B. wrote: On Monday, 17 October 2016 at 19:14:49 UTC, ANtlord wrote: redirect to ddemangle, that's its job. Do you know the way how to redirect? I've tried as you have written above and this makes impossible to type any command to gdb.
Re: About debugging (again)
On Monday, 17 October 2016 at 17:53:30 UTC, Basile B. wrote: On Monday, 17 October 2016 at 17:46:05 UTC, Basile B. wrote: On Monday, 17 October 2016 at 15:45:56 UTC, ANtlord wrote: On Monday, 17 October 2016 at 15:43:32 UTC, ANtlord wrote: [...] Oh Sorry, I've forgotten about pointing technical parameters. Ubuntu 14.04 GDB 7.7.1 DMD64 D Compiler v2.071.1 redirect gdb's output to "ddemangle". This is what I do in the alpha version of Coedit's GDB commander, now in console mode I don't know the exact method. seems to be: gdb binary_name | ddemangle This makes gdb useless. I can't type any command. Propably can I use demangle by another way?
Re: About debugging (again)
On Monday, 17 October 2016 at 17:57:19 UTC, Martin Krejcirik wrote: On Monday, 17 October 2016 at 15:45:56 UTC, ANtlord wrote: GDB 7.7.1 Use latest GDB, 7.10 has got much better D support. Tested on GDB 7.11.1. Same case :(
Re: About debugging (again)
On Monday, 17 October 2016 at 15:43:32 UTC, ANtlord wrote: Hello! I've met an issue related to debugging by GDB. Directly when I try to show call stack I get like this http://pastebin.com/kRFRqznq. How can I make name of methods more human readable? I see part of printed name matches to name of methods from code and I can suppose what method was called, but it would be great if I can debug application without any supposing. Sorry if my english is not clear. Oh Sorry, I've forgotten about pointing technical parameters. Ubuntu 14.04 GDB 7.7.1 DMD64 D Compiler v2.071.1
About debugging (again)
Hello! I've met an issue related to debugging by GDB. Directly when I try to show call stack I get like this http://pastebin.com/kRFRqznq. How can I make name of methods more human readable? I see part of printed name matches to name of methods from code and I can suppose what method was called, but it would be great if I can debug application without any supposing. Sorry if my english is not clear.
Calling methods under gdb.
Hello everyone! I want to contribute some project, but I have inconvenient things related to debug. My high level of using GDB is show a variable and get type of a variable. In C++ usually I use QtCreator and debugging was pretty. In Python I have PDB, that can evaluate code. In D I have just GDB. Maybe I don't understand power of GDB, but it is so inconvenient for me. So can you help me? I don't know how to call any method. I can't call method, object's method or template method. I've tried command `call`, but I get message `No symbol "func" in current context`. Although I stand under line, where this method is called. Regards.
Re: Search Engine
On Wednesday, 8 October 2014 at 20:15:33 UTC, Chris Williams wrote: On Wednesday, 8 October 2014 at 18:15:08 UTC, ANtlord wrote: It would be stable? I mean program, that will use C++ extern interface. Trying to link to C++ code will cause some work to solve build issues, but there shouldn't be any stability impacts other than recognizing that C++ won't be using memory management. Ok, I have got it. So... I think, that topic is over. Thank you.
Re: Search Engine
On Monday, 6 October 2014 at 18:54:53 UTC, yawniek wrote: On Monday, 6 October 2014 at 17:11:51 UTC, ANtlord wrote: Good day! I recenlty have tried create typical project on vibe.d. The web framework is not bad. And I can say, that it is better that something another web frameworks. But I have met a problem. I can't find search engine. I use xapian always. It has API for several languages, but except D. I know about another search engines, but I can't find even one for D. Does D have search engine? Or Have I find theme for starting open source project? Best Regards. Sorry for my english. you should be able to include xapian via c++ extern interface see: http://dlang.org/cpp_interface.html or you can use std.json to talk to elasticsearch. It would be stable? I mean program, that will use C++ extern interface.
Search Engine
Good day! I recenlty have tried create typical project on vibe.d. The web framework is not bad. And I can say, that it is better that something another web frameworks. But I have met a problem. I can't find search engine. I use xapian always. It has API for several languages, but except D. I know about another search engines, but I can't find even one for D. Does D have search engine? Or Have I find theme for starting open source project? Best Regards. Sorry for my english.