std.array.array for immutable data types
Is there a way to avoid using to! conversion here? immutable string[] dst = to!(immutable string[])(array(pipe.readEnd.byLineCopy));
Re: enumerated iteration to struct
On Wednesday, 7 February 2018 at 01:10:34 UTC, Fra Mecca wrote: I don't know if this post belongs to the learn section, but I'll try anyway. I am using the std.path.pathSplitter function that returns a PathSplitter function exposing ranges primitive. I have some question that could be generalized to other structs that expose range primitives. 1. Why can't I write foreach(i, el; pathSplitter("foor/bar").enumerate) ? 2. Supposing I want to fix this problem, what do I add to the struct? opApply? There was a stupid stupid error on my part because I wasn't import the range module. 3. Why doesn't ranges infer the iteration method at compile time so that I don't need to write enumerate? This question is still valid. I think it would be saner to write foreach(idx, el; paths) instead of foreach(idx, el; paths.enumerate)
enumerated iteration to struct
I don't know if this post belongs to the learn section, but I'll try anyway. I am using the std.path.pathSplitter function that returns a PathSplitter function exposing ranges primitive. I have some question that could be generalized to other structs that expose range primitives. 1. Why can't I write foreach(i, el; pathSplitter("foor/bar").enumerate) ? 2. Supposing I want to fix this problem, what do I add to the struct? opApply? 3. Why doesn't ranges infer the iteration method at compile time so that I don't need to write enumerate?
Re: rdmd main.d leads to Segmentation fault
On Friday, 26 January 2018 at 22:40:29 UTC, Timoses wrote: Hey, simple hello world crashes with segfault: [...] Where did you get the D toolchain? Does the same segmentation fault happen with dmd or gdc or ldc? (dmd should be the more probable) Can you compile a dub project?
Help me understand how to contribute to bugs report / fixing
Hi, I have been lurking in the bug tracker for some time, checking and trying to reproduce bugs and fixes. I finally want to submit something and contribute but I am having an hard time understanding the workflow. Pull request are done via git and bugs reported by the tracker. The problem is when I want to understand if the bug of the tracker is referenced in the repo of the organization and has an open PR. --- Real world case: this bug has been reported recently: https://issues.dlang.org/show_bug.cgi?id=18288#add_comment but it should be closed given how in the recent changes to the phobos master branch the bug is fixed. You can double check that by running the code snippet using dmd-nightly in run.dlang.io. From a quick glance at the phobos repo, I found no mention of this bug in any closed or open PR, just a PR (#6056, bug 18280) on the same file (comparison.d) that probably fixed the issue for bug 18288. What should I do now? I am undecided between: - commenting on the bug tracker and close the bug - link the pr 6056 on the bug tracker - leaving it be I feel that the section "Get involved" on the D wiki should aid newcomers with a more detailed description of the workflow of maintainers and collaborators.
Create D portable binary
Is there a way to compile a project and deploying it as a single statically linked binary? My main target would be something like a self contained jar (like .war files), but something that is in the style of go binaries and portable to another Linux distribution without any hassle would be enough. From what I understand the main problem in achieving this is the dependency to curl (all the warnings related to gethostbyname during linking phase) and glibc that makes it hard to static link. What if musl is used as libc? Right now it seems that the only viable option is to distribute object files and make the end user link them
How to declare immutable struct outside of try catch and reference it later
I have this code: Configuration conf = void ; try { conf = parse_config("config.sdl"); } catch (Exception e) { std.stdio.stderr.writeln("Error reading configuration file: ", e.msg); exit(1); } // other code function(value, conf); // end I get: source/app.d(18,3): Error: cannot modify struct conf Configuration with immutable members Is there a way to declare conf outside of the try catch block and use it later? I thought void explicitly avoid inizialization.
Strange error when compiling with dmd, not with ldc
I have this struct: immutable struct Configuration { string title; string baseurl; string url; string email; string author; string parser; string target; string urlFormat; string urlFormatCmd; short port; string[] ignore; string[] extensions; @property string toString() { auto urlF = (urlFormatCmd ? "url_format_cmd: " ~ urlFormatCmd : "") ~ "\n"; return "title: "~ title ~ "\n" ~ "baseurl: " ~ baseurl ~ "\n" ~ "url: " ~ url ~ "\n" ~ "email: "~ email ~ "\n" ~ "author: " ~ author ~ "\n" ~ "parser: " ~ parser ~ "\n" ~ "target: " ~ target ~ "\n" ~ "url_format: " ~ urlFormat ~ "\n" ~ "ignore: " ~ to!string(ignore)[1 .. $ - 1] ~ "\n" ~ "extensions: " ~ to!string(extensions)[1 .. $ - 1] ~ "\n" ~ urlF; } } and this function: void show_config() { writef("%s", parse_config( exists("config.sdl") ? "config.sdl" : "").toString); } Whenever I compile with ldc2 I get no errors, while with dmd I get: source/configuration.d(105,27): Error: immutable method configuration.Configuration.toString is not callable using a mutable object What is the problem?
behaviour of spawnProcess
I have this snipper of code: auto pid = spawnProcess([exe, j], po.readEnd, pi.writeEnd, std.stdio.stderr); where exe is the executable name and j is argv[1]. I have noticed that whenever j contains a string with a space in it, spawnprocess splits the string into another argument. In this way, even if I can use an array to index the arguments, the behaviour is very different from execvp or subprocess.call. Is this desired? Or is it a bug?
Static if on release build
I can't find any documentation regarding conditional compilation in release and debug mode. I have read the page regarding the topicon dlang.org but adding the snippet below makes no difference when compiling with dub -b release { version(full) { //do something } else { //do something else } How can I produce a release version with different parameters from debug using dub and static if's?
Re: Containers and arrays with custom memory allocators
On Tuesday, 17 October 2017 at 14:14:19 UTC, Ivan wrote: Hi, I am a C/C++ programmer interested in using D as a replacement for C/C++. I do care a lot about performance and memory management, so I want to use my own (or from std.experimental) memory allocators. Are there any good tutorials or examples about how to use custom memory allocators for arrays and existing containers? Or should I just go ahead and write my own containers that are allocator aware? Thanks. I am still working on it, but given your case it may be useful. https://github.com/FraMecca/D_Libraries_Registry
Re: Is there an opposite of .toString()?
On Saturday, 14 October 2017 at 00:18:35 UTC, myst wrote: I'm sorry if this has been answered already, it seems like a very basic question. There is .toString() method convention for printing, but I can not find anything alike for reading. Is there something like operator>>() in C++? What's an ideomatic way of reading an object? Can you make an example of "reading from object"? Or better some snippet of a c++ code that does what you mean
Re: Add a precompiled c++ obj file to dub
On Saturday, 7 October 2017 at 23:54:50 UTC, user1234 wrote: On Saturday, 7 October 2017 at 19:56:52 UTC, Fra Mecca wrote: Hi all, I am writing a backend that is partly Vibe.d and partly clucene in c++. I have some object files written in c++ and compiled with g++ that are not considered by dub during the linking phase and throws `function undefined error ` every time. Is there a way to tell dub to let dmd handle that .o files? Yes, add this to your JSON: "sourceFiles-linux-x86_64" : [ "somepath/yourobject.o" ], I tried the sourceFiles approach, it failed and I could reproduce that in some days. At the end I added them as linking options (lflags) but it is kinda odd that it works given that everything is supplied to dmd as -Lobj.o
Add a precompiled c++ obj file to dub
Hi all, I am writing a backend that is partly Vibe.d and partly clucene in c++. I have some object files written in c++ and compiled with g++ that are not considered by dub during the linking phase and throws `function undefined error ` every time. Is there a way to tell dub to let dmd handle that .o files?
Odd stacktrace: Access Violation in object.TypeInfo_Interface.getHash
I encountered a runtime error in my code and all I can get (even in debug mode) is the following stacktrace: object.Error@(0): Access Violation 0x0051C308 in const(nothrow @trusted uint function(const(void*))) object.TypeInfo_Interface.getHash 0x0058D2C0 in D6engine5world5world5World6__vtblZ Error executing command run: Program exited with code 1 No other information is provided. Anyone ever experienced anything similar? That __vtblZ part of the symbol name scares me a bit, TBH. The codebase is big, so will take me some time to reduce it to a simple example, even if I were to use dustmite, but I was hoping that someone faced this error message before and could give me a pointer on what to look for.
Classes and @disable this()
I just realized that you cannot define a disabled default constructor for classes: writing code like this will give a linker error class Something {
Re: Classes and @disable this()
On Sunday, 8 February 2015 at 16:22:36 UTC, fra wrote: Missclick... Anywya: class Something { @disable this(); this(int i) {} } produces an undefined reference error. I guess it has to do with classes implicitly inheriting from Object, and Object defining a this(), and @disable telling the compiler not to produce code for the given function. However making it a compiler error would be far, far better then getting the linker error. In my case, the mangled name was 100% unintelligible (the usual _ctor was nowhere to be found, probably due to the class name being so long that it was getting shortened in some way)
Re: Fast array copy. SIMD manual or automatic?
On Saturday, 7 February 2015 at 06:30:32 UTC, tcak wrote: I have two char arrays at the size of 16KB. I will copy a part of data between them again and again. arrayA[0 .. dataLen] = arrayB[0 .. dataLen]; Does the compiler generate code that uses SIMD operations (128-bits memory copy) automatically, or do I need to do anything special for this? Does SIMD even matter anything when it comes to copying? I was sure it was just about moving data into SIMD registers for later operation on that.
Re: Tracing down core.exception.InvalidMemoryOperationError
On Monday, 28 July 2014 at 22:13:56 UTC, Joakim wrote: On Monday, 28 July 2014 at 13:31:08 UTC, Martin Drasar via Digitalmars-d-learn wrote: On 28.7.2014 14:09, Joakim via Digitalmars-d-learn wrote: More broadly speaking, it is thrown whenever certain memory operations are attempted while the GC is running, 6 in all, as you can see here: https://github.com/D-Programming-Language/druntime/blob/master/src/gc/gc.d#L458 I believe I stuck in printfs till I found out which one was run before the error was thrown, and then traced that back with more printfs to where it was getting called. I didn't have a debugger available, you may be able to trace faster with one. Hi, thanks for the tip. I have a debugger at hand and I am would prefer to use it. However, I don't really know where and how to start. I would like to break at core/exception.d when onInvalidMemoryOperationError is called, but I am not sure how to build druntime with debug information. There does not seem to be some flag in the makefile like for dmd. Is there some document describing how to do this? It's not in the makefile; I simply added the -g or -gc flag where it compiled and then the debug symbols showed up in the debugger. You may also want to experiment with the -debug flag, which will turn on various kinds of log output depending on which module and flag you use it with. I can tell you it is the logger, for sure. I have had similar problems in the past because I was trying to print a string in a destructor, and even just using the string concatenation is enough for an allocation to happen and for the exception to ruin everything. As a bonus, the exception is thrown from another thread :P In fact, now that we have @nogc I really think we could use *at least a warning* if the compiler determines that allocation might happen inside a destructor... (btw: a debug strategy might be: fire up dmd beta 2.066, add @nogc at all destructors and see where the compiler complains)
std.string inPattern() and UTF symbols
various (UTF) symbols seems to be ignored by inPattern, see http://dpaste.dzfl.pl/e8ff9002 for a quick example (munch() uses inPattern() internally) Is it me doing something in an improper way, or is the documentation lacking more specific limitation of the function? All I can read is In the future, the pattern syntax may be improved to be more like regular expression character classes. This doesn't sound like non-ascii symbols are not supported
Re: std.string inPattern() and UTF symbols
On Monday, 9 December 2013 at 16:10:34 UTC, qznc wrote: That is probably not the root of Fras problem, though. You are right, that was not the root, even if the mistake is extremely simple: foreach(c, s) is used to seek the string. I just realized that foreach can mess things up when used on strings. I can't scroll the feeling this is a pitfall of the language: the code foreach (immutable dchar c; s) writeln(token: , c); produces deeply different results than foreach (c; s) writeln(token: , c); see http://dpaste.dzfl.pl/302291fd I understand why foreach would produce such a result, but I guess newcomers will get burnt by this. I will open a bug report for the munch function in the mean time.
Re: std.string inPattern() and UTF symbols
On Monday, 9 December 2013 at 16:10:34 UTC, qznc wrote: On Monday, 9 December 2013 at 15:58:53 UTC, qznc wrote: I also smell a unicode bug, due to the combination of foreach and length. Bug reported. :) https://d.puremagic.com/issues/show_bug.cgi?id=11712 That is probably not the root of Fras problem, though. Your ticket: The following assert fails, but should not. assert(!inPattern('a', äöüa-z)); Actually, 'a' IS in the given pattern, so the inPattern should return true, then you negate it and therefore it fails. Long story short, it should fail, and it does. So your bug report is actually incorrect.
is there anything like a DUB manual?
I finally decided to try out DUB. The simple examples work great, but I could not find any user guide/list of possible options to be put in the package.json file. Just as an example, how do you pass specific compiler flags like '-J'?
Re: is there anything like a DUB manual?
On Saturday, 7 December 2013 at 20:13:52 UTC, Nicolas Sicard wrote: Did you have a look at http://code.dlang.org/package-format ? how the hell did I managed to miss that? :D Thankee
Re: Is this reasonable?
On Friday, 6 December 2013 at 02:11:20 UTC, Jonathan M Davis wrote: Regardless, we're pretty much stuck at this point. Changing it would silently break lots of code. I still wonder what was the reasoning behind C's warning about comparison between signed and unsigned integers instead of giving an error. And as much as I do understand the no warnings policy, I really think that if you keep features from C, you should also keep C warnings. (BTW: I was quite sure dmd warned the user, maybe it was GDC or LDC instead?)
Re: Is this reasonable?
On Friday, 6 December 2013 at 11:56:35 UTC, Jonathan M Davis wrote: There's no such thing as standard warnins in C. What gets warned about depends entirely on the compiler and what it's settings are. You are 100% right, I was speaking out of my mind. Anyway, I still don't understand the rationale behind allowing those comparisons in C in the first place, but I guess I will never know :P