Re: How to link a msvcr120.dll in an inverse recursive way after a Windows .exe binary deployment
On Tuesday, 6 September 2022 at 04:36:55 UTC, ShadoLight wrote: True. In that case just distribute the DLL (taken from the DMD bin folder) alongside the HelloWorld EXE so that both reside in the same folder on the target computer. The proper way to do this is to ship the correct version of the Visual C++ redistributable installer and run it as part of the application install process: https://docs.microsoft.com/en-us/cpp/windows/latest-supported-vc-redist?view=msvc-170
Re: How to link a msvcr120.dll in an inverse recursive way after a Windows .exe binary deployment
On Monday, 5 September 2022 at 07:02:53 UTC, BoQsc wrote: The problem is, D Language Compiler is not included along the Windows Operating System. No compiler is included natively with the Windows OS. Not even Microsoft's. Neither msvcr120.dll is included along the Windows Operating System. You have to download it. No other way. Or... you download the DMD installer which conveniently include it for you. How can you download it, if your .exe binary that has the functionality to download it, cannot even be started due to msvcr120.dll not existing on the operating system. I don't understand this. You need DMD to build your EXE. I suppose you have this since your question is specifically about DMD. If that is the case you have the DLL you need. Copy the DLL to C:\Windows\System32\ It required administrator privilegies and this is only a HelloWorld example of the D language deployed on computers, where the D language is yet to be installed. True. In that case just distribute the DLL (taken from the DMD bin folder) alongside the HelloWorld EXE so that both reside in the same folder on the target computer. If you don't have administrative priveleges you cannot modify the PATH on the target computer either, so this is the only way. That is anyway quite standard under Windows - if you search for msvcr*.dll on any Windows machine you'll find lots of copies co-located with the EXEs that use them (using the version that came with the specific version of Visual Studio they were using to build the EXE - for example msvcr90.dll). These DLLs are simply the Visual Studio C/C++ Runtime distributed with Visual Studio.
Re: Forked GC explained
On 9/5/22 7:12 AM, frame wrote: And what if the programmer has no actual reference but wrongly forced a `free()` through a pointer cast? https://dlang.org/spec/garbage.html#pointers_and_gc * Do not store pointers into non-pointer variables using casts and other tricks. ```d void* p; ... int x = cast(int)p; // error: undefined behavior ``` The garbage collector does not scan non-pointer fields for GC pointers. Note that this does not require the forked GC to cause this problem. -Steve
Re: synchronized/shared associative array .require error
On 9/4/22 11:24 PM, cc wrote: On Saturday, 3 September 2022 at 14:37:16 UTC, Steven Schveighoffer wrote: On 9/2/22 3:15 PM, cc wrote: Tried casting away shared as a workaround but I assume that will cause some kind of TLS catastrophe. I think it will be fine, but you may have an issue. You are returning a non-shared `VAL`, but your class is `shared`, which means `table`, and all the `VAL` and `KEY` inside must also be `shared`. If you cast away `shared` you have to put it back upon return. TLS should not be involved here at all, so there is no problem there. Alright, so this is safe then? ```d alias VAL[KEY] T; auto require(KEY key) { auto unsharedT = cast(T) table; auto r = unsharedT.require(key); table = cast(shared) unsharedT; return cast(shared) r; } ``` I think that is fine-ish. You still don't have a shared `KEY` there. But it really depends on what KEY is. Most likely it's fine (e.g. if `KEY` is string). If you don't ever really fetch anything out of the key, and just use it to map to your values, I think it should be fine. Was a bit surprised to see mutating `unsharedT` left `table` unchanged and needed reassigning. Yes, because before an AA contains an element, it is a `null` AA. When you add the first element, it's allocated. When you make a copy of a `null` AA, it doesn't affect the original. You can fix this by reinterpret casting the AA instead of copying it: ```d auto r = .require(*(cast(T*)), key); // I think this might also work: auto r = (cast()table).require(key); ``` -Steve
Re: Comparing slices with std.variant.Algebraic
On Monday, 5 September 2022 at 08:58:21 UTC, anonymouse wrote: On a related note, std.variant.Algebraic has been deprecated and the suggested replacement is std.sumtype.SumType. What is the proper way to make this conversion? Attempting to do a drop-in replacement results in the following errors: ``` axis.d(400): Error: incompatible types for array comparison: `SumType!(bool, int, long, float, double, string, DateTime)[]` and `double[]` axis.d(86): Error: incompatible types for `(this.data[i]) + (rhs.data[i])`: both operands are of type `SumType!(bool, int, long, float, double, string, DateTime)` axis.d(414): Error: template instance ``` `SumType` does not attempt to forward operators to the contained value like `Algebraic` does, so you will have to use [`tryMatch`][1] to access the value(s) in cases like these. ```d // Compare a DataType[] to a double[] import std.algorithm.comparison: equal; /+ Will throw an exception if lhs contains a value that can't be compared to a double. +/ alias cmp = (DataType lhs, double rhs) => lhs.tryMatch!(value => value == rhs); DataType[] a; double[] b; bool result = a.equal!cmp(b); ``` ```d // Add two DataType values /+ addValues will take two DataTypes as arguments and match on both simultaneously. If the two DataTypes do not contain values that can be added together, an exception will be thrown. See: - https://dlang.org/phobos/std_sumtype.html#multiple-dispatch - https://dlang.org/phobos/std_sumtype.html#introspection-based-matching +/ alias addValues = tryMatch!((lhs, rhs) => lhs + rhs); DataType a; DataType b; DataType result = addValue(a, b); ``` [1]: https://phobos.dpldocs.info/std.sumtype.tryMatch.html
Re: BetterC stack traces?
On Monday, 5 September 2022 at 12:07:35 UTC, Paul Backus wrote: On Monday, 5 September 2022 at 10:47:38 UTC, IchorDev wrote: Ah, I'm actually trying to create my own implementation of this, so the goal would be to not rely on a dependency. I can't exactly make head nor tail of the library's source other than that it seems to have a unique implementation on each processor/OS type. I'm sure there must be something hidden in `core.internal.` for this. I'll look at the implementation of `rt.trace` and see if I can find anything. I think this is what you are looking for: https://github.com/dlang/dmd/blob/master/druntime/src/rt/deh.d Digging in a little deeper, it looks like the druntime implementation ultimately depends on the [C++ exception handling ABI][1], via its platform-independent library interface. Bindings are defined in [`core.internal.backtrace.unwind`][2]. There is also what looks like a from-scratch implementation of table-based exception handling in [`rt.deh_win64_posix`][3], but according to a comment it is no longer used. Might be educational to read, though. [1]: https://itanium-cxx-abi.github.io/cxx-abi/abi-eh.html [2]: https://github.com/dlang/dmd/blob/master/druntime/src/core/internal/backtrace/unwind.d [3]: https://github.com/dlang/dmd/blob/master/druntime/src/rt/deh_win64_posix.d
Re: BetterC stack traces?
On Monday, 5 September 2022 at 10:47:38 UTC, IchorDev wrote: Ah, I'm actually trying to create my own implementation of this, so the goal would be to not rely on a dependency. I can't exactly make head nor tail of the library's source other than that it seems to have a unique implementation on each processor/OS type. I'm sure there must be something hidden in `core.internal.` for this. I'll look at the implementation of `rt.trace` and see if I can find anything. I think this is what you are looking for: https://github.com/dlang/dmd/blob/master/druntime/src/rt/deh.d
Re: Forked GC explained
On Saturday, 3 September 2022 at 14:31:31 UTC, Steven Schveighoffer wrote: On 9/3/22 9:35 AM, frame wrote: What happens if a manually `GC.free()` is called while the forked process marks the memory as free too but the GC immediately uses the memory again and then gets the notification to free it from the forked child? Can this happen? No, because if you can free it, you should have had a reference to it when you forked, which should mean it's not garbage. And what if the programmer has no actual reference but wrongly forced a `free()` through a pointer cast? ``` | OP | Memory M --- Parent: | - | Unreferenced, marked in use --- Parent: | fork --- Parent: | - | Unreferenced, marked in use Child: | | Unreferenced, marked in use --- Parent: | - | Unreferenced, marked in use Child: | | Unreferenced, found M --- Parent: | free| Unreferenced, marked not in use <- error forced by programmer Child: | | Unreferenced, found M --- Parent: | new | Referenced, re-used because it was marked free Child: | | Unreferenced, found M --- Parent: | - | Referenced, used Child: | | Done scanning. Please collect: M --- Parent: | collect | M Child: | | exit --- ``` @wjoe is the GC aware of this to exclude M from the child result set because it has changed while the child was running? There's a talk on it from the 2013 dconf by the inventor: https://dconf.org/2013/talks/lucarella.html -Steve Thanks for the link. The slides mentioning shared memory.
Re: Comparing slices with std.variant.Algebraic
On Monday, 5 September 2022 at 10:30:32 UTC, Ali Çehreli wrote: On 9/5/22 01:58, anonymouse wrote: > array [1.7, 3.7, 5.7, 7.7, 9.7] in both cases, which is what is being > asserted by those two lines. None of those values can be represented precisely in a floating point type. Without looking at the code, I wonder whether the tests will pass if you can manage to use the following values instead, which can be represented precisely: [1.5, 3.5, 5.5, 7.5, 9.5] Ali It will not. --anonymouse
Re: BetterC stack traces?
On Sunday, 4 September 2022 at 18:49:37 UTC, Paul Backus wrote: You can use `libunwind` for this: https://www.nongnu.org/libunwind/ It's a C library, but it should work for D too. Ah, I'm actually trying to create my own implementation of this, so the goal would be to not rely on a dependency. I can't exactly make head nor tail of the library's source other than that it seems to have a unique implementation on each processor/OS type. I'm sure there must be something hidden in `core.internal.` for this. I'll look at the implementation of `rt.trace` and see if I can find anything.
Re: Comparing slices with std.variant.Algebraic
On 9/5/22 01:58, anonymouse wrote: > array [1.7, 3.7, 5.7, 7.7, 9.7] in both cases, which is what is being > asserted by those two lines. None of those values can be represented precisely in a floating point type. Without looking at the code, I wonder whether the tests will pass if you can manage to use the following values instead, which can be represented precisely: [1.5, 3.5, 5.5, 7.5, 9.5] Ali
Comparing slices with std.variant.Algebraic
Observe the [implementation](https://github.com/Kriyszig/magpie/blob/master/source/magpie/axis.d) of ```d stuct Axis(U...){} ``` More specifically, observe its usage in the unittests for [Binary Ops on Variant Axis](https://github.com/Kriyszig/magpie/blob/master/source/magpie/axis.d#L410-L437) and [Binary Ops on Variant + Other DataType](https://github.com/Kriyszig/magpie/blob/master/source/magpie/axis.d#L440-L467) Note that both tests fail due to asserts on lines 422 and 452. Note also that commenting out these two lines results in successful compilation of all other tests. Inspecting c.data, one will find that it holds the array [1.7, 3.7, 5.7, 7.7, 9.7] in both cases, which is what is being asserted by those two lines. So the question is, what is the proper way to compare a slice (array literal?) and an Algebraic in current D? I assume that this code worked back in 2019, however, I am unable to detect when it stopped working because no DMD compiler prior to v2.100.0 works properly on my system. On a related note, std.variant.Algebraic has been deprecated and the suggested replacement is std.sumtype.SumType. What is the proper way to make this conversion? Attempting to do a drop-in replacement results in the following errors: ``` axis.d(400): Error: incompatible types for array comparison: `SumType!(bool, int, long, float, double, string, DateTime)[]` and `double[]` axis.d(86): Error: incompatible types for `(this.data[i]) + (rhs.data[i])`: both operands are of type `SumType!(bool, int, long, float, double, string, DateTime)` axis.d(414): Error: template instance `axis.Axis!void.Axis.opBinary!("+", void)` error instantiating axis.d(86): Error: incompatible types for `(this.data[i]) + (rhs.data[i])`: `SumType!(bool, int, long, float, double, string, DateTime)` and `int` axis.d(445): Error: template instance `axis.Axis!void.Axis.opBinary!("+", int[])` error instantiating axis.d(43): Error: none of the overloads of template `object.get` are callable using argument types `!(int)(const(SumType!(bool, int, long, float, double, string, DateTime)))` /Users/anonymouse/dlang/dmd-2.100.0/osx/bin/../../src/druntime/import/object.d(3409): Candidates are: `get(K, V)(inout(V[K]) aa, K key, lazy inout(V) defaultValue)` /Users/anonymouse/dlang/dmd-2.100.0/osx/bin/../../src/druntime/import/object.d(3416): `get(K, V)(inout(V[K])* aa, K key, lazy inout(V) defaultValue)` axis.d(47): Error: none of the overloads of template `object.get` are callable using argument types `!(double)(const(SumType!(bool, int, long, float, double, string, DateTime)))` /Users/anonymouse/dlang/dmd-2.100.0/osx/bin/../../src/druntime/import/object.d(3409): Candidates are: `get(K, V)(inout(V[K]) aa, K key, lazy inout(V) defaultValue)` /Users/anonymouse/dlang/dmd-2.100.0/osx/bin/../../src/druntime/import/object.d(3416): `get(K, V)(inout(V[K])* aa, K key, lazy inout(V) defaultValue)` axis.d(474): Error: template instance `axis.Axis!void.Axis.convertTo!(int[])` error instantiating axis.d(43): Error: none of the overloads of template `object.get` are callable using argument types `!(double)(const(SumType!(bool, int, long, float, double, string, DateTime)))` /Users/anonymouse/dlang/dmd-2.100.0/osx/bin/../../src/druntime/import/object.d(3409): Candidates are: `get(K, V)(inout(V[K]) aa, K key, lazy inout(V) defaultValue)` /Users/anonymouse/dlang/dmd-2.100.0/osx/bin/../../src/druntime/import/object.d(3416): `get(K, V)(inout(V[K])* aa, K key, lazy inout(V) defaultValue)` axis.d(47): Error: none of the overloads of template `object.get` are callable using argument types `!(double)(const(SumType!(bool, int, long, float, double, string, DateTime)))` /Users/anonymouse/dlang/dmd-2.100.0/osx/bin/../../src/druntime/import/object.d(3409): Candidates are: `get(K, V)(inout(V[K]) aa, K key, lazy inout(V) defaultValue)` /Users/anonymouse/dlang/dmd-2.100.0/osx/bin/../../src/druntime/import/object.d(3416): `get(K, V)(inout(V[K])* aa, K key, lazy inout(V) defaultValue)` axis.d(478): Error: template instance `axis.Axis!void.Axis.convertTo!(double[])` error instantiating ``` Thanks, --anonymouse
Re: Tracing out error that causes compiler crash
On Sunday, 4 September 2022 at 20:48:52 UTC, solidstate1991 wrote: What do I pass as the tester? You can use a script as described here: https://github.com/CyberShadow/DustMite/wiki/Detecting-a-segfault-in-dmd-itself
Re: How to link a msvcr120.dll in an inverse recursive way after a Windows .exe binary deployment
On Sunday, 4 September 2022 at 22:05:24 UTC, ShadoLight wrote: On Sunday, 4 September 2022 at 15:16:47 UTC, BoQsc wrote: **Folder structure** .\msvcr120.dll .\folder1\HelloWorld.exe .\folder2\HelloWorld.exe You don't need to do this. msvcr120.dll is already shipped with the DMD compiler at [DMD-install-folder]\windows\bin64\msvcr120.dll. (It is also in [DMD-install-folder]\windows\bin). You can access it directly from there. The problem is, D Language Compiler is not included along the Windows Operating System. Neither msvcr120.dll is included along the Windows Operating System. You have to download it. No other way. How can you download it, if your .exe binary that has the functionality to download it, cannot even be started due to msvcr120.dll not existing on the operating system. You can try to use pre-existing Command Line Utilities like bitsadmin (Windows 7), curl (Windows 10), but really how can you interact with them from within D Language Binary if it can't even launch. You can try to write a batch script for all that. I really do not want to write batch scripts for the rest of my life, that's why I'm here in the D Language Forum. Copy the DLL to C:\Windows\System32\ It required administrator privilegies and this is only a HelloWorld example of the D language deployed on computers, where the D language is yet to be installed.