Why pow() won't go beyond 2^31?
I am using the function pow() from std.math but if I try pow(2, 32) it returns 0, it doesn't compute beyond the maximum value of an int(2^31) and I am working with long. What should I do?
Re: How to debug FinalizeError?
No I'm not preallocating any exceptions. It was idea, but I removed all calls which can make throw. I'm using very old dmd 2.074.1, so as I have patched it for my text editor with IDE functions. I had a year break in development, so now I need to rewrite all my patches. But exactly the output of my program looks like this: core.exception.FinalizeError@src/rt/lifetime.d(1407): Finalization error === Bypassed === BerkeleyDB exceptions mixed with output of destructors || core.exception.InvalidMemoryOperationError@src/core/exception.d(696): Invalid memory operation It means that "Invalid memory operation" occurred earlier than "Finalization error"? The line on which shows the pointer src/rt/lifetime.d(1407) is exactly: onFinalizeError(*pc, e); Why gdb doesn't see this function? My program (the text editor) had run test all night under gdb with break on InvalidMemoryOperationError and didn't fall. So it is very-very-very hard to reproduce. And I haven't ideas where maybe this throw. At least I don't see any throw in explicit form.
Re: How to center dlangui Window on screen
On Wednesday, 28 November 2018 at 23:07:50 UTC, greatsam4sure wrote: On Wednesday, 28 November 2018 at 17:23:21 UTC, Edgar Huckert wrote: On Wednesday, 28 November 2018 at 08:55:11 UTC, greatsam4sure wrote: I am learning Dlang and Dlangui. I encounter, a little problem on: how to center dlangui window on screen. How to set the window width and height outside the constructor How to maximize and minimize the window using code. How to set global font for the application. The font display is not too nice. I have check online, the documentation and available tutorial to no help Thanks in advance For a little bit of information look at: https://github.com/buggins/dlangui/pull/372 Without going into depth I have tested this under Linux/GTK with dlangui: WindowState state; Rectrect; rect.left = 800; rect.top= 10; rect.bottom = 600; rect.right = 1000; bool bRet= window.setWindowState(state, false, rect); window.show(); This changed the position and size of my initial window. Edgar Huckert This help a little but not what I am looking for. I want to calculate the width and window of the screen so as to center my window on screen I also notice that a window of 350 x 550 appear bigger compare to the same Widow dimension in Havana and adobe air. Why is it so? Plz help! Thanks in advance To center horizontal: l = left s = screen width w = window width l = (s / 2) - (w / 2) To center vertical: t = top s = screen height h = window height t = (s / 2) - (h / 2) And about the window size. It has probably to do with the type of Window you're rendering, like whether it has borders or not. Borders are not calculated in the width / height, so they take up extra space. Adobe usually never uses the native GUI for borders etc. so the border size (if there is one) is included in their width / height.
Re: How to center dlangui Window on screen
On Wednesday, 28 November 2018 at 17:23:21 UTC, Edgar Huckert wrote: On Wednesday, 28 November 2018 at 08:55:11 UTC, greatsam4sure wrote: I am learning Dlang and Dlangui. I encounter, a little problem on: how to center dlangui window on screen. How to set the window width and height outside the constructor How to maximize and minimize the window using code. How to set global font for the application. The font display is not too nice. I have check online, the documentation and available tutorial to no help Thanks in advance For a little bit of information look at: https://github.com/buggins/dlangui/pull/372 Without going into depth I have tested this under Linux/GTK with dlangui: WindowState state; Rectrect; rect.left = 800; rect.top= 10; rect.bottom = 600; rect.right = 1000; bool bRet= window.setWindowState(state, false, rect); window.show(); This changed the position and size of my initial window. Edgar Huckert This help a little but not what I am looking for. I want to calculate the width and height of the screen so as to center my window on screen I also notice that a window of 350 x 550 appear bigger compare to the same Widow dimension in javafx and adobe air. Why is it so? Plz help! Thanks in advance
Re: How to debug FinalizeError?
On Wednesday, 28 November 2018 at 22:40:17 UTC, unDEFER wrote: Hello! After long-long time of debugging, I just have decided InvalidMemoryOperationError in my program. But now my program after few hours of testing again crashes with "Finalization error". So InvalidMemoryOperationError means a GC function got called while the GC was locked. This is usually because you did an allocation inside a destructor. Finalization error happens when a destructor throws an exception. Now, many times, trying to throw an exception from inside a destructor will first trigger the invalid operation - allocating the exception will be an error before the exception actually exists. But there are a few ways around this, like preallocating or calling a function that uses a statically allocated exception. Language features that use statically allocated exceptions include: * InvalidMemoryOperationError * OutOfMemoryError * SwitchError There might be more, but this is all I see right now (my process btw: search the druntime source code for "staticError", the function that makes those. But this is subject to change, so first maybe look up the definition of onOutOfMemoryError and see the pattern there.) Of these... well, they are all kinda difficult to cause in a destructor. Are you preallocating something in your code and throwing it in a destructor? Also, what *exactly* is the message you get when the exception happens? It should include a line number from druntime as well as message from the inner exception that caused it in the first place.
Re: derelict-sdl2 automatically stripping the SDL_ prefix from names
Hello, as I know allMembers returns members not recursively. If you want to get really all members you need to make recursive function. In my program I used the next routine to print all members of module: static void allMembersOfModule(string module_name, bool root=false)() { static if (module_name != "object" && module_name != __MODULE__) { mixin("import "~module_name~";"); pragma(msg, module_name~":"); foreach(member; __traits(allMembers, mixin(module_name))) { static if (__traits(compiles, mixin(member)) && (!__traits(compiles, __traits(getProtection, mixin(member))) || __traits(getProtection, mixin(member)) != "private" && __traits(getProtection, mixin(member)) != "package")) pragma(msg, member); } static if (root || module_name == "std.algorithm" || module_name == "std.range") { import std.algorithm.searching: startsWith; foreach(member; __traits(allMembers, mixin(module_name))) { static if (__traits(compiles, mixin(member)) && __traits(compiles, mixin(member).stringof.startsWith("module ")) && mixin(member).stringof.startsWith("module ")) { allMembersOfModule!(member); } } } } } As I know it worked good. Maybe it helps to you also.
Re: How to center dlangui Window on screen
On Wednesday, 28 November 2018 at 17:23:21 UTC, Edgar Huckert wrote: On Wednesday, 28 November 2018 at 08:55:11 UTC, greatsam4sure wrote: I am learning Dlang and Dlangui. I encounter, a little problem on: how to center dlangui window on screen. How to set the window width and height outside the constructor How to maximize and minimize the window using code. How to set global font for the application. The font display is not too nice. I have check online, the documentation and available tutorial to no help Thanks in advance For a little bit of information look at: https://github.com/buggins/dlangui/pull/372 Without going into depth I have tested this under Linux/GTK with dlangui: WindowState state; Rectrect; rect.left = 800; rect.top= 10; rect.bottom = 600; rect.right = 1000; bool bRet= window.setWindowState(state, false, rect); window.show(); This changed the position and size of my initial window. Edgar Huckert This help a little but not what I am looking for. I want to calculate the width and window of the screen so as to center my window on screen I also notice that a window of 350 x 550 appear bigger compare to the same Widow dimension in Havana and adobe air. Why is it so? Plz help! Thanks in advance
How to debug FinalizeError?
Hello! After long-long time of debugging, I just have decided InvalidMemoryOperationError in my program. But now my program after few hours of testing again crashes with "Finalization error". What this error means exactly? I again did something wrong in destructor? And how to debug it? I tried "break onFinalizeError" in gdb like "break onInvalidMemoryOperationError", but it says: Function "onFinalizeError" not defined. There are too few information about this error in documentation and forum, and I didn't find anything about it in wiki. Thank you.
Re: LDC2 win64 calling convention
You're not using naked asm; this entails a prologue (spilling the params to stack etc.). Additionally, LDC doesn't really like accessing params and locals in DMD-style inline asm, see https://github.com/ldc-developers/ldc/issues/2854. You can check the final asm trivially online, e.g., https://run.dlang.io/is/e0c2Ly (click the ASM button). You'll see that your params are in R8, RDX and RCX (reversed order as mentioned earlier).
Re: LDC2 win64 calling convention
Thank You for the explanation! But my tests has different results: void* SSE_sobelRow(ubyte* src, ubyte* dst, size_t srcStride){ asm{ push RDI; mov RAX, 0; mov RDX, 0; mov RCX, 0; //clear 'parameter' registers mov RAX, src; mov RDI, dst; //gen movups XMM0,[RAX]; movaps XMM1,XMM0; pslldq XMM0,1; movaps XMM2,XMM1; psrldq XMM1,1; pavgb XMM1,XMM0; pavgb XMM1,XMM2; movups [RDI],XMM1; //gen end pop RDI; }} When I clear those volatile regs that are used for register calling, I'm still able to get good results. However when I put "mov [RBP+8], 0" into the code it generates an access violation, so this is why I think parameters are on the stack. What I'm really unsire is that the registers I HAVE TO save in my asm routine. Currently I think I only able to trash the contents of RAX, RCX, RDX, XMM0..XMM5 based on the Microsoft calling model. But I'm not sure what's the actual case with LDC2 Win64. If my code is surrounded by SSE the optimizations of the LDC2 compiler, and I can't satisfy the requirements, I will have random errors in the future. I better avoid those. On the 32bit target the rule is simpe: you could do with all the XMM regs and a,c,d what you want. Now at 64bit I'm quite unsure. :S
Re: LDC2 win64 calling convention
On Wednesday, 28 November 2018 at 20:17:53 UTC, kinke wrote: The stack isn't used at all To prevent confusion: it's used of course, e.g., if there are more than 4 total parameters. Just not in the classical sense, i.e., a 16-bytes struct isn't pushed directly onto the stack, but the caller makes the copy and passes a pointer, either in a register or on the stack.
Re: LDC2 win64 calling convention
On Wednesday, 28 November 2018 at 18:56:14 UTC, realhet wrote: 1. Is there register parameters? (I think no) Of course, e.g., POD structs of power-of-2 sizes <= 8 bytes and integral scalars as well as float/double/vectors. The stack isn't used at all, aggregates > 8 bytes are passed by ref (caller makes a copy on its stack and passes a pointer to it to the callee); that seems not to be mentioned at all in the Wiki article. 2. What are the volatile regs? RAX, RCX, RDX, XMM6..XMM15? See Microsoft's docs. 3. Is the stack pointer aligned to 16? It is IIRC. 4. Is there a 32 byte shadow area on the stack? Yes, IIRC. --- LDC conforms to the regular Win64 ABI (incl. __vectorcall extension for vectors). The biggest difference is that `extern(D)` (as opposed to `extern(C)` or `extern(C++)`) reverses the arguments - `foo(1, 2, 3, 4)` becomes `foo(4, 3, 2, 1)`, so not the first 4 args are passed in registers if possible, but the last ones (incl. special cases wrt. struct-return + `this` pointers). Other than that, there are just very few special cases for delegates and dynamic arrays, which only apply to `extern(D)`.
LDC2 win64 calling convention
Hi, Is there a documentation about the win64 calling convention used with LDC2 compiler? So far I try to use the Microsoft x64 calling convention, but I'm not sure if that's the one I have to. But it's not too accurate becaues I think it uses the stack only. https://en.wikipedia.org/wiki/X86_calling_conventions#Microsoft_x64_calling_convention I'm asking for Your help in the following things: 1. Is there register parameters? (I think no) 2. What are the volatile regs? RAX, RCX, RDX, XMM6..XMM15? 3. Is the stack pointer aligned to 16? 4. Is there a 32 byte shadow area on the stack? Thank you!
Re: How to center dlangui on screen
On Wednesday, 28 November 2018 at 08:55:11 UTC, greatsam4sure wrote: I am learning Dlang and Dlangui. I encounter, a little problem on: how to center dlangui window on screen. How to set the window width and height outside the constructor How to maximize and minimize the window using code. How to set global font for the application. The font display is not too nice. I have check online, the documentation and available tutorial to no help Thanks in advance For a little bit of information look at: https://github.com/buggins/dlangui/pull/372 Without going into depth I have tested this under Linux/GTK with dlangui: WindowState state; Rectrect; rect.left = 800; rect.top= 10; rect.bottom = 600; rect.right = 1000; bool bRet= window.setWindowState(state, false, rect); window.show(); This changed the position and size of my initial window. Edgar Huckert
Re: How to iterate getSymbolsByUDA
On 11/28/18 2:18 AM, Eko Wahyudin wrote: static foreach(sym; getSymbolsByUDA!(A, Attr)){ writeln(sym.stringof); // print variable name "a" this what i want } foreach(sym; getSymbolsByUDA!(A, Attr)){ writeln(sym.stringof); // print "sym" } foreach(sym; getSymbolsByUDA!(A, Attr)){ writeln(__traits(identifier, sym)); //also print "sym" } is there a way to get variable name using foreach like static foreach? Generally, foreach establishes a variable for the item, whereas static foreach does not. Note: I can't even get this to work, even in old versions of dmd. I get the Error: need `this` for `a` of type `int` But if you can get it to work, you may have luck with: alias symbols = getSymbolsByUDA!(A, Attr); foreach(i, _; symbols) { writeln(symbols[i].stringof); // or writeln(__traits(identifier, symbols[i])); } Which is an old workaround for how foreach on tuples used to work. -Steve
Re: D & C++ class question
On Wednesday, 28 November 2018 at 13:42:43 UTC, Nicholas Wilson wrote: On Wednesday, 28 November 2018 at 13:13:40 UTC, bauss wrote: Well unfortunately I cannot control the C++ side of things, but I assume that it'll work properly with extern(C++) so I guess I will just go ahead and try and see if everything works out. I have access to the C++ source so at the very least I can see how it's used there and if it's possible in the way I want it to. I don't hope I have to have a separate C++ "bridge" to make it work. Its mostly a magling problem, if the C++ API uses class& that you have to interface with then you have a problem that would require a shim. It looks like every class is passed by pointers, so that's a relief on that part I guess.
Re: D & C++ class question
On Wednesday, 28 November 2018 at 13:13:40 UTC, bauss wrote: Well unfortunately I cannot control the C++ side of things, but I assume that it'll work properly with extern(C++) so I guess I will just go ahead and try and see if everything works out. I have access to the C++ source so at the very least I can see how it's used there and if it's possible in the way I want it to. I don't hope I have to have a separate C++ "bridge" to make it work. Its mostly a magling problem, if the C++ API uses class& that you have to interface with then you have a problem that would require a shim.
Re: D & C++ class question
On Wednesday, 28 November 2018 at 10:44:05 UTC, Nicholas Wilson wrote: On Wednesday, 28 November 2018 at 07:22:46 UTC, bauss wrote: If I have a class from D. How would you use that class in C++? Like what's the correct approach to this. Would it work just by doing "extern(C++)" or will that only work for D to use C++ classes? If you have foo.d class Foo { int aMember; void aMethod() { ... }; final aFinalMethod() { ... }; } to expose that to C++ you need to add extern(C++) too Foo and use it in C++ as a Foo* foo.h class Foo { int aMember; virtual void aMethod(); void aFinalMethod(); }; If you can't/don't want to do that you can always pass it around in C++ as an opaque pointer with functions that call the member functions and get/set the variables (i.e. the pimpl strategy). Well unfortunately I cannot control the C++ side of things, but I assume that it'll work properly with extern(C++) so I guess I will just go ahead and try and see if everything works out. I have access to the C++ source so at the very least I can see how it's used there and if it's possible in the way I want it to. I don't hope I have to have a separate C++ "bridge" to make it work.
Re: D & C++ class question
On Wednesday, 28 November 2018 at 07:22:46 UTC, bauss wrote: If I have a class from D. How would you use that class in C++? Like what's the correct approach to this. Would it work just by doing "extern(C++)" or will that only work for D to use C++ classes? If you have foo.d class Foo { int aMember; void aMethod() { ... }; final aFinalMethod() { ... }; } to expose that to C++ you need to add extern(C++) too Foo and use it in C++ as a Foo* foo.h class Foo { int aMember; virtual void aMethod(); void aFinalMethod(); }; If you can't/don't want to do that you can always pass it around in C++ as an opaque pointer with functions that call the member functions and get/set the variables (i.e. the pimpl strategy).
How to center dlangui on screen
I am learning Dlang and Dlangui. I encounter, a little problem on: how to center dlangui window on screen. How to set the window width and height outside the constructor How to maximize and minimize the window using code. How to set global font for the application. The font display is not too nice. I have check online, the documentation and available tutorial to no help Thanks in advance