Re: Log rotation in std.logger.filelogger
On Tuesday, 23 May 2023 at 13:13:18 UTC, Andrew wrote: On Tuesday, 23 May 2023 at 11:21:07 UTC, apz28 wrote: On Wednesday, 17 May 2023 at 21:11:41 UTC, Vitalii wrote: Hello! Please tell me how to enable log rotation in std.logger.filelogger? Without log rotation, it seems that the std.logger.filelogger is useless, because it will quickly take up all the free space on the hard drive. Or can try my log package https://github.com/apz28/dlang/tree/main https://github.com/apz28/dlang/tree/main/source/pham/external/std/log log_logger.d RollingFileLogger Happy coding! Please don't take this as an insult, as I've also written my own logging library lol. But I have a feeling that our efforts would be better spent in improving the standard library's implementation rather than making our own logger. Hopefully this will become easier in the future as issues are migrated to github and more effort is put into organization. D is just a learning project (hobby one) and I do not have time to go through the process to add codes to standard library. However, it is www.boost.org/LICENSE_1_0.txt license so feel free to get it and add it to standard one Cheers
Re: Log rotation in std.logger.filelogger
On Wednesday, 17 May 2023 at 21:11:41 UTC, Vitalii wrote: Hello! Please tell me how to enable log rotation in std.logger.filelogger? Without log rotation, it seems that the std.logger.filelogger is useless, because it will quickly take up all the free space on the hard drive. Or can try my log package https://github.com/apz28/dlang/tree/main https://github.com/apz28/dlang/tree/main/source/pham/external/std/log log_logger.d RollingFileLogger Happy coding!
Re: Implicit type conversion depending on assignment
On Thursday, 23 March 2023 at 14:36:11 UTC, Alexander Zhirov wrote: On Thursday, 23 March 2023 at 14:19:31 UTC, user1234 wrote: omg, let's rewrite this... Or abuse opBinary struct MyVal { string value; T opBinary(string op, T)(T rhs) if (op == "+") { import std.conv : convto = to; static if (is(T==int)) return convto!T(value) + rhs; else static if (is(T==float)) return convto!T(value) + rhs; else static assert(0); } alias opBinary this; } void main() { auto a = MyVal("100"); auto b = MyVal("11.2"); int MyInt = a + 0; float myFloat = b + 0.0f; }
return attribute with latest DMD - dmd-nightly -unittest -dip1000
why foo2 is not inferred as scope which is shorter scope then foo1? import std.stdio; @safe: class Obj {@safe: override string toString() { return "obj"; } } struct Foo1 {@safe: this(Obj obj) { this._obj = obj; } ~this() { _obj = null; } // do something with obj // _obj must not be out live with Foo1, so need return attribute @property Obj obj() return { return _obj; } private Obj _obj; } struct Foo2 {@safe: this(Obj obj) { this._obj = obj; } ~this() { _obj = null; } // do something with obj void call() { writeln(_obj.toString()); } // _obj must not be out live with Foo1, so need return attribute @property Obj obj() return { return _obj; } private Obj _obj; } void call1() { auto obj = new Obj(); auto foo1 = Foo1(obj); call2(foo1); } // foo2 borrows foo1.obj and do something with it void call2(ref Foo1 foo1) { auto foo2 = Foo2(foo1.obj); call3(foo2); } void call3(ref Foo2 foo2) { foo2.call(); } void main() { call1(); } Getting below error message onlineapp.d(29): Error: reference to local variable `foo1` assigned to non-scope parameter `obj` calling onlineapp.Foo2.this Remove "return" from property obj fix the error message
Re: [Help Needed] - Debugging compilation time
On Friday, 21 October 2022 at 16:32:17 UTC, Hipreme wrote: Hey guys, I have been complaining a lot of time right now from D compilation speed at least for my project. I have: - Underused CTFE - Underused Templates - Avoided importing standard libraries - Created a multi module projects for better code reuse The slow is from executing CTFE (template constraints, enum expression, static if ...). The culprit is this function: Expression.ctfeInterpret() in this module dmd.expression.d Even for compiling DMD, that function will take 1/3 of total times Try to reduce CTFE usage than it will be fast again. D should analyze to make executing CTFE faster Cheers
Re: Storing a lambda alongside type-erased data
On Thursday, 8 September 2022 at 15:02:13 UTC, Paul Backus wrote: On Thursday, 8 September 2022 at 03:18:08 UTC, Ali Çehreli wrote: I looked at how std.variant.VariantN prints the correct type and failed to understand the magic there. :( Then I came up with storing a lambda that is created when the exact type is known. The following simple variant can carry arbitrary set of data because the data is provided as sequence template parameters (aka variadic). This is actually pretty much exactly what VariantN does, except instead of storing a pointer to a lambda, it stores a pointer to an instance of a template function. The member variable `fptr` [1] is the equivalent of your `dataToStr`. It stores a pointer to an instance of the `handler` template [2]. Whenever a new value is assigned to the VariantN, `fptr` is updated to point to the template instance corresponding to the new value's type [3]. [1] https://github.com/dlang/phobos/blob/v2.100.1/std/variant.d#L217-L218 [2] https://github.com/dlang/phobos/blob/v2.100.1/std/variant.d#L260-L645 [3] https://github.com/dlang/phobos/blob/v2.100.1/std/variant.d#L731 My implement is similar but a pointer to template struct with various functions. The advantage is that you can add various attributes to those functions https://github.com/apz28/dlang/blob/main/source/pham/utl/utl_variant.d#L904 https://github.com/apz28/dlang/blob/main/source/pham/utl/utl_variant.d#L1394
Re: How to call a function from a dll created with d ?
Below is working on Windows --file dimedll.d: module dimedll; import core.sys.windows.windows; import core.sys.windows.dll; import std.stdio; mixin SimpleDllMain; export void testFunc() { writeln("This is from dll"); } --file dime.d: import core.sys.windows.windows; import std.stdio; import dimedll; pragma(lib, "dimedll.lib"); void main() { writeln("Lets call testFunc()"); testFunc(); } --file dimedll.di: module dimedll; extern void testFunc(); --file dimedll.def LIBRARY "dimedll.dll" EXETYPE NT SUBSYSTEM WINDOWS CODE SHARED EXECUTE DATA WRITE -- command lines in sequence: -- there should be files as first dmd: dimedll.exp, dimedll.lib, dimedll.obj dmd -of=dimedll.dll dimedll.d dimedll.def dmd dime.d dimedll.di
Re: Protected Members in Class
On Friday, 24 December 2021 at 08:35:38 UTC, Salih Dincer wrote: What do I need to do to see that the protected is active, need a separate module? ```d // Source: https://tour.dlang.org/tour/en/basics/classes class Any { // protected is just seen by inheriting // classes protected string type; this(string type) { this.type = type; } // public is implicit by the way string getType() { return type; } } import std.stdio, std.string; import std.uni : isWhite; void main() { Any any = new Any("bu bir deneme"); any.getType.writeln("--> Split:"); any.type.split!isWhite.writeln; any.type = "deneme"; any.type.writeln; }/* Console Out: bu bir deneme--> Split: ["bu", "bir", "deneme"] deneme */ ``` https://dlang.org/spec/attribute.html#visibility_attributes #5
Re: Why code failed to compile for foo2?
On Tuesday, 14 December 2021 at 05:04:46 UTC, Tejas wrote: Is there anything wrong with the answer I posted? Can you please tell me if there's anything dissatisfactory about it? I feel like it does everything the OP wants. Also, am I wrong in using `Unconst` over `Unqual`? Isn't `Unqual` overkill if you just want to cast away `const`? 1. A template function should behave as to replace 4 overload functions There is special logic for parameter type (2 vs 4...) 2. Your implementation does not remove 'const' as below import std.traits : Unconst; import std.stdio : writeln; void foo2(T)(T x) if(is(Unconst!(T) : ulong)) {//You don't need Unqual for this pragma(msg, T.stringof); writeln(x); } void main() { import std.math; const int s1 = -3; int s2 = -2; foo2(abs(s1)); foo2(abs(s2)); enum byte b1 = 0; const byte b2; byte b3; foo2(b1); foo2(b2); foo2(b3); } --Output const(int) int byte const(byte) 3 2 0 0 0
Re: Why code failed to compile for foo2?
On Saturday, 11 December 2021 at 23:44:59 UTC, Adam Ruppe wrote: On Saturday, 11 December 2021 at 23:17:17 UTC, Stanislav Blinov wrote: ? No. If it was unsatisfied constraint, the error would've shown that. And if you try to instantiate it, you'll see it is an unsatisfied constraint anyway. There's two layers of failure here. Using Unqual there is pretty iffy, i wouldn't bother with it at all, but if you do anything, instead qualify it const. But either way, then the constraint still fails since int isn't unsigned. I'd really recommend simplifying this a lot. 1. This is why there is a diverse logic for language rule vs template rule. The overload functions enjoy all benefits of implicit conversion rule but none for template 2. This is why template implementation create more function bloats more than it needs to be as compilable example below import std.traits : isUnsigned, Unqual; void foo2(T, alias UT1 = Unqual!T)(T x) // You can create alias UT1 but not able to use it in function parameter if(isUnsigned!T) { alias UT2 = Unqual!T; pragma(msg, T.stringof); pragma(msg, UT1.stringof); pragma(msg, UT2.stringof); } void main() { import std.math; int s = 1; foo2(cast(uint)abs(s)); foo2(cast(const(uint))abs(s)); } Output as below uint uint uint const(uint) uint uint
Re: Why code failed to compile for foo2?
On Sunday, 12 December 2021 at 00:02:25 UTC, Stanislav Blinov wrote: @apz28, I can't figure out the intent here. To convert result of abs to an unsigned? The function logic works only for unsigned type and the parameter value can be altered in body hence Unqual. If not Unqual, must declare a local var and make a copy. Just asking if this can be done to avoid a cast by caller
Why code failed to compile for foo2?
void foo1(ubyte x) {} void foo1(ushort x) {} void foo1(uint x) {} void foo1(ulong x) {} import std.traits : isUnsigned, Unqual; void foo2(T)(Unqual!T x) if(isUnsigned!T) {} void main() { import std.math; int s = 1; foo1(abs(s)); foo2(abs(s)); //failed? } /* onlineapp.d(15): Error: template `onlineapp.foo2` cannot deduce function from argument types `!()(int)` onlineapp.d(7):Candidate is: `foo2(T)(Unqual!T x)` */
Re: Output Range Problem? How to make it work?
On Monday, 11 October 2021 at 00:37:43 UTC, Paul Backus wrote: On Monday, 11 October 2021 at 00:19:44 UTC, apz28 wrote: /* Getting this error onlineapp.d(34): Error: none of the overloads of `toString` are callable using argument types `(Buffer)`, candidates are: onlineapp.d(19):`onlineapp.Foo.toString()` onlineapp.d(26):`onlineapp.Foo.toString(const(char)[] fmt)` onlineapp.d(22):`toString(Writer, Char)(return ref Writer sink)` */ The signature of your `toString` method should match one of the examples in [the documentation][1]: ```d void toString(Writer, Char)(ref Writer w, const ref FormatSpec!Char fmt) void toString(Writer)(ref Writer w) string toString(); ``` Here is an example that works: ```d import std.range: put; import std.array: appender; import std.format: formattedWrite; struct Foo { void toString(Writer)(ref Writer writer) { put(writer, "Foo"); } } void main() { auto buffer = appender!string; Foo foo; formattedWrite(buffer, "%s", foo); assert(buffer[] == "Foo"); } ``` Link: https://run.dlang.io/is/dZLRuo [1]: https://phobos.dpldocs.info/std.format.write.html On Monday, 11 October 2021 at 00:37:43 UTC, Paul Backus wrote: The subject is why the call is not allowed (format is not mention in question). Below sample is a bit more clear import std.range.primitives : isOutputRange; import std.traits: isSomeChar; @safe: struct Buffer(Char) { @safe: void put(Char c) {} void put(scope const(Char)[] s) {} } struct Foo { @safe: ref Writer outWork(Writer)(return ref Writer sink) if (isOutputRange!(Writer, char)) {return sink;} // Remove " && isSomeChar!Char" does not make any difference ref Writer outFail(Writer, Char)(return ref Writer sink) if (isOutputRange!(Writer, Char) && isSomeChar!Char) {return sink;} } void main() { pragma(msg, isOutputRange!(Buffer!char, char)); // Print true Buffer!char buffer; Foo foo; foo.outWork(buffer); // OK foo.outFail!(Buffer!char, char)(buffer); // OK with explicit foo.outFail(buffer); // NOT OK } /* Blow is output from online compiler true onlineapp.d(40): Error: template `onlineapp.Foo.outFail` cannot deduce function from argument types `!()(Buffer!char)`, candidates are: onlineapp.d(25):`outFail(Writer, Char)(return ref Writer sink)` */
Output Range Problem? How to make it work?
import std.range.primitives: isOutputRange; @safe: struct Buffer { @safe: void put(char c) {} void put(scope const(char)[] s) {} } struct Foo { @safe: string toString() {return null;} ref Writer toString(Writer, Char)(return ref Writer sink) if (isOutputRange!(Writer, Char) && isSomeChar!Char) {return sink;} string toString(const(char)[] fmt) {return null;} } void main() { Buffer buffer; Foo foo; foo.toString(buffer); } /* Getting this error onlineapp.d(34): Error: none of the overloads of `toString` are callable using argument types `(Buffer)`, candidates are: onlineapp.d(19):`onlineapp.Foo.toString()` onlineapp.d(26):`onlineapp.Foo.toString(const(char)[] fmt)` onlineapp.d(22):`toString(Writer, Char)(return ref Writer sink)` */
What is the value for D to allow assign bool to char/dchar? For me, it must be an error.
void main() { dchar d; d = false; d = true; char c; c = false; c = true; }
Re: How to Fix Weird Build Failure with "-release" but OK with "-debug"?
On Friday, 23 July 2021 at 18:44:47 UTC, Steven Schveighoffer wrote: On 7/22/21 7:43 PM, apz28 wrote: In any case, it's possible that fbConnection being null does not mean a null dereference, but I'd have to see the class itself. I'm surprised if you don't get a null dereference in non-release mode, unless this code is never actually called. -Steve The -debug build with passing unit-tests so no problem there. The -release build is having problem. After make change to accommodate it, it takes forever to build. I started it yesterday 11AM and it is still compiling now (more than a day already.) It takes a full 100% core and peek memory usage is 2.2GB. The hard-drive is SSD
Re: How to Fix Weird Build Failure with "-release" but OK with "-debug"?
On Thursday, 22 July 2021 at 18:56:43 UTC, Steven Schveighoffer wrote: On 7/22/21 2:38 PM, apz28 wrote: On Wednesday, 21 July 2021 at 20:39:54 UTC, Dukc wrote: On Wednesday, 21 July 2021 at 14:15:51 UTC, Steven Schveighoffer wrote: 2. It's hard for me to see where the null dereference would be in that function (the `bool` implementation is pretty simple). DMD complains about dereferences in three different lines. I suspect it's `this` reference that is `null`. Look like DMD has some bug. If I changed this line https://github.com/apz28/dlang/blob/02989b94bfe306d723f2780e010c61f71f873cbe/source/pham/db/db_fbdatabase.d#L148 from: auto reader = FbXdrReader(null, response.data); to: auto reader = FbXdrReader(fbConnection, response.data); then the error go away. FbXdrReader constructor allows to accept null for that parameter. Is it "safe" means not allow to pass null? I don't know what an FbConnection is, but it looks like you call something on it. Your code is immense, and github search really *really* sucks. So I can't get better information. But if it's a class, and that is a normal member, it is indeed dereferencing a null pointer. -Steve FbConnection is a class, FbXdrReader is a struct and for this call, response.data is not null & its' length will be greater than zero and FbConnection is not being used. So why DMD try to evaluate at compiled time hence error 1. Should not evaluate at compile time for this function call/construct 2. The error message is missing proper line # or nothing related to the module displayed in error message https://github.com/apz28/dlang/blob/main/source/pham/db/db_fbbuffer.d#L527
Re: How to Fix Weird Build Failure with "-release" but OK with "-debug"?
On Wednesday, 21 July 2021 at 20:39:54 UTC, Dukc wrote: On Wednesday, 21 July 2021 at 14:15:51 UTC, Steven Schveighoffer wrote: 2. It's hard for me to see where the null dereference would be in that function (the `bool` implementation is pretty simple). -Steve DMD complains about dereferences in three different lines. I suspect it's `this` reference that is `null`. Look like DMD has some bug. If I changed this line https://github.com/apz28/dlang/blob/02989b94bfe306d723f2780e010c61f71f873cbe/source/pham/db/db_fbdatabase.d#L148 from: auto reader = FbXdrReader(null, response.data); to: auto reader = FbXdrReader(fbConnection, response.data); then the error go away. FbXdrReader constructor allows to accept null for that parameter. Is it "safe" means not allow to pass null?
Re: How to Fix Weird Build Failure with "-release" but OK with "-debug"?
On Wednesday, 21 July 2021 at 11:52:39 UTC, apz28 wrote: On Wednesday, 21 July 2021 at 04:52:44 UTC, Mathias LANG wrote: It seems the compiler is doing extra analysis and seeing that a null pointer is being dereferenced. Can you provide the code for "pham\db\db_skdatabase.d" at L138 through 140 ? ```d package(pham.db): // Line# 133 final DbReadBuffer acquireSocketReadBuffer(size_t capacity = DbDefaultSize.socketReadBufferLength) nothrow @safe { version (TraceFunction) dgFunctionTrace(); if (_socketReadBuffer is null) _socketReadBuffer = createSocketReadBuffer(capacity); return _socketReadBuffer; } ``` The entire codes is available from github https://github.com/apz28/dlang/blob/main/source/pham/db/db_skdatabase.d#L138
Re: How to Fix Weird Build Failure with "-release" but OK with "-debug"?
On Wednesday, 21 July 2021 at 04:52:44 UTC, Mathias LANG wrote: It seems the compiler is doing extra analysis and seeing that a null pointer is being dereferenced. Can you provide the code for "pham\db\db_skdatabase.d" at L138 through 140 ? ```d package(pham.db): // Line# 133 final DbReadBuffer acquireSocketReadBuffer(size_t capacity = DbDefaultSize.socketReadBufferLength) nothrow @safe { version (TraceFunction) dgFunctionTrace(); if (_socketReadBuffer is null) _socketReadBuffer = createSocketReadBuffer(capacity); return _socketReadBuffer; } ```
How to Fix Weird Build Failure with "-release" but OK with "-debug"?
VisualD project - Any hint to work around DMD version: DMD32 D Compiler v2.096.0-rc.1-dirty Copyright (C) 1999-2021 by The D Language Foundation, All Rights Reserved written by Walter Bright Failed Build Command line: dmd -release -m32mscoff -O -inline -dip25 -dip1000 -preview=fixAliasThis -X -Xf"Win32\Release\db_library.json" -c -of"Win32\Release\db_library.obj" @Win32\Release\db_library.build.rsp with below error message: ..\..\pham\db\db_skdatabase.d(140): Error: null dereference in function _D4pham2db10fbdatabase7FbArray__T13readArrayImplTbZQsMFNfCQCeQCc8database12DbNameColumnZAb ..\..\pham\db\db_skdatabase.d(139): Error: null dereference in function _D4pham2db10fbdatabase7FbArray__T13readArrayImplTbZQsMFNfCQCeQCc8database12DbNameColumnZAb Error: null dereference in function _D4pham2db10fbdatabase7FbArray__T13readArrayImplTbZQsMFNfCQCeQCc8database12DbNameColumnZAb ..\..\pham\db\db_skdatabase.d(138): Error: null dereference in function _D4pham2db10fbdatabase7FbArray__T13readArrayImplTbZQsMFNfCQCeQCc8database12DbNameColumnZAb
Re: How to execute a random postgresql-query.
On Tuesday, 29 June 2021 at 20:35:07 UTC, Alain De Vos wrote: Some implementations take all queries full in memory. But what when i need one record. And the select result could be huge. And we don't want swapping for this? You can try my db package https://github.com/apz28/dlang/tree/main/source/pham/db For Postresql, it is in "pham.db.pgdatabase" module. The document is a bit lacking but if you open that module and search for "executeReader();" for sample usage. The implementation follow .NET interface and currently it is working for both Firebird and Postgresql database engines. You need to download entire D package: https://github.com/apz28/dlang Happy Codings
Re: Why filling AA in shared library freezes execution?
On Friday, 29 January 2021 at 12:45:02 UTC, Imperatorn wrote: Anyone knows what it would take to fix it? This may help to narrow down the problem. Disable garbage collect Configuring the Garbage Collector https://dlang.org/spec/garbage.html https://stackoverflow.com/questions/472133/turning-off-the-d-garbage-collector Or change it so that there is only one thread Parallel marking https://dlang.org/spec/garbage.html
How to get call stack for InvalidMemoryOperationError while doing unittest?
core.exception.InvalidMemoryOperationError@src\core\exception.d(647): Invalid memory operation reference D runtime unittest executor codes try { fp(); ++results.passed; } catch ( Throwable e ) { import core.stdc.stdio; printf("%.*s(%llu): [unittest] %.*s\n", cast(int) e.file.length, e.file.ptr, cast(ulong) e.line, cast(int) e.message.length, e.message.ptr); if ( typeid(e) == typeid(AssertError) ) { // Crude heuristic to figure whether the assertion originates in // the unittested module. TODO: improve. auto moduleName = m.name; if (moduleName.length && e.file.length > moduleName.length && e.file[0 .. moduleName.length] == moduleName) { // Exception originates in the same module, don't print // the stack trace. // TODO: omit stack trace only if assert was thrown // directly by the unittest. continue; } } // TODO: perhaps indent all of this stuff. _d_print_throwable(e); }
Re: New programming paradigm
On Thursday, 7 September 2017 at 17:13:43 UTC, EntangledQuanta wrote: On Thursday, 7 September 2017 at 15:36:47 UTC, Jesse Phillips wrote: [...] All types have a type ;) You specified in the above case that m is an int by setting it to 4(I assume that is what var(4) means). But the downside, at least on some level, all the usable types must be know or the switch cannot be generated(there is the default case which might be able to solve the unknown type problem in some way). [...] Nice for simple types but fail for struct, array & object Current variant implementation is lack of type-id to check for above ones. For this lacking, is there a runtime (not compile time - trait) to check if a type is a struct or array or object? Cheer
Compiler bug?
abstract class A { string _s; @property: final string s() { return _s; } A s(string x) { _s = x; return this; } } class B : A { @property: final override A s(string x) { _s = x; return this; } } void main() { B b = new B(); b.s = "abc"; assert(b.s == "abc"); } Compilation output /d536/f408.d(32): Error: function f408.B.s (string x) is not callable using argument types ()
How to fix wrong deprecation message - dmd-2.075.1
void main() { import std.utf : toUTF16; // Same problem with toUTF8 wstring s = toUTF16!string("abc"); } Compilation output: /d500/f513.d(3): Deprecation: function std.utf.toUTF16 is deprecated - To be removed November 2017. Please use std.utf.encode instead. /d500/f513.d(3): Deprecation: function std.utf.toUTF16 is deprecated - To be removed November 2017. Please use std.utf.encode instead.