Re: bool passed by ref, safe or not ?
On Wednesday, 5 June 2024 at 01:18:06 UTC, Paul Backus wrote: The only safe values for a `bool` are 0 (false) and 1 (true). AFAIK that was fixed and now full 8-bit range is safe.
Re: How to pass in reference a fixed array in parameter
On Tuesday, 4 June 2024 at 12:22:23 UTC, Eric P626 wrote: I try to create a 2D array of fixed length and pass it in parameter as a reference. Normally, in C, I would have used a pointer as parameter, and pass the address of the array. Not obvious what you're trying to do. How would you do it in C? Use one dimensional array? You can use one dimensional array in D too. If dimensions of the maze are dynamic, you just write the maze creation function that allocates the maze as you want. In simple case: ``` void main() { writeln("Maze generation demo"); s_cell [5][5] maze; print_maze (maze); } void print_maze (ref s_cell [5][5] maze ) { } ``` With factory: ``` void main() { s_cell[][] maze=make(5,5); print_maze(maze); } void print_maze(s_cell[][] maze) { } s_cell[][] make(int width, int height) { } ```
Re: How to pass in reference a fixed array in parameter
With accessor: ``` void main() { s_cell[] maze=make(5,5); s_cell a=maze.get(1,2); print_maze(maze); } void print_maze(s_cell[] maze) { } s_cell[] make(int width, int height) { return new s_cell[width*height]; } s_cell get(s_cell[] maze, int x, int y) { return maze[5*y+x]; //oops } ``` looks like you need to store the maze width somewhere.
Re: How to use D without the GC ?
1) arena allocator makes memory manageable with occasional cache invalidation problem 2) no hashtable no problem 3) error handling depends on your code complexity, but even in complex C# code I found exceptions as boolean: you either have an exception or you don't 4) I occasionally use CTFE, where `@nogc` is a nuisance 5) polymorphism can be a little quirky
Re: Why `foo.x.saa.aa` and `foo.y.saa.aa` is the same? `shared_AA.saa` should still be instance variable, not class variable, right?
It's a bug.
Re: freebsd dub linker error
Try to run clang with -v option and compare with gcc.
Re: How to debug thread code
On Sunday, 10 July 2022 at 21:27:08 UTC, Hipreme wrote: "Your app has entered a break state, but there is no code to show because all threads were executing external code (typically system or framework code)." Open the threads window and click on threads there, their stack will be in the stack window.
Re: null == "" is true?
On Tuesday, 12 July 2022 at 20:36:03 UTC, Antonio wrote: Honestly, it is difficult to understand for newcomers... there is a reason, but there is a reason in javascript for `0 == ''` too People would have different preferences there. Difference between null and empty is useless. D does the right thing here, what other languages do, is a mistake. If you want such difference, use the Nullable wrapper or Algebraic.
Re: null == "" is true?
On Monday, 18 July 2022 at 21:23:32 UTC, Antonio wrote: I will study it in detail and report (if required). May be, I will write the DTO problem with D article if I find time in august. In my experience null and empty in DTOs usually play the same logical role. It's a very contrived technical difference without practical usage, such distinction is way beyond any business logic. Even if you implement this distinction, I'm not sure anybody will carefully pay attention to it. In languages that make difference between null and empty, null is often replaced with empty to work around problems with null, such codebase can't properly preserve null values.
Re: null == "" is true?
On Tuesday, 19 July 2022 at 10:29:40 UTC, Antonio wrote: The summary is that a DTO that works like a Map needs to represent the absent key ant this is not the same that the Null value Example: ```d struct Null { /*...*/ } struct Undefined { /*...*/ } struct ContactDto { DtoVal!(Undefined, string) name DtoVal!(Undefined, Null, string) phonenumber, DtoVal!(Undefined, AddressDto) address } // ... ContactDto data = {phonenumber:Null(), address:{city:{code:"BCN"}}}; updateContact(id, data); ``` As I understand, in your scenario there's no difference between null string and empty string, they both work like empty string, and D treats them as empty string. That's what I mean when I said that distinction between null and empty is meaningless.
Re: null == "" is true?
Also what's the difference between null and empty phone number?
Re: null == "" is true?
On Tuesday, 19 July 2022 at 18:05:34 UTC, Antonio wrote: In a relational database, `NULL` is not the same that `""`... and `NULL` is not the same that `0`. Are semantically different and there are database invariants (like foreign keys) based on it. Trying to "mix" this concepts in a database is a mistake. So, it's an implementation detail or a relational database that leaks into business logic because nobody thought about it? Just because a relational database has many features, it doesn't mean business logic must use them all, it must use only what makes sense for business logic. When you treat with Domain Models, you try to represent this semantics in all levels of your software... including APIs What semantics your domain models implement? Is it semantics of all features of a relational database or is semantics of business logic?
Re: char* pointers between C and D
This is how to do it the D way: ``` int main(string[] args) { string ch1 = "Hello World!"; char[] ch2="Hello World!".dup; string s1=ch1[1..$]; char[] s2=ch2[1..$]; writeln(s1); writeln(s2); return 0; } ```
Re: toString doesn't compile with -dip1000 switch
Bar.toString is typed `@system`.
Re: How to workaround on this (bug?)
Provide two functions and let the caller choose ``` void fun(ref Variant v) nothrow { } void fun2(Variant v) { fun(v); } ```
Re: Static executable (ldc, linux)
ldc2 -link-defaultlib-shared=false or something like that
Re: Is "auto t=T();" not the same as "T t;"?
Looks like explicitly initialized variable in this case allocates array literal. Uninitialized variable is initialized with init pattern. This may be correct as uninitialized variable isn't guaranteed to hold a value most useful for you, it's only guaranteed to hold a defined value.
Re: dub ldc2 static linking
On Friday, 28 October 2022 at 02:46:42 UTC, ryuukk_ wrote: I'm just right now having an issue with glibc version mismatch for my server Just compile with an old enough glibc, 2.14 works for me.
Re: Make IN Dlang
On Tuesday, 1 November 2022 at 23:40:22 UTC, Christian Köstlin wrote: I am still trying to find answers to the following questions: 1. Is it somehow possible to get rid of the dub single file scheme, and e.g. interpret a full dlang script at runtime? If there was an interpreter like ``` #!/bin/mind ...code ``` maybe it could run dub with right options and thus won't need a build script.
Re: Make IN Dlang
But embedded sdl is likely to be dwarfed by the actual code anyway.
Re: Make IN Dlang
Another idea is to separate the script and interpreter then compile them together. ``` --- interp.d --- import script; import ...more stuff ...boilerplate code int main() { interpret(script.All); return 0; } --- script.d --- #! ? module script; import mind; auto All=Task(...); ...more declarative tasks --- run --- dmd /usr/local/interp.d /path/to/script.d ```
Re: aa.keys, synchronized and shared
Try this: ``` synchronized final class SyncAA(K, V) { V opIndex(K key) { return sharedTable[key]; } V opIndexAssign(V value, K key) { return sharedTable[key]=value; } const(K[]) keys() const { return unsharedTable.keys; } void remove(K key) { sharedTable.remove(key); } V get(K key, lazy V defaultValue=V.init) { auto p = key in sharedTable; return p ? *p : defaultValue; } private: V[K] sharedTable; ref inout(V[K]) unsharedTable() inout { return *cast(inout(V[K])*)&sharedTable; } } void f(shared SyncAA!(string,string) a) { a.keys(); a["12"]="34"; a.remove("12"); } ```
Re: aa.keys, synchronized and shared
With allocation: ``` synchronized final class SyncAA(K, V) { V opIndex(K key) { return sharedTable[key]; } V opIndexAssign(V value, K key) { return sharedTable[key]=value; } const(K[]) keys() const { return unsharedTable.keys; } void remove(K key) { sharedTable.remove(key); } V get(K key, lazy V defaultValue=V.init) { auto p = key in sharedTable; return p ? *p : defaultValue; } private: V[K] sharedTable; ref inout(V[K]) unsharedTable() inout { return *cast(inout(V[K])*)&sharedTable; } } shared SyncAA!(string,string) saa; void f() { saa=new shared SyncAA!(string,string); saa.keys(); saa["12"]="34"; saa.remove("12"); } ```
Re: aa.keys, synchronized and shared
This works for me: ``` synchronized final class SyncAA(K, V) { this(K key, V val) { sharedTable[key]=val; } V opIndex(K key) { return sharedTable[key]; } V opIndexAssign(V value, K key) { return sharedTable[key]=value; } const(K[]) keys() const { return unsharedTable.keys; } void remove(K key) { sharedTable.remove(key); } V get(K key, lazy V defaultValue=V.init) { auto p = key in sharedTable; return p ? *p : defaultValue; } private: V[K] sharedTable; inout(V[K]) unsharedTable() inout { return cast(inout(V[K]))sharedTable; } } shared SyncAA!(string,string) saa; void f() { saa=new shared SyncAA!(string,string)("1","2"); saa.keys(); saa["12"]="34"; saa.remove("12"); } ```
Re: How often I should be using const? Is it useless/overrated?
On Friday, 18 November 2022 at 17:57:25 UTC, H. S. Teoh wrote: You're looking at it the wrong way. The kind of issues having const would solve is like when your function takes parameters x, y, z, and somewhere deep in the function you see the expression `x + y*z`. If x, y, and z are const, then you immediately know what the value of this expression is. However, if they were not, then you'd have to trace through all of the preceding code to figure out whether their values have changed, and how they have changed. The former makes the code easier to understand, the latter adds complexity to understanding the code. AFAIK Rust allows shadowing (intentionally) to solve usability problems with immutable variables, so when deep in the function you see `x+y*z`, you can't immediately tell its value, because the variables could be previously shadowed and you have to trace through all of the preceding code to figure it out :)
Re: Logging logs in Windows
On Saturday, 4 February 2023 at 13:31:41 UTC, Alexander Zhirov wrote: I understand that programming under Windows is a shame for a programmer, but is there really no ready-made solution for using the system log in Windows? It would be a logging library like log4j that would have different logging backends.
Re: Non-ugly ways to implement a 'static' class or namespace?
On Monday, 23 January 2023 at 00:36:36 UTC, thebluepandabear wrote: It's not a freedom issue, it's a library-design issue. Some libraries want to incorporate a namespace-like design to force the user to be more 'explicit' with what they want. SFML has a `Keyboard` namespace which has a `Key` enum. The user is 'forced' (although I am not sure if this is the case since it's C++) to use the `Keyboard.` declaration before using the `Key` enum. Looking at code block 1 and 2, which makes more sense? Pretty sure you can strip namespaces in any language that has namespaces, C# routinely does it and refers to all types with their nonqualified names. It even has Keys enum: https://learn.microsoft.com/en-us/dotnet/api/system.windows.forms.keys which is referred to as Keys after stripping the System.Windows.Forms namespace.
Re: Non-ugly ways to implement a 'static' class or namespace?
On Friday, 10 February 2023 at 14:17:25 UTC, Kagamin wrote: Pretty sure you can strip namespaces in any language that has namespaces, C# routinely does it and refers to all types with their nonqualified names. It even has Keys enum: https://learn.microsoft.com/en-us/dotnet/api/system.windows.forms.keys which is referred to as Keys after stripping the System.Windows.Forms namespace. An example from KeePass: https://github.com/dlech/KeePass2.x/blob/VS2022/KeePass/Util/SendInputExt/SiCodes.cs#L86
Re: Non-ugly ways to implement a 'static' class or namespace?
On Friday, 10 February 2023 at 21:52:02 UTC, ProtectAndHide wrote: Well in Swift, there is no problem .. at all. Why is it a problem in D then? (and I mean technically). What about the increment operator `++` ?
Re: Non-ugly ways to implement a 'static' class or namespace?
On Monday, 13 February 2023 at 08:22:06 UTC, ProtectAndHide wrote: Chris Lattner outlines the reasons for removing it in Swift 3.0 here: https://github.com/apple/swift-evolution/blob/main/proposals/0004-remove-pre-post-inc-decrement.md So your complaint is that you agree with Chris Lattner and disagree with others?
Re: Non-ugly ways to implement a 'static' class or namespace?
My point is you know you're just picky.
[OT] (Go) Do I read it right?
https://github.com/dominikh/go-tools/issues/917 How go programmers cope with this feature?
Re: Best way to read/write Chinese (GBK/GB18030) files?
On Monday, 13 March 2023 at 00:32:07 UTC, zjh wrote: Thank you for your reply, but is there any way to output `gbk` code to the console? I guess if your console is in gbk encoding, you can just write bytes with stdout.write.
Re: Threads
static is thread local by default. ``` module main; import app; import core.thread; int main(string[] args) { static shared int result; static shared string[] args_copy; static void app_thread() { App app = new App(); result = app.run(args_copy); } args_copy = cast(shared)args; // Running app interface in a thread; Thread thread = new Thread(&app_thread).start(); thread.join(); return result; } ```
Re: Best way to read/write Chinese (GBK/GB18030) files?
https://dlang.org/phobos/std_stdio.html#rawWrite
Re: Convert binary to UUID from LDAP
This guid is (int,short,short,byte[8]) in little endian byte order. So if you want to convert it to big endian, you'll need to swap bytes in those int and two shorts. ``` ubyte[] guid=... int* g1=cast(int*)guid.ptr; *g1=bswap(*g1); ```
Re: Convert binary to UUID from LDAP
This guid is (int,short,short,byte[8]) in little endian byte order. So if you want to convert it to big endian, you'll need to swap bytes in those int and two shorts. ``` ubyte[] guid=... int* g1=cast(int*)guid.ptr; *g1=bswap(*g1); ```
Re: Log rotation in std.logger.filelogger
I suppose you write a custom logger for that or take an already written one from code.dlang.org
Re: Compiling to RiscV32
You try to use C declarations, but they are specific to each C library, and different C libraries have different declarations, so headers can't decide which C library declarations to use. Try -mtriple=riscv32-unknown-linux
Re: Compiling to RiscV32
Worked for me on ldc 1.20 https://forum.dlang.org/post/vuxuftogvszztdrrt...@forum.dlang.org
Re: Compiling to RiscV32
Probably bug in druntime, v-functions shouldn't have `pragma(printf)`, because they don't have arguments to check.
Re: Compiling to RiscV32
Maybe the problem is with va_list, try to compile with -mtriple=riscv64-unknown-linux -mcpu=generic-rv64
Re: Print debug data
Naming is hard.
Re: AA vs __gshared
On Friday, 28 July 2023 at 03:54:53 UTC, IchorDev wrote: I was told that using `__gshared` is quite a bit faster at runtime than using `shared`, but I also don't really know anything concrete about `shared` because the spec is so incredibly vague about it. The difference between them is purely formal if you're not on an old gdc, where shared was synchronized like C# volatile. If the crashes are frequent, can you reproduce a crash with a minimal amount of code, start many threads and access the locked AA concurrently.
Re: array index out of bound may not throw exception?
On Friday, 21 July 2023 at 23:40:44 UTC, mw wrote: Is there a way to let it report on the spot when it happens? On linux if you catch an exception and call abort, the debugger will show you where abort was called, on windows you can call DebugBreak function, the debugger will show where it was called.
Re: Is it possible to make an Linux Executable Binary using a Windows Operating System? [compiling and linking]
You will also need crt1.o, crti.o, crtn.o and libc.a
Re: AA vs __gshared
Your error is using allocating the object with malloc. Since gc doesn't see your AA, the AA is freed and you get UAF.
Re: malloc error when trying to assign the returned pointer to a struct field
On Friday, 8 September 2023 at 13:32:00 UTC, rempas wrote: On Friday, 8 September 2023 at 13:05:47 UTC, evilrat wrote: ```d import core.stdc.stdlib; import core.stdc.stdio; alias u64 = ulong; alias i64 = long; struct Vec(T) { private: T* _ptr = null; // The pointer to the data u64 _cap = 0; // Total amount of elements (not bytes) we can store u64 _len = 0; public: /* Create a vector by just allocating memory for it. The null terminator is not set for strings as, the vector is considered empty and we should first push something to it in order to use it! */ this(i64 size) { this._len = 0; this._cap = size; static if (is(T == char)) { size += 1; } // Additional space for the null terminator this._ptr = cast(T*)malloc(size); } ref T opIndex(size_t idx) { return _ptr[idx]; } } extern(C) void main() //unittest { enum el = 3; auto vec = Vec!char(10); assert(vec._ptr); vec[el] = 'h'; assert(vec[el] == 'h'); printf("ptr = %p\n", vec._ptr); printf("vec ptr = %p\n", &vec[el]); printf("vec local = %p\n", &vec); printf("vec[%d] = %c\n", el, vec[el]); foreach (i; 0..vec._cap) { printf("-"); } printf("\n"); foreach (i; 0..vec._cap) { printf("%d", vec[i]); } printf("\n"); printf("run ok\n"); } ``` ldc2 -betterC -run membug.d output ``` ptr = 0x55cb701de2a0 vec ptr = 0x55cb701de2a3 vec local = 0x7fffa1542258 vec[3] = h -- 00010400 run ok ``` I have made a search on the web and I found out one thread that pointed out that it may be a Glibc error. However, because like I said the problem only happens when I assign the returned value to the `_ptr` field, I just wanted to post here in case someone has a similar experience and if it's a compiler bug in which case, we should report it. Did you run this example program above? Does it crash?
Re: DMD: How to compile executable without producing .obj file?
The .exe is produced by the linker, which works with files: it takes one or more .obj files with program code and links them into and .exe file. I heard ldc has builtin linker or something like that, so hypothetically might be able to link on the fly.
Re: ImportC: Windows.h
You can declare them ``` extern(C) void _InterlockedExchangeAdd(){ assert(false); } ```
Re: ImportC: Windows.h
Is GENERIC_WRITE awailable?
Re: Behaves different on my osx and linux machines
Add more debugging? ``` bool done = false; while (!done) { writeln(1); auto result = ["echo", "Hello World"].execute; if (result.status != 0) { writeln(2); throw new Exception("echo failed"); } writeln(result.output); receiveTimeout(dur!"msecs"(-1), (LinkTerminated t) { writeln("Done"); done = true; }, ); writeln(3); } writeln("ByeBye"); ```
Re: Behaves different on my osx and linux machines
Maybe write and read lock each other, try to use puts: ``` bool done = false; while (!done) { puts("1"); auto result = ["echo", "Hello World"].execute; if (result.status != 0) { writeln(2); throw new Exception("echo failed"); } puts("2"); writeln(result.output); puts("3"); receiveTimeout(dur!"msecs"(-1), (LinkTerminated t) { writeln("Done"); done = true; }, ); writeln(4); } writeln("ByeBye"); ```
Re: Behaves different on my osx and linux machines
Maybe you're not supposed to print text while reading?
Re: Error "Outer Function Context is Needed" when class declared in unittest
Looks like the context is currently passed for nested functions, not for nested classes.
Re: Accessing array elements with a pointer-to-array
On Thursday, 25 January 2024 at 20:11:05 UTC, Stephen Tashiro wrote: void main() { ulong [3][2] static_array = [ [0,1,2],[3,4,5] ]; static_array[2][1] = 6; } The static array has length 2, so index 2 is out of bounds, must be 0 or 1.
Re: length's type.
I have an idea to estimate how long strlen takes on an exabyte string.
New discussion
You can just post with a new title.
Re: what was the problem with the old post blit operator already ?
It was mostly fine, such types are not supposed to be immutable, but recently came an idea of reference counted strings, which need to be immutable for being strings.
Re: length's type.
On Thursday, 8 February 2024 at 05:56:57 UTC, Kevin Bailey wrote: How many times does the following loop print? I ran into this twice doing the AoC exercises. It would be nice if it Just Worked. ``` import std.stdio; int main() { char[] something = ['a', 'b', 'c']; for (auto i = -1; i < something.length; ++i) writeln("less than"); return 0; } ``` Try this: ``` import std.stdio; int ilength(T)(in T[] a) { assert(a.length<=int.max); return cast(int)a.length; } int main() { char[] something = ['a', 'b', 'c']; for (auto i = -1; i < something.ilength; ++i) writeln("less than"); return 0; } ```
Re: length's type.
On Tuesday, 13 February 2024 at 23:57:12 UTC, Ivan Kazmenko wrote: I do use lengths in arithmetic sometimes, and that leads to silent bugs currently. On the other hand, since going from 16 bits to 32 and then 64, in my user-side programs, I had a flat zero bugs because some length was 2^{31} or greater -- but at the same time not 2^{32} or greater. So, in D, I usually `to!int` or `to!long` them anyway. Or cast in performance-critical places. I had a similar bug in C++: the find function returns npos sentinel value when not found, it was assigned to uint and then didn't match npos on comparison, but it would if they were signed.
Re: vibe.d still does not work on FreeBSD.
Docs say SSL_get0_peer_certificate was added in openssl 3.
Re: "Error: `TypeInfo` cannot be used with -betterC" on a CTFE function
On Sunday, 7 April 2024 at 06:46:39 UTC, Liam McGillivray wrote: instantiated from here: `front!char` Looks like autodecoding, try to comment `canFind`.
Re: OT: in economic terms Moore's Law is already dead
TBH modern computers are obscenely powerful, I just spent weeks on celeron 1.8GHz 2mb L2 cache 2gb ram computer and didn't see any slowness on it despite some bloated software in python and a strange text editor pluma that ate 150mb ram just editing a plain text file, I swear it's not based on electron, most operations were seemingly io-bound. On my notebook I downclocked i7 to 50% to reduce it to a decent TDP, there was a reduction in performance... probably, because I don't see it without reference, i7 was a mistake, honestly.
Re: Wrong vtable for COM interfaces that don't inherit IUnknown
On Tuesday, 16 July 2019 at 01:38:49 UTC, evilrat wrote: Also from what I see MS done this intentionally, means they either no longer loves COM or there was some other good reason. Primary consumer of COM interfaces is Visual Basic. It was really only Bill Gates who loved Basic, he wrote a Basic interpreter in 1975 and created Microsoft as a business that sold Basic interpreters. As gamedev was locked in C++, there was no real use case for COM there, so MS probably does the expected thing and goes with straight C++.
Re: Wrong vtable for COM interfaces that don't inherit IUnknown
On Sunday, 21 July 2019 at 07:04:00 UTC, rikki cattermole wrote: COM is used heavily in WinAPI since about Vista. Pretty much all new functionality has been exposed by it and NOT extern(Windows) functions which was the standard during up to about XP (for example notification icons would today be COM based but isn't). E.g. jump lists https://docs.microsoft.com/en-us/windows/win32/api/shobjidl_core/nn-shobjidl_core-icustomdestinationlist Shell object library? It shipped with Internet Explorer 4 and was installable on windows 95. Shell (explorer) is not really winapi, it's more or less a normal userland application that provides integration, like an RPC server, in this way it can be similar to d-bus, but it's difficult to say, because the library abstracts whether it works in process or out of process, most (older) shell objects work in process and simply provide shell logic like moving files to trash bin and creating shortcuts.
Re: Is betterC affect to compile time?
On Thursday, 25 July 2019 at 12:46:48 UTC, Oleg B wrote: What reason for such restrictions? It's fundamental idea or temporary implementation? I think it's a dmd limitation. Currently it has a bug that it can still generate code for ctfe templated functions, and they will fail to link if they use runtime. So yeah, currently betterC really means betterC all the way down. The alternative is to compile without -betterC switch and just use a minimal runtime if you use runtime features, then you have full language in ctfe.
Re: Calling / running / executing .d script from another .d script
On Sunday, 28 July 2019 at 12:56:12 UTC, BoQsc wrote: Right now, I'm thinking what is correct way to run another .d script from a .d script. Do you have any suggestions? You mean something like execute(["rdmd", "another.d"]); ?
Re: Help me decide D or C
On Wednesday, 31 July 2019 at 22:30:52 UTC, Alexandre wrote: 1) Improve as a programmer 2) Have fun doing programs Thats it basically. I am planning to study all "free" time I have. I am doing basically this since last year. Try Basic. It has builtin graphics, seeing you program draw is quite fascinating.
Re: Is it possible to target all platforms that Qt Quick can target?
You're probably interested in readiness, not possibility?
Re: Pro programmer
On Monday, 26 August 2019 at 12:02:12 UTC, GreatSam4sure wrote: I want customizable GUI toolkit like JavaFX and adobe spark framework in D. DWT was translated from java SWT, you can do the same for JavaFX, D is heavily based on java and there's an automatic translation tool from java to D. There's no silver bullet to become a pro, you just work and gain experience and this experience allows you to reflect on coding practices on increasing scale.
Re: D1: How to declare an Associative array with data
Maybe something like this https://forum.dlang.org/post/hloitwqnisvtgfoug...@forum.dlang.org
Re: getting rid of immutable (or const)
On Thursday, 5 September 2019 at 12:46:06 UTC, berni wrote: OK. This are two solutions and although I'll probably not going to use any of those (due to other reasons), I still don't understand, why the original approach does not work. If I've got a book an put it in a box and later I'll get it out again, it's still the same book. So why has a struct changed when I put it into an AA and get it out again? It's not supposed to change... Physical objects work like reference types. A place on bookshelf is at one coordinate and a book is at another coordinate, you don't copy the book, you fill a place on bookshelf with a reference to the book.
Re: Name change weird
Maybe you upgraded SFML and now binding doesn't match?
Re: How to use Dbus to detect application uniqueness in D?
https://ddbus.dpldocs.info/ddbus.bus.requestName.html
Re: How to use Dbus to detect application uniqueness in D?
On Sunday, 29 September 2019 at 02:09:56 UTC, Hossain Adnan wrote: On Saturday, 28 September 2019 at 13:37:12 UTC, Kagamin wrote: https://ddbus.dpldocs.info/ddbus.bus.requestName.html It requires a Connection type which I cannot find in the API. It's in ddbus.thin, missing documentation comment, see unittest: https://ddbus.dpldocs.info/source/ddbus.bus.d.html#L46
Re: How to use Dbus to detect application uniqueness in D?
On Sunday, 29 September 2019 at 02:09:56 UTC, Hossain Adnan wrote: On Saturday, 28 September 2019 at 13:37:12 UTC, Kagamin wrote: https://ddbus.dpldocs.info/ddbus.bus.requestName.html It requires a Connection type which I cannot find in the API. It's in ddbus.thin, missing documentation comment, see unittest: https://ddbus.dpldocs.info/source/ddbus.bus.d.html#L46 and usage example at http://code.dlang.org/packages/ddbus
Re: Eliding of slice range checking
On Wednesday, 23 October 2019 at 11:20:59 UTC, Per Nordlöw wrote: Does DMD/LDC avoid range-checking in slice-expressions such as the one in my array-overload of `startsWith` defined as bool startsWith(T)(scope const(T)[] haystack, scope const(T)[] needle) { if (haystack.length >= needle.length) { return haystack[0 .. needle.length] == needle; // is slice range checking avoid here? } return false; } LDC is good at optimizing simple patterns, the only pitfall I know is https://forum.dlang.org/post/eoftnwkannqmubhjo...@forum.dlang.org
Re: Eliding of slice range checking
On Wednesday, 23 October 2019 at 11:20:59 UTC, Per Nordlöw wrote: Does DMD/LDC avoid range-checking in slice-expressions such as the one in my array-overload of `startsWith` defined as bool startsWith(T)(scope const(T)[] haystack, scope const(T)[] needle) { if (haystack.length >= needle.length) { return haystack[0 .. needle.length] == needle; // is slice range checking avoid here? } return false; } LDC is good at optimizing simple patterns, the only pitfall I know is https://forum.dlang.org/post/eoftnwkannqmubhjo...@forum.dlang.org
Re: Why same pointer type for GC and manual memory?
On Wednesday, 13 November 2019 at 16:43:27 UTC, IGotD- wrote: On Wednesday, 13 November 2019 at 15:30:33 UTC, Dukc wrote: I'm not 100% sure what managed pointers mean -Are they so that you can't pass them to unregistered memory? A library solution would likely do -wrap the pointer in a struct and make it @system to extract it's pointer as "raw". So you cannot put it to C-allocated arrays without type casting, which you probably don't do accidently. Best example is probably managed C++, an MS extension to C++ which is now deprecated. However, it server as an interesting example where MS extended C++ with a ^gc type. AFAIK those managed pointers are not general purpose, but specifically for managed .net objects, you can't allocate unmanaged object on managed heap, and managed object on unmanaged heap. In case of D you would have raw pointers for unmanaged objects allocated in C heap and D GC heap, and additional .net pointers for .net objects.
Re: Parsing with dxml
On Monday, 18 November 2019 at 06:44:43 UTC, Joel wrote: ``` http://www.w3.org/2001/XMLSchema-instance";> ``` You're missing a closing tag.
Re: OR in version conditional compilation
https://issues.dlang.org/show_bug.cgi?id=19495#c1
Re: Best way to learn 2d games with D?
On Thursday, 19 March 2020 at 13:10:29 UTC, Steven Schveighoffer wrote: Similar for me but not GameMaker but RPG Maker. I've seen all your work on the language, and this is a pretty good endorsement. Not sure if I'm ready to pay for it though, I want to make sure his motivation/drive is not going to fizzle out ;) IME RPG Maker has bad support for animations and shines in mostly static turn based RPG battles. Some games try to do nontrivial animations, but they become very slow slideshows with many seconds between slides. Not sure which game he would prefer to make.
Re: Can I get the compiler to warn or fail on uninitialized variables/class members?
Maybe if you teach dparse to do this check.
Re: GtkD - how to list 0..100K strings [solved]
On Monday, 27 April 2020 at 10:28:04 UTC, mark wrote: I renamed the class shown in my previous post from View to InnerView, then created a new View class: class View : ScrolledWindow { import qtrac.debfind.modelutil: NameAndDescription; InnerView innerView; this() { super(); innerView = new InnerView; addWithViewport(innerView); } void clear() { innerView.viewData.clear; } void populate(NameAndDescription[] namesAndDescriptions) { innerView.viewData.populate(namesAndDescriptions); } } Try this: void populate(NameAndDescription[] namesAndDescriptions) { if(namesAndDescriptions.length>100)namesAndDescriptions=namesAndDescriptions[0..100]; innerView.viewData.populate(namesAndDescriptions); }
Re: Spawn a Command Line application Window and output log information
On Monday, 18 May 2020 at 17:02:02 UTC, BoQsc wrote: The important question is: how can we change the name/title of this Command Line application. As the simplest solution, you can set the window title in shortcut properties.
Re: Spawn a Command Line application Window and output log information
On Monday, 18 May 2020 at 17:20:17 UTC, BoQsc wrote: It would be great if we could change/customise the icon of the Command line application that run the HelloWorld application. But I have a bad feeling that it is probably not possible without a GUI library. I think the window icon is just the first icon pulled from the executable file.
Re: How to allocate/free memory under @nogc
On Thursday, 21 May 2020 at 17:19:10 UTC, Konstantin wrote: Hi all! I will try to ask again(previous two posts still have no answers) : are there any site/page/docs somewhere to track actual info about @nogc support in language itself and in phobos library? Or, at least plans to extend such support? https://dlang.org/spec/function.html#nogc-functions - here's language support. Phobos tends to infer attributes like @nogc, so it's context dependent, the actual info is provided by the compiler.
Re: DIP1000 spec?
Logic is apparently still in flux, too early to document.
Re: Initializing an associative array of struct
that's int id=parameters[param].id;
Re: Initializing an associative array of struct
string param="aa"; parameters[param]=Parameter(); in id=parameters[param].id;
Re: GtkD code review - How to update a progressbar using data sharing concurrency
Not sure how much synchronization do you want to do. import gio.Application : GioApplication = Application; import gtk.Application : Application; import gtk.ApplicationWindow : ApplicationWindow; import gtk.ProgressBar : ProgressBar; import glib.Timeout : Timeout; import gtkc.gtktypes : GApplicationFlags, GPriority; shared class Downloader { import core.atomic; string[] links = [`link1`, `link2`, `link3`, `link4`]; private size_t completed = 0; size_t count() { return atomicLoad(completed); } void increment() { atomicOp!"+="(completed, 1); } static void start(shared Downloader downloader) { import std.parallelism : parallel; import core.thread : Thread, seconds; { // emulate HTTP response overhead; Thread.sleep(seconds(2)); } { // emulate random Download time import std.random : Random, uniform; auto rnd = Random(4361); foreach (ref link; downloader.links.parallel()) { Thread.sleep(uniform(0, 6, rnd).seconds()); downloader.increment(); } } } } class ProgressIndicatorBar : ProgressBar { this() { super.setShowText(true); super.setPulseStep(0.2); } } class PrimaryWindow : ApplicationWindow { const int width = 320, height = 100; ProgressIndicatorBar pib; this(Application app) { super(app); super.setSizeRequest(width, height); scope (success) super.showAll(); pib = new ProgressIndicatorBar(); scope (success) add(pib); shared downloader = new shared Downloader(); import std.parallelism : task; auto downloadTask = task!(Downloader.start)(downloader); downloadTask.executeInNewThread(); auto timeout = new Timeout(100, delegate bool() { const long completed=downloader.count, total=downloader.links.length; if (completed < total) { if (completed == 0) { pib.setText(`Awaiting response...`); pib.pulse(); } else { pib.setText(`Downloading...`); double fraction=completed; fraction/=total; pib.setFraction(fraction); } return true; } else { super.setTitle(`Downloading complete`); // pib.setShowText(false); pib.setVisible(false); return false; } }, GPriority.HIGH); } } int main(string[] args) { auto application = new Application(`org.gitlab.helloprogressbar`, GApplicationFlags.FLAGS_NONE); application.addOnActivate(delegate void(GioApplication app) { auto appWindow = new PrimaryWindow(application); }); return application.run(args); }
Re: How to correctly integrate D library to Swift/Obj-C mobile project?
If you want to use them from D, you need those classes and methods declared in the D language, in text.
Re: Downloading files over TLS
On Friday, 26 June 2020 at 10:12:09 UTC, Jacob Carlborg wrote: Downloading files over TLS. This seems that it's something that should be quite simple to do. My high level goals are cross-platform and easy distribution. I don't need anything fancy just a simple API like this: download("https://url.com";, "/local/file"); Maybe just start wget or something like that? * Network [6]. This is an Apple specific library provided by the platform. This is the recommend alternative to SecureTransport. The problem is that this is not just an alternative TLS implementation, it's a completely different alternative to BSD sockets. The API is completely different and will require some extra layers to to provide a cross-platform API. This means that I cannot use any of the existing library to just add TLS, it will be a completely different implementation, which might be ok. Another big problem is that it only available on macOS 10.14 and later. I have not decided yet if this is acceptable or not Since you want the latest certificate storage, you intend to support only the latest system. Many root certificates will timeout now. * Are there any high level APIs, like NSURLSession, on Windows that can be used to download files? https://docs.microsoft.com/en-us/windows/win32/winhttp/about-winhttp
Re: How to send ownerTid into a parallel foreach loop?
std.concurrency is for noninteractive appications, the approach with gui timer was the correct one.
Re: How to send ownerTid into a parallel foreach loop?
On Saturday, 27 June 2020 at 07:51:21 UTC, adnan338 wrote: On Saturday, 27 June 2020 at 07:31:56 UTC, Kagamin wrote: std.concurrency is for noninteractive appications, the approach with gui timer was the correct one. Thank you. That works but my progress bar is sometimes getting stuck because of a possible data race. See https://forum.dlang.org/post/gacweulvbyorkseti...@forum.dlang.org Sometimes? In that code you write the progress variable only once, so it doesn't change after that. Nothing else can possibly happen there with or without multithreading.
Re: Light-weight runtime
On Sunday, 28 June 2020 at 07:09:53 UTC, Виталий Фадеев wrote: I want light-weight runtime ! How to ? Runtime provides language features that rely on extra code. Removing that code from runtime means to give up on corresponding language features. This way you can implement only features you want or even reduce runtime to almost zero. You can start by not linking your code with druntime and see what's missing and see if you can evade or implement the feature.
Re: Garbage collection
On Saturday, 27 June 2020 at 14:49:34 UTC, James Gray wrote: I have produced something which essentially reproduces my problem. What is the problem? Do you have a leak or you want to know how GC works?
Re: Calling C functions
On Monday, 29 June 2020 at 19:55:59 UTC, Steven Schveighoffer wrote: Yep, for sure. I'll file an issue. Anyone know why the calling convention would differ? It's easier to enforce left to right evaluation order this way: arguments are pushed to stack as they are evaluated, which is pascal calling convention.
Re: Program exited with code -11 when calling
bson_t* bson_new_from_json(in char* data, long len, bson_error_t* error); string str_utf8 = "{\"a\":1}"; bson_error_t error; auto bson = bson_new_from_json(str_utf8.ptr, str_utf8.length, &error); You have a wrong declaration for bson_error_t too.