Re: noobie question, dub or meson?
Meson doesn't track dependencies properly for d, so your dirty builds will be wrong if you go that route. You might consider keeping the c and d code in the same repository, but with separate build systems; using dub to build the d code and and whatever tool you prefer for c. Or try reggae.
noobie question, dub or meson?
Hi D I've started a D layer for one of my C libraries that's adds some new functionality and a bit of an interface upgrade. In turn I'm using this combined code-base as a dependency for D "scripts". Since my software is used by a few outside groups in my field, it seems I should get used to packaging D modules, even if those packages never make it to the central dub repo. Given that source code for the combined library is some D but mostly C, would you recommend that I: 1) Keep the D sources and C sources in separate projects? 2) Use meson to create a combined package? 3) Use dub to create a combined package? 4) Some other option? The D code is useless without it's C core, so a dub package that just includes the D parts would be disappointing. The library's not huge, only about 25K lines, but I don't think I have time for a straight conversion of the whole thing to D at this point. Thanks for your opinions on the matter,
Re: rdmd and D equivalent for PYTHONPATH?
On Wednesday, 17 March 2021 at 20:24:19 UTC, Tobias Pankrath wrote: For scripts this could be a good way, but it does not really work with most dub packages: 1. put all your dependencies into a single location, like /home//dstuff 2. add -I /home//dstuff to your call to rdmd/dmd (or put into /etc/dmd.conf 3. add -i (lowercase) to your call of rdmd/dmd 4. profit I tried that route, and it's not too bad, but I have C library dependencies so I start getting shebangs that look like this: #!/usr/bin/env -S rdmd -i -I${D_PATH} -L-L${LD_LIBRARY_PATH} -L-ldas2.3 -L-lexpat -L-lssl -L-lfftw3 So kinda messy, though the rdmd -i option is nice. Since the dub packages have the linker info builtin, it seemed better to use this instead: #!/usr/bin/env dub and to assist with finding local packages, throw in some sort of local search path via an environment variable reference in the dub.sdl section. If everyone used the same environment variable in dub.sdl comment it could become a defacto standard for scripts, similar to PYTHONPATH or MATLABPATH, though not nearly as fundamental. To make this work the dependencies must have the correct project layout, e.g. sources should be in the top-level project directory and not in a subdirectory source. This rules out most dub packages :/ Yea, this seemed strange to me. I'd think that a group would want the compiler's module lookup semantics to match the common package layout scheme and vice-versa. But since I'm new around here I'll just assume that the mismatch came about for a reason. The dub designers were probably trying to solve some problem that I'm unaware of.
Re: rdmd and D equivalent for PYTHONPATH?
On Wednesday, 17 March 2021 at 20:13:49 UTC, Imperatorn wrote: On Wednesday, 17 March 2021 at 19:33:26 UTC, Chris Piker wrote: On Wednesday, 17 March 2021 at 09:34:21 UTC, Mike Parker wrote: [...] Sure will, thanks for the invite to contribute in a specific way. [...] You probably already know this, just sharing: https://atilaoncode.blog/2020/02/19/want-to-call-c-from-python-use-d/ Hey, that looks nice. I'm trying to get away from python as the front end language, but I do have a fair bit of C code running around and there are a lot of python users. Thanks for the tip :)
rawRead from Pipe segfaults
In order to watch out for lost bytes in a pipe I encountered this segfault. It seems that the readEnd is already closed when rawRead = fread is called (uncomment the eof line). How do I keep the pipe open? ```piperawreadsegfault.d (linux) import std.stdio; import std.process; void main () { auto dev_zero = File ("/dev/zero", "r"); auto dev_null = File ("/dev/null", "w"); auto p = pipe (); auto proc1 = spawnProcess (["dd", "bs=4096", "count=2"], dev_zero, p.writeEnd); auto proc2 = spawnProcess (["dd", "bs=4096", "count=1"], p.readEnd, dev_null); auto res2 = wait (proc2); auto res1 = wait (proc1); stderr.writeln ("res1 = ", res1, ", res2 = ", res2); // stderr.writeln (p.readEnd.eof); ubyte [1] u; auto n = p.readEnd.rawRead (u); } ``` $ dmd -g piperawreadsegfault $ gdb ./piperawreadsegfault (gdb) r Starting program: /tmp/k/piperawreadsegfault [Thread debugging using libthread_db enabled] Using host libthread_db library "/lib64/libthread_db.so.1". 2+0 records in 2+0 records out 8192 bytes (8.2 kB) copied, 2.487e-05 s, 329 MB/s 1+0 records in 1+0 records out 4096 bytes (4.1 kB) copied, 2.0234e-05 s, 202 MB/s res1 = 0, res2 = 0 Program received signal SIGSEGV, Segmentation fault. 0x77054f99 in fread () from /lib64/libc.so.6 (gdb) bt #0 0x77054f99 in fread () from /lib64/libc.so.6 #1 0x0048fd96 in std.stdio() (obj=..., f=0x0) at [...]/dmd2/linux/bin64/../../src/phobos/std/stdio.d:4383 #2 0x0048fcb7 in std.stdio.File() (this=..., buffer=...) at [...]/dmd2/linux/bin64/../../src/phobos/std/stdio.d:1036 #3 0x0048f10a in D main () at piperawreadsegfault.d:18 [...]
Re: How to delete dynamic array ?
On 3/17/21 10:21 AM, jmh530 wrote: > That's a little advanced, I think. And you also have > http://ddili.org/ders/d.en/slices.html > saying that slices are just another name for dynamic arrays. I don't fully agree with myself there. :) Slices are interfaces to many different kinds of consecutive objects: nameless dynamic arrays owned by the GC, static arrays, dynamic arrays managed by the programmer, etc. The conflation stems from the fact that the storage for the slice becomes "a dynamic array owned by the GC" as soon as new storage is needed: appending, concatenation, and increasing the length. The slice leaves its existing storage just like that. Ali
Re: Why Throwable.message is not a property
On Wednesday, 17 March 2021 at 19:38:48 UTC, Adam D. Ruppe wrote: On Wednesday, 17 March 2021 at 19:32:02 UTC, uranuz wrote: Seems that a problem with concatenation is because Throwable.message has const(char)[] type, but not string. This makes some inconvenience ;-) Yes, that's what I thought. The concat operation tends to give the most flexible type of the arguments... and I wish it would then ACTUALLY use that flexibility... but it doesn't. Regardless though since you know you are concating it, which means you get a new string anyway, you can safely cast(string) it. string longMsg = "The: " ~ cast(string) exc.message; that's how i do it. This is what I have done ;-)
Re: rdmd and D equivalent for PYTHONPATH?
On Wednesday, 17 March 2021 at 19:33:26 UTC, Chris Piker wrote: So, if I could do the equivalent of: dub add-path via an environment variable (not a permanent change under ~/.dub), or have some environment variable that tells dub where to read a "system-level" local-packages.json file and merge it's paths in with any personal settings, that would likely handle our internal code sharing needs. For scripts this could be a good way, but it does not really work with most dub packages: 1. put all your dependencies into a single location, like /home//dstuff 2. add -I /home//dstuff to your call to rdmd/dmd (or put into /etc/dmd.conf 3. add -i (lowercase) to your call of rdmd/dmd 4. profit -i automatically adds all modules that are imported to the compilation, i.e. all your dependencies are compiled together with your code, when they are needed. It searches for them where -I points to. To make this work the dependencies must have the correct project layout, e.g. sources should be in the top-level project directory and not in a subdirectory source. This rules out most dub packages :/
Re: rdmd and D equivalent for PYTHONPATH?
On Wednesday, 17 March 2021 at 19:33:26 UTC, Chris Piker wrote: On Wednesday, 17 March 2021 at 09:34:21 UTC, Mike Parker wrote: [...] Sure will, thanks for the invite to contribute in a specific way. [...] You probably already know this, just sharing: https://atilaoncode.blog/2020/02/19/want-to-call-c-from-python-use-d/
Re: Why Throwable.message is not a property
On Wednesday, 17 March 2021 at 19:32:02 UTC, uranuz wrote: Seems that a problem with concatenation is because Throwable.message has const(char)[] type, but not string. This makes some inconvenience ;-) Yes, that's what I thought. The concat operation tends to give the most flexible type of the arguments... and I wish it would then ACTUALLY use that flexibility... but it doesn't. Regardless though since you know you are concating it, which means you get a new string anyway, you can safely cast(string) it. string longMsg = "The: " ~ cast(string) exc.message; that's how i do it.
Re: rdmd and D equivalent for PYTHONPATH?
On Wednesday, 17 March 2021 at 09:34:21 UTC, Mike Parker wrote: On Wednesday, 17 March 2021 at 07:13:31 UTC, Chris Piker wrote: Very handy example. Unfortunately it means that paths are embedded in scripts, which is usually a bad idea. The ability to use D source modules “script style” is something that has grown organically over time largely as a convenience. I doubt anyone is using it heavily enough to have tested the boundaries, In your exploration of those boundaries, please take note of what you discover so they can potentially be expanded where possible. Sure will, thanks for the invite to contribute in a specific way. D looks to be a good replacement for split Python/C development though I don't want to drag all my python baggage in here. I'm trying to understand the D way of doing things before suggesting changes. Interpreted languages like Python MATLAB, IDL are the norm in my field. So anything that makes D easier to use for "quick-and-dirty" data analysis tasks would make it more palatable to the casual programmers I interact with. I general dub seems fantastic! I was stunned yesterday by a three-line vibe.d test script I ran that produced a compiled running web-server. So, if I could do the equivalent of: dub add-path via an environment variable (not a permanent change under ~/.dub), or have some environment variable that tells dub where to read a "system-level" local-packages.json file and merge it's paths in with any personal settings, that would likely handle our internal code sharing needs.
Re: Why Throwable.message is not a property
On Wednesday, 17 March 2021 at 17:52:20 UTC, Adam D. Ruppe wrote: On Wednesday, 17 March 2021 at 17:46:27 UTC, uranuz wrote: Also because it is not a property in some contexts when I try to concatenate it with string without parentheses using "~" operator it fails Can you post some sample code that demonstrates this? Seems that a problem with concatenation is because Throwable.message has const(char)[] type, but not string. This makes some inconvenience ;-) There is an example: import std; void main() { auto exc = new Exception("Test"); string longMsg = "The: " ~ exc.message; // Adding parentheses () after "message" actually doesn't change anything. Error is the same writeln(longMsg); } Compile error: onlineapp.d(6): Error: cannot implicitly convert expression "The: " ~ exc.message() of type char[] to string I could add cast(string), but it's not something I want to do. The reason, why I want to use "message" instead of "msg" is that I want to add some extra information to exception as separate typed fields. But I want it to be displayed when converting exception to string. So I shall override "message" and convert this extra info to string...
Re: Is it possible to suppress standard lib and dlang symbols in dylib (macos)
On Wednesday, 17 March 2021 at 15:16:36 UTC, Jacob Carlborg wrote: On Wednesday, 17 March 2021 at 13:52:48 UTC, Guillaume Piolat wrote: On Sunday, 14 March 2021 at 11:33:00 UTC, David wrote: Anyone else done this? Pointers welcome. Sorry for delay. Just add "dflags-osx-ldc": ["-static"], macOS doesn't support static linking. -- /Jacob Carlborg Ah that's really useful to know, thanks - this is my first bit of macOS dev (other than high level stuff like R, Python, kdb etc) and I'm having to learn more about internals than I really care to - ho hum.
Re: Why Throwable.message is not a property
On Wednesday, 17 March 2021 at 17:46:27 UTC, uranuz wrote: Also because it is not a property in some contexts when I try to concatenate it with string without parentheses using "~" operator it fails Can you post some sample code that demonstrates this?
Why Throwable.message is not a property
The question is why Throwable.message is not a @property?! It looks strange now, because "message" is not a *verb*, but a *noun*. So it's expected to be a property. Also because it is not a property in some contexts when I try to concatenate it with string without parentheses using "~" operator it fails, because (as you could expect) it is a *regular* function, but not a property. I wonder if it was made as *non-property* by some reason or by oversight? Thanks
Re: can't link a code, is it a bug or my fault?
On Thursday, 11 March 2021 at 17:41:27 UTC, rikki cattermole wrote: Try it with: -allinst It may just be deciding a template instance isn't required. The error message could maybe be changed to include this? "Try -allinst bla bla"
Re: How to delete dynamic array ?
On Wednesday, 17 March 2021 at 16:32:28 UTC, Ali Çehreli wrote: On 3/17/21 3:54 AM, jmh530 wrote: On Tuesday, 16 March 2021 at 23:49:00 UTC, H. S. Teoh wrote: double[] data; data = cast(double[]) malloc(n * double.sizeof)[0 .. n]; This is one of those things that is not explained well enough. I have something here: http://ddili.org/ders/d.en/pointers.html#ix_pointers.slice%20from%20pointer Ali That's a little advanced, I think. And you also have http://ddili.org/ders/d.en/slices.html saying that slices are just another name for dynamic arrays.
Re: How to delete dynamic array ?
On Wednesday, 17 March 2021 at 16:20:06 UTC, Steven Schveighoffer wrote: [snip] I've had online battles about this terminology, and people asked me to change my array article to disavow this distinction, but I'm not going to change it. It's so much easier to understand. -Steve I'll be on your side on that one.
Re: can't link a code, is it a bug or my fault?
On Thursday, 11 March 2021 at 17:41:27 UTC, rikki cattermole wrote: Try it with: -allinst It may just be deciding a template instance isn't required. Good workaround for such kind of bugs! ) Up to 2.063 : Failure with output: Error: unrecognized switch '-allinst' Since 2.064 : Success and no output
Remove routes from URLRouter in vibe.d
I want to be able to dynamically remove some routes in my Vibe.d application. URLRouter accounts for newly added routes, but I can't find a way to clear routes unless I create the new URLRouter object, in which case I also need to re-create HTTP listener. Also, is it safe to replace already existing route handlers?
Re: How to delete dynamic array ?
On 3/17/21 3:54 AM, jmh530 wrote: On Tuesday, 16 March 2021 at 23:49:00 UTC, H. S. Teoh wrote: double[] data; data = cast(double[]) malloc(n * double.sizeof)[0 .. n]; This is one of those things that is not explained well enough. I have something here: http://ddili.org/ders/d.en/pointers.html#ix_pointers.slice%20from%20pointer Ali
Re: How to delete dynamic array ?
On 3/17/21 12:06 PM, jmh530 wrote: On Wednesday, 17 March 2021 at 14:30:26 UTC, Guillaume Piolat wrote: On Wednesday, 17 March 2021 at 10:54:10 UTC, jmh530 wrote: This is one of those things that is not explained well enough. Yes. I made this article to clear up that point: https://p0nce.github.io/d-idioms/#Slices-.capacity,-the-mysterious-property "That a slice own or not its memory is purely derived from the pointed area." could perhaps better be said "A slice is managed by the GC when the memory it points to is in GC memory"? I probably skimmed over the link when I originally read it without really understanding it. I'm able to understand it now. I think the underlying issue that needs to get explained better is that when you do int[] x = [1, 2, 3]; the result is always a GC-allocated dynamic array. However, z below int[3] y = [1, 2, 3]; int[] z = y[]; does not touch the GC at all. For a long time, I operated under the assumption that dynamic arrays and slices are the same thing and that dynamic arrays are always GC-allocated. z is obviously a slice of y, but it is also a dynamic array in the sense that you can append to it and get an array with one more member than y (except in @nogc code). However, when appending to z, it seems that what's really happening is that the GC is allocating a new part of memory, copying over the original value of y and then copying in the new value. So it really becomes a new kind of thing (even if the type is unchanged). One takeaway is there is no issue with a function like below @nogc void foo(T)(T[] x) {} so long as you don't actually need the GC within the function. A static array can be passed in just using a slice. This is why I view slices as not dynamic arrays. I think of a slice as pointing at memory. When you append it effectively: 1. Checks to see if the underlying memory is GC allocated. 2. If not, it allocates new GC memory to hold the original memory + the appended data 3. It appends the data to the GC block that it now must point at. In this way, it presents a dynamic array *interface*, but it's not necessarily pointing at a dynamic array type (at least in the way I think of a dynamic array type). I've had online battles about this terminology, and people asked me to change my array article to disavow this distinction, but I'm not going to change it. It's so much easier to understand. -Steve
Re: How to delete dynamic array ?
On Wednesday, 17 March 2021 at 14:30:26 UTC, Guillaume Piolat wrote: On Wednesday, 17 March 2021 at 10:54:10 UTC, jmh530 wrote: This is one of those things that is not explained well enough. Yes. I made this article to clear up that point: https://p0nce.github.io/d-idioms/#Slices-.capacity,-the-mysterious-property "That a slice own or not its memory is purely derived from the pointed area." could perhaps better be said "A slice is managed by the GC when the memory it points to is in GC memory"? I probably skimmed over the link when I originally read it without really understanding it. I'm able to understand it now. I think the underlying issue that needs to get explained better is that when you do int[] x = [1, 2, 3]; the result is always a GC-allocated dynamic array. However, z below int[3] y = [1, 2, 3]; int[] z = y[]; does not touch the GC at all. For a long time, I operated under the assumption that dynamic arrays and slices are the same thing and that dynamic arrays are always GC-allocated. z is obviously a slice of y, but it is also a dynamic array in the sense that you can append to it and get an array with one more member than y (except in @nogc code). However, when appending to z, it seems that what's really happening is that the GC is allocating a new part of memory, copying over the original value of y and then copying in the new value. So it really becomes a new kind of thing (even if the type is unchanged). One takeaway is there is no issue with a function like below @nogc void foo(T)(T[] x) {} so long as you don't actually need the GC within the function. A static array can be passed in just using a slice.
What happened to std.net.curl HTTP execute?
I am using std.net.curl and the following chunk of code in many places: """ http.setPostData(userData, "application/json"); http.addRequestHeader("Accept", "application/json"); http.addRequestHeader("Authorization", "BEARER " ~ clientAccessToken); auto jsonData = http.execute.parseJSON; if (jsonData.isNull) { """ Today I tried to compile one of the scripts and it failed with Error: no property execute for type std.net.curl.HTTP When was it removed? I checked GitHub history briefly but the latest change dates back to April 2020 when these scripts were not even written. How did they work couple of months ago? I am confused.
Re: How to delete dynamic array ?
On Wednesday, 17 March 2021 at 14:30:26 UTC, Guillaume Piolat wrote: On Wednesday, 17 March 2021 at 10:54:10 UTC, jmh530 wrote: This is one of those things that is not explained well enough. I want just to add, case 3 is wrong usage. Right one is: GC.free(GC.addrOf(ar.ptr));
Re: Is it possible to suppress standard lib and dlang symbols in dylib (macos)
On Wednesday, 17 March 2021 at 15:16:36 UTC, Jacob Carlborg wrote: macOS doesn't support static linking. The proper way to solve this is to bundle the dynamic libraries with the application. If it's a GUI application it can be located in the application bundle. It seems like David already figured this out [1]. [1] https://forum.dlang.org/post/wsvlwdgzswxprtfjz...@forum.dlang.org -- /Jacob Carlborg
Re: Is it possible to suppress standard lib and dlang symbols in dylib (macos)
On Wednesday, 17 March 2021 at 13:52:48 UTC, Guillaume Piolat wrote: On Sunday, 14 March 2021 at 11:33:00 UTC, David wrote: Anyone else done this? Pointers welcome. Sorry for delay. Just add "dflags-osx-ldc": ["-static"], macOS doesn't support static linking. -- /Jacob Carlborg
Re: How to delete dynamic array ?
On Wednesday, 17 March 2021 at 10:54:10 UTC, jmh530 wrote: This is one of those things that is not explained well enough. Yes. I made this article to clear up that point: https://p0nce.github.io/d-idioms/#Slices-.capacity,-the-mysterious-property "That a slice own or not its memory is purely derived from the pointed area." could perhaps better be said "A slice is managed by the GC when the memory it points to is in GC memory"?
Re: Is it possible to suppress standard lib and dlang symbols in dylib (macos)
On Sunday, 14 March 2021 at 11:33:00 UTC, David wrote: Anyone else done this? Pointers welcome. Sorry for delay. Just add "dflags-osx-ldc": ["-static"],
Re: How to change button text color in NM_CUSTOMDRAW (Win32 API question)
On Wednesday, 17 March 2021 at 06:39:26 UTC, Imperatorn wrote: Good that you solved it, that wasn't what I thought the solution would be 👀 I was sure about i can solve this through NM_CUSTOMDRAW. Because, in VB .net, we can change back color & fore color of button. On the same time, there is an option to turn on the OwnerDrawStyle. If we set this property true, we need to draw the button on our own. So i am pretty sure that, that property will turn a normal button to an owner drawn button. But if we don't use that property, then also we can change the button colors. So that means, without using BS_OWNERDRAW style, we can change the colors. And that's the NM_CUSTOMDRAW message. Unfortunately, there is not much tutorials or documentation about handling this message in a Button's case. We can find some examples and articles related to ListView & Treeview. But not a single line of documentation about buttons. Was more than 10 years ago since I was "the king of win api" 😔 Glad to know that. Can you write an article about how to use Gdi+ in win api apps ? Now I am using gdi. But i want to test how gdi+ works on win32 apps.
Re: How to delete dynamic array ?
On Tuesday, 16 March 2021 at 23:49:00 UTC, H. S. Teoh wrote: [snip] Note that T[] is just a slice, not the dynamic array itself. The dynamic array is allocated and managed by the GC when you append stuff to it, or when you create a new array with `new` or an array literal. None of the latter, however, precludes you from using T[] for memory that you manage yourself. For example, you could do this: double[] data; data = cast(double[]) malloc(n * double.sizeof)[0 .. n]; Now you have a slice to memory you allocated yourself, and you have to manage its lifetime manually. When you're done with it: free(data.ptr); data = []; // null out dangling pointer, just in case The GC does not get involved unless you actually allocate from it. As long as .ptr does not point to GC-managed memory, the GC will not care about it. (Be aware, though, that the ~ and ~= operators may allocate from the GC, so you will have to refrain from using them. @nogc may help in this regard.) T This is one of those things that is not explained well enough.
Re: rdmd and D equivalent for PYTHONPATH?
On Wednesday, 17 March 2021 at 07:13:31 UTC, Chris Piker wrote: Very handy example. Unfortunately it means that paths are embedded in scripts, which is usually a bad idea. The ability to use D source modules “script style” is something that has grown organically over time largely as a convenience. I doubt anyone is using it heavily enough to have tested the boundaries, In your exploration of those boundaries, please take note of what you discover so they can potentially be expanded where possible.
Re: rdmd and D equivalent for PYTHONPATH?
On Wednesday, 17 March 2021 at 07:13:31 UTC, Chris Piker wrote: On Wednesday, 17 March 2021 at 06:07:01 UTC, user1234 wrote: [...] Very handy example. Unfortunately it means that paths are embedded in scripts, which is usually a bad idea. [...] You can use a local registry too. That should work but ten the dep version must be set to "*". See https://dub.pm/commandline.html#add-local
Re: rdmd and D equivalent for PYTHONPATH?
On Wednesday, 17 March 2021 at 06:07:01 UTC, user1234 wrote: You can use local a specific local version too, for example the git repository #!/usr/bin/env dub /+ dub.sdl: dependency "mir-algorithm" path="/home/x/repositories/mir/mir-algorithm" +/ In addition with --nodeps, no internet is required. Very handy example. Unfortunately it means that paths are embedded in scripts, which is usually a bad idea. I'm still looking for environment variables or config files that affect dub's module include path. Is there dub variable to give a general path for all dependencies? Since dub can read environment variables, this may be a way to get a top-level module directory known to scripts without hard coding paths. Also, what do people do when generating .deb or .rpm packages for D libraries? They must reference some local library path in a general fashion (I would think). The only module paths I see referenced in: /etc/dmd.conf are for phobos and the runtime import. I guess I could just add another one there. Not sure if gdc also uses that file.