Re: Distinguish between a null array and an empty array
On Sunday, 24 May 2020 at 12:12:31 UTC, bauss wrote: Is there a way to do that? Since the following are both true: int[] a = null; int[] b = []; assert(a is null); assert(!a.length); assert(b is null); assert(!b.length); What I would like is to tell that b is an empty array and a is a null array. Yes you can tell: your `is null` check actually works, the part that doesn't work is that `int[] b = []` is initializing b to null. Here's an example: --- int[0] emptyArray; int[] a = null; // a.ptr is null, a.length is 0 int[] b = emptyArray[]; // b.ptr is non-null, b.length is 0 assert(a is null); assert(!a.length); assert(b !is null); assert(!b.length); ---
Re: Dub platform probes
On Monday, 25 May 2020 at 22:58:54 UTC, Tim wrote: [...] Same here, but /tmp. $ ls /tmp/dub* | wc -l 174
Dub platform probes
Hi all I end up with a directory flooded with platform probes. How can I make sure that old ones are deleted automatically? Thanks
Re: How to get the pointer of "this" ?
On Monday, 25 May 2020 at 22:32:52 UTC, Vinod K Chandran wrote: What is an opCast ? operator overload of the cast function. if you didn't write one, you don't have to worry about this.
Re: How to get the pointer of "this" ?
On Monday, 25 May 2020 at 22:31:00 UTC, Vinod K Chandran wrote: A dword is an unsigned, 32-bit unit of data. We can use uint in D. I have tried that too, but no luck. A DWORD_PTR is *not* the same as a uint. It is more like a size_t or void* depending on context.
Re: How to get the pointer of "this" ?
On Monday, 25 May 2020 at 22:04:28 UTC, Adam D. Ruppe wrote: On Monday, 25 May 2020 at 21:45:39 UTC, welkam wrote: Where is DWORD_PTR defined? it is a win32 thing. should be able to directly cast to it most the time if there is opCast on the class it needs another layer of helper function but without opCast it should just work Hi, What is an opCast ?
Re: How to get the pointer of "this" ?
On Monday, 25 May 2020 at 21:45:39 UTC, welkam wrote: On Sunday, 24 May 2020 at 17:05:16 UTC, Vinod K Chandran wrote: cast(DWORD_PTR) this); Where is DWORD_PTR defined? I cant find it in docs. If its an alias of long then you have to cast to a pointer like this cast(long*) this; you need to specify that you want to cast to a pointer of type T. In this case T is long. Hi, Thanks for the reply. Well, DWORD_PTR is a win32 data type. It is defined in the file windows.h. A dword is an unsigned, 32-bit unit of data. We can use uint in D. I have tried that too, but no luck.
ModuleInfo and -fno-moduleinfo option
Hello, As a general question, what is the purpose of ModuleInfo, constructing and deconstructing each of the runtime's modules? In other words, what are the ramifications of using gdc's -fno-moduleinfo option? I am asking this because I found that skipping its generation solves the problems generated by DSO registration in environments with no knowledge of a dynamic linker. However, I doubt this was among the initial motives for creating this compiler option and I would like to be aware of all implications. Thank you, Cristi
Re: How to get the pointer of "this" ?
On Monday, 25 May 2020 at 21:45:39 UTC, welkam wrote: Where is DWORD_PTR defined? it is a win32 thing. should be able to directly cast to it most the time if there is opCast on the class it needs another layer of helper function but without opCast it should just work
Re: How to get the pointer of "this" ?
On Sunday, 24 May 2020 at 17:05:16 UTC, Vinod K Chandran wrote: cast(DWORD_PTR) this); Where is DWORD_PTR defined? I cant find it in docs. If its an alias of long then you have to cast to a pointer like this cast(long*) this; you need to specify that you want to cast to a pointer of type T. In this case T is long.
Re: How to get the pointer of "this" ?
On Monday, 25 May 2020 at 18:42:33 UTC, bauss wrote: On Monday, 25 May 2020 at 17:14:13 UTC, Vinod K Chandran wrote: On Monday, 25 May 2020 at 16:54:11 UTC, Mike Parker wrote: [...] Hi @Mike Parker, Thank you for your valuable suggestions. I will sure follow them. Well, the exact line number where the error showing is the one with the "SetWindowSubclass" function. In pastebin, the line number is 124. Need to see the Control class too. I think the problem might be something you're referencing from there but need to be sure. @bauss, Here is the code for Control class. https://pastebin.com/Hy9dCNdS
Re: How to get the pointer of "this" ?
On Monday, 25 May 2020 at 17:14:13 UTC, Vinod K Chandran wrote: On Monday, 25 May 2020 at 16:54:11 UTC, Mike Parker wrote: On Monday, 25 May 2020 at 16:26:31 UTC, Vinod K Chandran wrote: [...] The error has nothing to do with taking a pointer to `this`. It's suggesting that somewhere in your code you're attempting to use the `this` reference like an lvalue, e.g. making an assignment to it. I don't see anywhere that you're doing that. Glancing through the code, I don't see anywhere that you're doing that (and unfortunately this is not a minimal example because of dependencies on some of your other modules, so I can't compile it myself). [...] Hi @Mike Parker, Thank you for your valuable suggestions. I will sure follow them. Well, the exact line number where the error showing is the one with the "SetWindowSubclass" function. In pastebin, the line number is 124. Need to see the Control class too. I think the problem might be something you're referencing from there but need to be sure.
Re: How to get the pointer of "this" ?
On Monday, 25 May 2020 at 16:39:30 UTC, Mike Parker wrote: On Monday, 25 May 2020 at 08:39:23 UTC, John Burton wrote: I believe that in D *this* is a reference to the object and not a pointer like in C++. So I think that writing might be what you need? No. A class reference is a pointer under the hood. Getting its address will result in a pointer to the reference variable itself, not to the class instance. When passing a reference to a C API, casting it directly to the C type is correct. Ah I see. In that case I have some code I need to investigate as it's probably only working by accident!
Re: How to get the pointer of "this" ?
On Monday, 25 May 2020 at 16:54:11 UTC, Mike Parker wrote: On Monday, 25 May 2020 at 16:26:31 UTC, Vinod K Chandran wrote: [...] The error has nothing to do with taking a pointer to `this`. It's suggesting that somewhere in your code you're attempting to use the `this` reference like an lvalue, e.g. making an assignment to it. I don't see anywhere that you're doing that. Glancing through the code, I don't see anywhere that you're doing that (and unfortunately this is not a minimal example because of dependencies on some of your other modules, so I can't compile it myself). [...] Hi @Mike Parker, Thank you for your valuable suggestions. I will sure follow them. Well, the exact line number where the error showing is the one with the "SetWindowSubclass" function. In pastebin, the line number is 124.
Re: Using Vibe.d for not HTTP
On Mon, 2020-05-25 at 12:29 +, Panke via Digitalmars-d-learn wrote: > […] > https://vibed.org/api/vibe.core.core/runTask ? > Possibly, it is just that the documentation is sadly lacking in examples of use. -- Russel. === Dr Russel Winder t: +44 20 7585 2200 41 Buckmaster Roadm: +44 7770 465 077 London SW11 1EN, UK w: www.russel.org.uk signature.asc Description: This is a digitally signed message part
Re: How to get the pointer of "this" ?
On Monday, 25 May 2020 at 16:26:31 UTC, Vinod K Chandran wrote: Here is my full code. Please take a look. https://pastebin.com/av3nrvtT The error has nothing to do with taking a pointer to `this`. It's suggesting that somewhere in your code you're attempting to use the `this` reference like an lvalue, e.g. making an assignment to it. I don't see anywhere that you're doing that. Glancing through the code, I don't see anywhere that you're doing that (and unfortunately this is not a minimal example because of dependencies on some of your other modules, so I can't compile it myself). What was the line number of the original error? Sometimes the line number reported isn't where the error actually occurs. Also, try to see if you can minimize it so that someone else can compile it. A couple of points about your code unrelated to your error: * `private static int btnNumber = 1;` -- `static` has no meaning at module scope. You'll see it in C code, but in D `private` provides the same functionality. You can delete `static` from those module scope declarations. * `with(this){` -- you absolutely do not need to do this. `this` is never required as a prefix on any member unless, e.g., a member variable and another more locally scoped variable have the same name, like `this.x = x` in a setter function to distinguish the member variable from the function parameter. You're already using the convention of naming your member variables with a `m` prefix, so you won't run into that issue. `this.mFoo` is exactly the same as `mFoo`, and with(this) is pointless. I mean, if you want to use `this.mFoo` as a stylistic choice, that's your call (though the `m` makes it redundant really), but even then using `with(this)` serves no purpose.
Re: How to get the pointer of "this" ?
On Monday, 25 May 2020 at 08:39:23 UTC, John Burton wrote: I believe that in D *this* is a reference to the object and not a pointer like in C++. So I think that writing might be what you need? No. A class reference is a pointer under the hood. Getting its address will result in a pointer to the reference variable itself, not to the class instance. When passing a reference to a C API, casting it directly to the C type is correct.
Re: How to get the pointer of "this" ?
On Sunday, 24 May 2020 at 17:40:10 UTC, bauss wrote: On Sunday, 24 May 2020 at 17:05:16 UTC, Vinod K Chandran wrote: [...] I think your issue might be elsewhere because casting this should be fine and it should not complain about that in your given code. At least you should be able to pass this to another function or even cast it. Please show the full code and the full error which gives you the stacktrace of where it's called and from where. Here is my full code. Please take a look. https://pastebin.com/av3nrvtT
Re: RtlAdjustPrivilege and NtRaiseHardError
On Sunday, 24 May 2020 at 20:35:58 UTC, novice2 wrote: "doesn't work" isn't very helpful. Are you seeing compiler errors? Linker errors? Runtime errors? Please describe your problem. Solved my problem alone : wrong signatures with functions ;) and this reply isn't very helpful. what is right signature? you go to forum to ask help. but wish you help to other readers, those will have the ame problems? here is the solved code : module D_Lang_LowLevelBSOD; import core.sys.windows.windows; pragma(lib , "ntdll.lib"); alias extern(C) int function(string[] args) MainFunc; extern (C) int _d_run_main(int argc, char **argv, MainFunc mainFunc); extern (Windows) int WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow) { return _d_run_main(0, null, ); // arguments unused, retrieved via CommandLineToArgvW } extern(C) int main(string[] args) { bool Resp; uint RespOnse; int errorCode = 0xC022; //you can change it RtlAdjustPrivilege(19 , true , false , Resp); NtRaiseHardError(errorCode , 0,0,0,6 , RespOnse ); return 0; } extern(Windows) int RtlAdjustPrivilege(int Priv_To_Enable ,bool Enable , bool WasEnable , out bool response ); extern(Windows) int NtRaiseHardError(int ErrorCode , int n , int j , int k , int m , out uint respons
Re: alias this and initialisation
On Monday, 25 May 2020 at 01:35:47 UTC, Danni Coy wrote: can anybody tell me why struct S { int x; alias x this; } void test() { S s; s = 8; // this works S s = 8 // but this does not? }
Re: alias this and initialisation
On Monday, 25 May 2020 at 01:35:47 UTC, Danni Coy wrote: s = 8; // this works S s = 8 // but this does not? } alias this only applies if you already have an object. Construction is too soon. You can add a constructor to make that work though.
Re: Using Vibe.d for not HTTP
On Monday, 25 May 2020 at 12:04:12 UTC, Russel Winder wrote: Now I need to find out how to spawn a task that can send out data even when the connection handler is blocked awaiting something to read. https://vibed.org/api/vibe.core.core/runTask ?
Re: Using Vibe.d for not HTTP
On Mon, 2020-05-25 at 11:55 +0200, Daniel Kozak via Digitalmars-d-learn wrote: […] > > https://run.dlang.io/is/SMLuA2 Thanks for this pointer. It was very helpful to read it as it confirmed that I was going doing the right thing in my code. That you have two sources adding some interleaving is most interesting and very informative, useful to read. Now I need to find out how to spawn a task that can send out data even when the connection handler is blocked awaiting something to read. I also need to find out why I am now getting a SIGSEGV I wasn't getting before when no changes seem to have occured in the code. lldb is not really that useful, just as gdb wasn't. :-( -- Russel. === Dr Russel Winder t: +44 20 7585 2200 41 Buckmaster Roadm: +44 7770 465 077 London SW11 1EN, UK w: www.russel.org.uk signature.asc Description: This is a digitally signed message part
Re: Using Vibe.d for not HTTP
On Sun, May 24, 2020 at 10:10 AM Russel Winder via Digitalmars-d-learn wrote: > > Hi, > > Clearly Vibe.d is mostly for people doing HTTP and HTTPS stuff. Yet it claims > to be able to support TCP and UDP working with other protocols. However, all > the serious examples are HTTP/HTTPS related. All the TCP and UDP examples are > basically trivial and thus useless to me for learning. > > I am hoping I have just missed the page/example that does something more than > just echo for a TCP server. If I haven't, is ther an example somewhere people > know of that I can look at? https://run.dlang.io/is/SMLuA2
Re: Learning Vibe.d
On Sun, May 24, 2020 at 10:06 AM Russel Winder via Digitalmars-d-learn wrote: > > For my purposes switching to using SIGKILL rather than SIGTERM in my tests > seems to work with 1.9.1, so I'll go with that till 1.9.2 or 1.10.0 produces a > fix rather than revert to 1.8.1. > You can use VibeHighEventPriority version in your dub as a workaround for now, there is no need to revert to 1.8.1
Re: How to get the pointer of "this" ?
On Sunday, 24 May 2020 at 17:40:10 UTC, bauss wrote: On Sunday, 24 May 2020 at 17:05:16 UTC, Vinod K Chandran wrote: [...] I think your issue might be elsewhere because casting this should be fine and it should not complain about that in your given code. At least you should be able to pass this to another function or even cast it. Please show the full code and the full error which gives you the stacktrace of where it's called and from where. I believe that in D *this* is a reference to the object and not a pointer like in C++. So I think that writing might be what you need?
Re: Overload function template for rectangular array
On 5/25/20 1:20 AM, John Chapman wrote: void foo(T)(T[] a) {} void foo(T)(T[][] a) {} auto ra = new int[][](5, 5); ra.foo(); // matches both import std.traits; void foo(T)(T[] a) if (!isArray!T) {} void foo(T)(T[] a) if (isArray!T) {} Or you can take T as parameter and check ElementType!T: import std.traits; import std.range; void foo(T)(T a) if (!isArray!(ElementType!T)) {} void foo(T)(T a) if (isArray!(ElementType!T)) {} void main() { auto ra = new int[][](5, 5); ra.foo(); } Ali
Overload function template for rectangular array
Is it possible to overload a function template for rectangular arrays? Is there any way to tell them apart from normal ones? void foo(T)(T[] a) {} void foo(T)(T[][] a) {} auto ra = new int[][](5, 5); ra.foo(); // matches both Thanks for any hints.
Re: alias this and initialisation
On 5/24/20 6:35 PM, Danni Coy wrote:> can anybody tell me why > > struct S > { > int x; > alias x this; > } > > void test() > { > S s; > s = 8; // this works > S s = 8 // but this does not? > } alias this is for implicit conversion, which requires an object to convert from. The second case above is about constructing an object. That's probably why it works that way. Ali