Re: Library for image editing and text insertion
On Wednesday, 27 April 2022 at 00:03:25 UTC, Adam Ruppe wrote: Sample code would be: Ego have problems cum scribendarum hic quoque, fortasse opus est dare aliquid aliud, cum componendis? ```d ~/programming/d/pic $ dmd app.d /usr/bin/ld: app.o:(.data.rel.ro+0x10): undefined reference «_D4arsd5image12__ModuleInfoZ» /usr/bin/ld: app.o:(.data.rel.ro+0x30): undefined reference «_D4arsd3png12__ModuleInfoZ» /usr/bin/ld: app.o: в функции «_Dmain»: app.d:(.text._Dmain[_Dmain]+0xcb): undefined reference «_D4arsd3ttf7TtfFont6__ctorMFNcIAhZSQBhQBfQBe» /usr/bin/ld: app.d:(.text._Dmain[_Dmain]+0xfb): undefined reference «_D4arsd3ttf7TtfFont12renderStringMFIAaiJiJiZAh» /usr/bin/ld: app.d:(.text._Dmain[_Dmain]+0x297): undefined reference «_D4arsd5color5Color6__ctorMFNaNbNcNiNfZSQBqQBoQBl» /usr/bin/ld: app.d:(.text._Dmain[_Dmain]+0x2a2): undefined reference «_D4arsd5color5Color10alphaBlendMxFNaNbNiNeSQBpQBnQBkZQl» /usr/bin/ld: app.d:(.text._Dmain[_Dmain]+0x31a): undefined reference «_D4arsd3png8writePngFAyaCQx5color11MemoryImageZv» /usr/bin/ld: app.o: в функции «_D4arsd5image__T17loadImageFromFileHTAyaZQzFQhZCQBu5color11MemoryImage»: app.d:(.text._D4arsd5image__T17loadImageFromFileHTAyaZQzFQhZCQBu5color11MemoryImage[_D4arsd5image__T17loadImageFromFileHTAyaZQzFQhZCQBu5color11MemoryImage]+0x1f): undefined reference «_D4arsd5image29guessImageFormatFromExtensionFAxaZEQBwQBu15ImageFileFormat» /usr/bin/ld: app.d:(.text._D4arsd5image__T17loadImageFromFileHTAyaZQzFQhZCQBu5color11MemoryImage[_D4arsd5image__T17loadImageFromFileHTAyaZQzFQhZCQBu5color11MemoryImage]+0x1d8): undefined reference «_D4arsd5image19loadImageFromMemoryFAxvZCQBm5color11MemoryImage» /usr/bin/ld: app.d:(.text._D4arsd5image__T17loadImageFromFileHTAyaZQzFQhZCQBu5color11MemoryImage[_D4arsd5image__T17loadImageFromFileHTAyaZQzFQhZCQBu5color11MemoryImage]+0x297): undefined reference «_D4arsd3png7readPngFAyaZCQx5color11MemoryImage» /usr/bin/ld: app.d:(.text._D4arsd5image__T17loadImageFromFileHTAyaZQzFQhZCQBu5color11MemoryImage[_D4arsd5image__T17loadImageFromFileHTAyaZQzFQhZCQBu5color11MemoryImage]+0x2a9): undefined reference «_D4arsd3bmp7readBmpFAyaZCQx5color11MemoryImage» /usr/bin/ld: app.d:(.text._D4arsd5image__T17loadImageFromFileHTAyaZQzFQhZCQBu5color11MemoryImage[_D4arsd5image__T17loadImageFromFileHTAyaZQzFQhZCQBu5color11MemoryImage]+0x2bb): undefined reference «_D4arsd4jpeg8readJpegFAxaZCQz5color11MemoryImage» /usr/bin/ld: app.d:(.text._D4arsd5image__T17loadImageFromFileHTAyaZQzFQhZCQBu5color11MemoryImage[_D4arsd5image__T17loadImageFromFileHTAyaZQzFQhZCQBu5color11MemoryImage]+0x341): undefined reference «_D4arsd5image7readSvgFAyaZCQz5color11MemoryImage» /usr/bin/ld: app.o: в функции «_D4arsd5targa__T11loadTgaImplTS3std5stdio4FileZQBfFKQwAxaZCQCf5color11MemoryImage»: app.d:(.text._D4arsd5targa__T11loadTgaImplTS3std5stdio4FileZQBfFKQwAxaZCQCf5color11MemoryImage[_D4arsd5targa__T11loadTgaImplTS3std5stdio4FileZQBfFKQwAxaZCQCf5color11MemoryImage]+0x9ab): undefined reference «_D4arsd5color14TrueColorImage7__ClassZ» /usr/bin/ld: app.d:(.text._D4arsd5targa__T11loadTgaImplTS3std5stdio4FileZQBfFKQwAxaZCQCf5color11MemoryImage[_D4arsd5targa__T11loadTgaImplTS3std5stdio4FileZQBfFKQwAxaZCQCf5color11MemoryImage]+0x9c6): undefined reference «_D4arsd5color14TrueColorImage6__ctorMFNaNbNfiiZCQBuQBsQBp» /usr/bin/ld: app.d:(.text._D4arsd5targa__T11loadTgaImplTS3std5stdio4FileZQBfFKQwAxaZCQCf5color11MemoryImage[_D4arsd5targa__T11loadTgaImplTS3std5stdio4FileZQBfFKQwAxaZCQCf5color11MemoryImage]+0xa01): undefined reference «_D4arsd5color14TrueColorImage4Data6colorsMNgFNaNbNdNiNeZANgSQCgQCe5Color» /usr/bin/ld: app.d:(.text._D4arsd5targa__T11loadTgaImplTS3std5stdio4FileZQBfFKQwAxaZCQCf5color11MemoryImage[_D4arsd5targa__T11loadTgaImplTS3std5stdio4FileZQBfFKQwAxaZCQCf5color11MemoryImage]+0xc12): undefined reference «_D4arsd5color14TrueColorImage4Data6colorsMNgFNaNbNdNiNeZANgSQCgQCe5Color» /usr/bin/ld: app.d:(.text._D4arsd5targa__T11loadTgaImplTS3std5stdio4FileZQBfFKQwAxaZCQCf5color11MemoryImage[_D4arsd5targa__T11loadTgaImplTS3std5stdio4FileZQBfFKQwAxaZCQCf5color11MemoryImage]+0xd02): undefined reference «_D4arsd5color14TrueColorImage4Data6colorsMNgFNaNbNdNiNeZANgSQCgQCe5Color» /usr/bin/ld: app.d:(.text._D4arsd5targa__T11loadTgaImplTS3std5stdio4FileZQBfFKQwAxaZCQCf5color11MemoryImage[_D4arsd5targa__T11loadTgaImplTS3std5stdio4FileZQBfFKQwAxaZCQCf5color11MemoryImage]+0xd5e): undefined reference «_D4arsd5color14TrueColorImage4Data6colorsMNgFNaNbNdNiNeZANgSQCgQCe5Color» /usr/bin/ld: app.o: в функции «_D4arsd5targa__T11loadTgaImplTS3std5stdio4FileZQBfFKQwAxaZ__T11readColor16Vbi0ZQsMFMDFZhZSQDk5color5Color»: app.d:(.text._D4arsd5targa__T11loadTgaImplTS3std5stdio4FileZQBfFKQwAxaZ__T11readColor16Vbi0ZQsMFMDFZhZSQDk5color5Color[_D4arsd5targa__T11loadTgaImplTS3std5stdio4FileZQBfFKQwAxaZ__T11readColor16Vbi0ZQsMFMDFZhZSQDk5color5Color]+0xab): undefined reference «_D4arsd5color5Color6__ctorMFNaNbNcNiNfZSQBqQBoQBl» /usr/bin/ld: app.o: в функции «_D4arsd5targa__T1
Re: Library for image editing and text insertion
On Wednesday, 27 April 2022 at 07:42:31 UTC, Alexander Zhirov wrote: ```d ~/programming/d/pic $ dmd app.d ``` Try passing the `-i` flag: `dmd -i app.d`. This way, imported modules are actually compiled and linked too. Currently it looks like you import arsd, but then don't link the library, so it complains about undefined references to functions in arsd.
Re: Library for image editing and text insertion
On Wednesday, 27 April 2022 at 07:42:31 UTC, Alexander Zhirov wrote: On Wednesday, 27 April 2022 at 00:03:25 UTC, Adam Ruppe wrote: Sample code would be: My inattention, it was necessary to write like this: ```sh dmd app.d -i arsd/image.d ``` Now everything is compiled and really the way I need it! Thank you very much! There are two more questions left: 1) How to write to jpeg correctly? 2) How can I reduce the size of the executable file? And then 3 megabytes is too much for such a utility.
Re: Library for image editing and text insertion
On Wednesday, 27 April 2022 at 08:29:27 UTC, Alexander Zhirov wrote: On Wednesday, 27 April 2022 at 07:42:31 UTC, Alexander Zhirov wrote: On Wednesday, 27 April 2022 at 00:03:25 UTC, Adam Ruppe wrote: Sample code would be: 1) How to write to jpeg correctly? That's how I managed to write to jpeg: ```d writeJpeg("dst.jpg", tci); ``` Now I would like to reduce the size of the executable file and it would be great at all!
Re: Language server
On Tuesday, 26 April 2022 at 18:15:57 UTC, Alain De Vos wrote: In a perfect world there would be someone uploading a youtube video how to implement neovim with a dlang language-server. With function-completions-help where hints are given about the functions and libraries. If anyone could do this , this would be nice to have. I'm not a vim user, but there is this: https://wiki.dlang.org/D_in_Vim If that is what you needed to get what you want, maybe make a YouTube video about it ;-) -- Bastiaan.
Re: Library for image editing and text insertion
On Wednesday, 27 April 2022 at 09:27:24 UTC, Alexander Zhirov wrote: Now I would like to reduce the size of the executable file and it would be great at all! Try the `-release` option to `dmd`. Or use LDC. -- Bastiaan.
CTFE and BetterC compatibility
Hello, I want to make a SAX XML parser in D that I could both use at run-time or compile-time. Also when I use it at compile-time, I would like to use BetterC so I don't have to link D-runtime. But I have some compilation problems. I use GDC (GCC 9.4.0). Here's a reduced sample code: ``` struct Data { int[] digits; } int parseDigit(char c) pure { return c - '0'; } Data parse(string str) pure { Data data; while (str.length != 0) { // Skip spaces while (str[0] == ' ') str = str[1 .. $]; // Parse single digit integer data.digits ~= parseDigit(str[0]); // Consume digit str = str[1 .. $]; } return data; } enum Data parsedData = parse("5 4 2 6 9"); extern(C) int main() { pragma(msg, "First digit=", parsedData.digits[0]); return 0; } ``` If I compile and link against D-runtime, it works: ``` $ gcc test.d -lgdruntime -o test First digit=5 ``` If I compile with BetterC (no D-runtime for GDC), I get a compilation error about RTTI: ``` $ gcc test.d -fno-druntime -o test test.d: In function ‘parse’: test.d:25:21: error: ‘object.TypeInfo’ cannot be used with -fno-rtti 25 | data.digits ~= parseDigit(str[0]); | ^ ``` If I compile without the BetterC switch, compilation actually works but I'll have some linker issues: ``` $ gcc test.d -o test First digit=5 /tmp/ccuPwjdv.o : In function « _D5test5parseFNaAyaZS5test4Data » : test.d:(.text+0x137) : undefined reference to « _d_arraybounds » test.d:(.text+0x183) : undefined reference to « _d_arraybounds » etc... ``` The operation requiring the D-runtime is appending the array, but it should **only** be done at compile-time. I don't understand why it requires to link against the D-runtime whereas it only needs it at compilation-time (and the compilation and CTFE interpretation works, as we can see in the last example). Is there a way to force the compiler to not emit any object ode for those functions? Or am I missing something? Regards, Claude
Re: CTFE and BetterC compatibility
On Wednesday, 27 April 2022 at 14:21:15 UTC, Claude wrote: data.digits ~= parseDigit(str[0]); Dynamic arrays are not supported using -betterC Andrea
Re: CTFE and BetterC compatibility
On Wednesday, 27 April 2022 at 14:21:15 UTC, Claude wrote: This is a long-standing pain point with BetterC (see https://issues.dlang.org/show_bug.cgi?id=19268). As for this: If I compile without the BetterC switch, compilation actually works but I'll have some linker issues: ``` $ gcc test.d -o test First digit=5 /tmp/ccuPwjdv.o : In function « _D5test5parseFNaAyaZS5test4Data » : test.d:(.text+0x137) : undefined reference to « _d_arraybounds » test.d:(.text+0x183) : undefined reference to « _d_arraybounds » etc... ``` When not using BetterC, but not linking against druntime either, you have to provide your own implementation for those functions. This is e.g. so you can replace druntime with your own version.
Re: CTFE and BetterC compatibility
This works: ```d struct Data { int[] digits; } int parseDigit(char c) pure { return c - '0'; } Data parse(string str) pure { Data data; if (__ctfe) { size_t used; data.digits.length = str.length; while (str.length != 0) { // Skip spaces while (str[0] == ' ') str = str[1 .. $]; // Parse single digit integer data.digits[used++] = parseDigit(str[0]); // Consume digit str = str[1 .. $]; } data.digits = data.digits[0 .. used]; } return data; } enum Data parsedData = parse("5 4 2 6 9"); extern(C) int main() { pragma(msg, "First digit=", parsedData.digits[0]); return 0; } ```
Re: CTFE and BetterC compatibility
On Wednesday, 27 April 2022 at 14:27:43 UTC, Stanislav Blinov wrote: This is a long-standing pain point with BetterC (see https://issues.dlang.org/show_bug.cgi?id=19268). That's what I was afraid of... Thanks for the link to the bug-report. On Wednesday, 27 April 2022 at 14:27:43 UTC, Stanislav Blinov wrote: When not using BetterC, but not linking against druntime either, you have to provide your own implementation for those functions. This is e.g. so you can replace druntime with your own version. Yeah... The problem is that there will a lot of those functions to define (for a whole XML parser). I suppose I can use cork functions with empty bodies?? I will check if the linker optimize them out...
Re: Library for image editing and text insertion
On Wednesday, 27 April 2022 at 11:59:20 UTC, Bastiaan Veelo wrote: Or use LDC. Gorgeous! LDC has compressed my code at times! Thanks again to everyone for help! Special thanks to **Adam Ruppe**
Re: A template construct like using()
On Tuesday, 26 April 2022 at 21:33:43 UTC, Chris Katko wrote: I swear I asked something like this before years ago but it doesn't show up in my previous forum posts. I'm looking for a construct that mimics using(var)/with(var) ```D bitmap* b; draw_with(b) { draw_pixel(red, 16, 16); //draw red pixel to bitmap b (b is implied above) } ``` But the code ends up being: ```D bitmap* b; set_target_bitmap(b); //entry code draw_pixel(red, 16, 16); // body set_target_bitmap(original_target); // exit code ``` The essence is wrapping something the code up in a kind of RAII-like entry and exit code that references a given target variable. Perhaps a mixin is what I'm looking for? assuming `set_target_bitmap` returns the previous target : ```d struct Bitmap { } struct PushPopBitmap { Bitmap* bitmap; Bitmap* old; alias bitmap this; this(Bitmap* bmp) { old = set_target_bitmap(bitmap = bmp); } ~this() { set_target_bitmap(old); } } Bitmap* set_target_bitmap(Bitmap* bmp); void draw_pixel(); void main() { Bitmap* bmp; with (PushPopBitmap(bmp)) draw_pixel(); } ``` At the end of the WithStatement block that restores the previous context.
Re: CTFE and BetterC compatibility
On Wednesday, 27 April 2022 at 14:34:27 UTC, rikki cattermole wrote: This works: Cool, thanks. Unfortunately, with that implementation, I need to know the maximum size for the array. It works for that particular example, but in the context of an XML file analysis, it's a bit awkward. Regarding my comment above, I tried using cork functions for missing symbols: it also works! However the linker does not optimize those functions out (I see the symbols in the executable binary)...
generic function instance without call
Hi, is it possible to get address of generic function instance for specified arguments without calling the function? Example: ```d auto foo(alias fn, Args...)(auto ref Args args){ ///return function/delegate type of `fn` for arguments `args` } void main(){ long x; auto fn = foo!((a, b) => true)(new int(42), x); static assert(is(typeof(fn) == bool function(int*, scope ref long)@safe pure nothrow @nogc )); } ```
Re: generic function instance without call
Fix: ```d auto fn = foo!((a, ref b) => true)(new int(42), x); ```
Re: CTFE and BetterC compatibility
On Wednesday, 27 April 2022 at 14:21:15 UTC, Claude wrote: The operation requiring the D-runtime is appending the array, but it should **only** be done at compile-time. In that case, you want to prove to the compiler it is only called at compile time by encapsulating the function inside a template or defining it immediately where it is called. Delete the stand-alone function `parse` and instead call it like this: ``` // define it enum Data parsedData = function Data (string str) pure { Data data; while (str.length != 0) { // Skip spaces while (str[0] == ' ') str = str[1 .. $]; // Parse single digit integer data.digits ~= parseDigit(str[0]); // Consume digit str = str[1 .. $]; } return data; } ("5 4 2 6 9"); // and call it in the same place ``` Or if you want it to be independently defined still, you can define it inside a helper template but you'd have to return a basic type instead of Data, so I think calling it immediately is what you want to do here. There was going to be a ctfe-only thing you could put in the function so the compiler doesn't try to generate the runtime version, but this got killed due to internal D politics. A pity.
Re: generic function instance without call
On Wednesday, 27 April 2022 at 15:23:26 UTC, vit wrote: Hi, is it possible to get address of generic function instance for specified arguments without calling the function? Example: ```d auto foo(alias fn, Args...)(auto ref Args args){ ///return function/delegate type of `fn` for arguments `args` } void main(){ long x; auto fn = foo!((a, b) => true)(new int(42), x); static assert(is(typeof(fn) == bool function(int*, scope ref long)@safe pure nothrow @nogc )); } ``` yeah sure; declare an alias that (fully) specialize the generic func and take the address using the alias Identifier.
Re: Library for image editing and text insertion
On Wednesday, 27 April 2022 at 14:40:59 UTC, Alexander Zhirov wrote: Gorgeous! LDC has compressed my code at times! How small did it get? And with my libs if you import the other ones like `arsd.png` or `arsd.jpeg` directly instead of `arsd.image` that MIGHT help trim it down by removing support for other formats. I'm not sure though, none of them are especially big but it might add up.
Re: Library for image editing and text insertion
On Wednesday, 27 April 2022 at 16:07:53 UTC, Adam D Ruppe wrote: How small did it get? ```sh dmd: 3136896 byte ldc: 223952 byte ``` And with my libs if you import the other ones like `arsd.png` or `arsd.jpeg` directly instead of `arsd.image` that MIGHT help trim it down by removing support for other formats. I'm not sure though, none of them are especially big but it might add up. Yes, just now, on your advice, I did so. The size has become a little smaller! 😌
Re: Library for image editing and text insertion
On Wednesday, 27 April 2022 at 16:37:21 UTC, Alexander Zhirov wrote: On Wednesday, 27 April 2022 at 16:07:53 UTC, Adam D Ruppe wrote: How small did it get? ```sh dmd: 3136896 byte ldc: 223952 byte ``` but uses libraries ldc-shared.so ```sh linux-vdso.so.1 (0x7ffef5d2d000) libphobos2-ldc-shared.so.99 => /usr/lib64/libphobos2-ldc-shared.so.99 (0x7f667e9ee000) libdruntime-ldc-shared.so.99 => /usr/lib64/libdruntime-ldc-shared.so.99 (0x7f667e8ac000) libm.so.6 => /usr/lib64/libm.so.6 (0x7f667e7c5000) libgcc_s.so.1 => /usr/lib64/libgcc_s.so.1 (0x7f667e7a9000) libc.so.6 => /usr/lib64/libc.so.6 (0x7f667e589000) /usr/lib64/ld-linux-x86-64.so.2 (0x7f667eebe000) ``` And if without using dynamic libraries, it weighs `1219776` bytes ```sh linux-vdso.so.1 (0x7ffca9ad) librt.so.1 => /lib/librt.so.1 (0x7f6240fc4000) libdl.so.2 => /lib/libdl.so.2 (0x7f6240fbe000) libpthread.so.0 => /lib/libpthread.so.0 (0x7f6240f9d000) libm.so.6 => /lib/libm.so.6 (0x7f6240e58000) libgcc_s.so.1 => /usr/lib/libgcc_s.so.1 (0x7f6240e3e000) libc.so.6 => /lib/libc.so.6 (0x7f6240c74000) /lib64/ld-linux-x86-64.so.2 => /lib/ld-linux-x86-64.so.2 (0x7f6240ff7000) ```
Re: Library for image editing and text insertion
On Wednesday, 27 April 2022 at 00:03:25 UTC, Adam Ruppe wrote: ... I know about Adam Ruppe's work, I already used his terminal.d, but I think that unfortunately most people don't and I think it should be announced more in these parts. For me arsd is for D what stb is for C. I think in the first time running any D compiler, it should blink in the terminal in Yellow/Pink or whatever color you like, and show some info like: Are you starting a new project any need some libs? Do you know about arsd? If not then go to: https://github.com/adamdruppe/arsd. :) matheus.
Re: Library for image editing and text insertion
On Wednesday, 27 April 2022 at 17:07:54 UTC, matheus wrote: I think in the first time running any D compiler, it should blink in the terminal in Yellow/Pink or whatever color you like, and show some info like: Are you starting a new project any need some libs? Do you know about arsd? If not then go to: https://github.com/adamdruppe/arsd. :) Hahaha 😄 This is the truth! I totally agree!
Re: generic function instance without call
On Wednesday, 27 April 2022 at 16:03:32 UTC, user1234 wrote: On Wednesday, 27 April 2022 at 15:23:26 UTC, vit wrote: Hi, is it possible to get address of generic function instance for specified arguments without calling the function? Example: ```d auto foo(alias fn, Args...)(auto ref Args args){ ///return function/delegate type of `fn` for arguments `args` } void main(){ long x; auto fn = foo!((a, b) => true)(new int(42), x); static assert(is(typeof(fn) == bool function(int*, scope ref long)@safe pure nothrow @nogc )); } ``` yeah sure; declare an alias that (fully) specialize the generic func and take the address using the alias Identifier. This work for types but not for attributes like `scope`, `return` and `auto ref`.
Re: generic function instance without call
On Wednesday, 27 April 2022 at 17:22:14 UTC, vit wrote: This work for types but not for attributes like `scope`, `return` and `auto ref`. Oh sorry... auto ref... I totally forgot [this old bug] [this old bug]: https://issues.dlang.org/show_bug.cgi?id=8204
Re: Library for image editing and text insertion
On Wednesday, 27 April 2022 at 17:07:54 UTC, matheus wrote: I know about Adam Ruppe's work, I already used his terminal.d, but I think that unfortunately most people don't and I think it should be announced more in these parts. tbh sometimes i just don't feel like answering messages. even this one, i was like "i can do that easily, but do i want to support another user?" but meh i had a few mins to kill anyway For me arsd is for D what stb is for C. Note that a few of those modules are stb ports over to D. I wrote the png and bmp modules myself, for example, but the jpeg is a port from C (that port done by ketmar on irc) and the ttf one is stb_ttf ported to D then with a little wrapper struct pasted on top. One thing I'm kinda proud of though is my OperatingSystemFont class in simpledisplay which can load a font and then pass it into the ttf thing and/or the nanovega module for all kinds of custom effects. You don't necessarily have to package your own ttf files!
Re: Problem with GC - linking C++ & D (with gdc)
On Tuesday, 26 April 2022 at 13:36:19 UTC, Claude wrote: On Tuesday, 26 April 2022 at 12:49:21 UTC, Alain De Vos wrote: --- I also encountered problems while I was trying to use CTFE only functions (using betterC so I don't have to link phobos/D-runtime). However, if those functions use the GC for instance (like appending a dynamic-array), it will require me to link D-runtime, whereas I only use them at compile-time. So I'm a bit confused... I'll try and get more information and reduce a code sample. dont't use `new` if you mean using betterC, `new` is based on GC. with betterC, you should using `malloc/free` reference info: https://dlang.org/spec/cpp_interface.html#memory-allocation
Re: Language server
I have not tested yet but i found two interesting links, https://github.com/Pure-D/serve-d/blob/master/editor-vim.md https://github.com/neoclide/coc.nvim