Re: Error 42 When Trying to Interop with a C# Libary
On Saturday, 5 November 2016 at 22:06:21 UTC, Sarcross wrote: LINK : fatal error LNK1104: cannot open file '+C:\Users\antzy_000\Documents\Programming\D\Resume-Parser\src\Parser2.lib' --- errorlevel 1104 dmd failed with exit code 1104. "lflags" : ["+C:\\Users\\antzy_000\\Documents\\Programming\\D\\Resume-Parser\\src\\Parser2.lib"], The error linker error tells you that the linker thinks the path you specified with '+' is a filename (which is why it tacked .lib on the end), meaning it doesn't recognize it as a command line option. That's because when you compile with -m32mscoff, you are using the Microsoft linker (link) rather than optlink, the default. The '+path' syntax is something optlink understands, but link does not. You can find the MS linker commands at [1], in this case you want [2]: "lflags" : "/LIBPATH:C:\Users\antzy_000\Documents\Programming\D\Resume-Parser\src\Parser2" [1] https://msdn.microsoft.com/en-us/library/y0zzbyt4.aspx [2] https://msdn.microsoft.com/en-us/library/1xhzskbe.aspx
Re: Bug after update to 2.072?
On Sunday, 6 November 2016 at 01:11:34 UTC, Alex wrote: dub dustmite ../dm2 --program-status=11 Try --program-status=139 (139 is 128 + 11)
Re: Bug after update to 2.072?
On Saturday, 5 November 2016 at 22:38:31 UTC, cym13 wrote: Could you use DustMite to generate a minimal code sample showing the bug? https://github.com/CyberShadow/DustMite tried dub dustmite ../dm which reduced my code to an empty main... :) and tried dub dustmite ../dm2 --program-status=11 which results to a message in the console: object.Exception@DustMite/dustmite.d(270): Initial test fails (try using --no-redirect for details) 4 dustmite0x00010b7173e8 _Dmain + 3480 5 dustmite0x00010b7a71df D2rt6dmain211_d_run_mainUiPPaPUAAaZiZ6runAllMFZ9__lambda1MFZv + 39 6 dustmite0x00010b7a710b void rt.dmain2._d_run_main(int, char**, extern (C) int function(char[][])*).tryExec(scope void delegate()) + 35 7 dustmite0x00010b7a7184 void rt.dmain2._d_run_main(int, char**, extern (C) int function(char[][])*).runAll() + 44 8 dustmite0x00010b7a710b void rt.dmain2._d_run_main(int, char**, extern (C) int function(char[][])*).tryExec(scope void delegate()) + 35 9 dustmite0x00010b7a7071 _d_run_main + 497 10 dustmite0x00010b717cdf main + 15 11 libdyld.dylib 0x7fffb4a1d254 start + 0 12 ??? 0x0002 0x0 + 2 How to use --no-redirect option? It said Unknown command line flags: --no-redirect when I tried it...
Re: Combining "chunkBy" and "until" algorithms
On 2016-11-05 14:57, Timon Gehr wrote: "chunkBy" a predicate that checks whether a line is standard. Use 'zip' to focus two adjacent chunks at the same time. Use 'filter' to only consider adjacent chunks where the first chunk consists of standard lines. Then extract the last line of the first chunk and combine it with the second chunk. import std.algorithm, std.range, std.typecons; import std.stdio; void main(){ auto data=["standard1","standard2","non-standard1","standard3", "non-standard2","non-standard3","standard4"]; static bool isStandard(string s){ return s.startsWith("standard"); } auto chunks=data.chunkBy!isStandard; auto pairs=zip(chunks.save,chunks.dropOne); auto result=pairs.filter!(x=>x[0][0]) .map!(x=>tuple(last(x[0][1]),x[1][1])); result.each!(x=>writeln(x[0],", (",x[1].joiner(", "),")")); } auto last(R)(R r){ // missing from Phobos AFAIK return zip(r.save,r.dropOne.recurrence!"a[n-1].dropOne" .until!(x=>x.empty)) .filter!(x=>x[1].empty).front[0]; } Prints: standard2, (non-standard1) standard3, (non-standard2, non-standard3) Wow, thanks. I have to take a closer look at this to understand the code above. What if I want to include all elements, i.e. "standard1" and "standard4" in the above example? -- /Jacob Carlborg
Re: Bug after update to 2.072?
On Saturday, 5 November 2016 at 21:45:46 UTC, Alex wrote: Hi everybody, something strange is going on: trying compiling and running my code after an update to 2.072, I get a not very instructive segmentation fault (code -11). [...] Could you use DustMite to generate a minimal code sample showing the bug? https://github.com/CyberShadow/DustMite
Re: Error 42 When Trying to Interop with a C# Libary
On Saturday, 5 November 2016 at 20:45:55 UTC, John C wrote: On Saturday, 5 November 2016 at 16:13:18 UTC, Sarcross wrote: If you're wondering, I did use the COFF2OMF tool on the library I got from the C# code, which is why in WordFileParser.d you'll see "pragma(lib, "Parser2")". I have never had success trying to link with a lib file converted by COFF2OMF. Are you able to use -m32mscoff? I was able to call a .NET DLL using the technique in the tutorial when I tried it a few months ago, using that DMD option instead. I added -m32mscoff to dflags in dub.json and it results in this error: LINK : fatal error LNK1104: cannot open file '+C:\Users\antzy_000\Documents\Programming\D\Resume-Parser\src\Parser2.lib' --- errorlevel 1104 dmd failed with exit code 1104. ^^^ Terminated, exit code: 2 ^^^ For reference, my dub.json: { "name" : "resume-parser", "description": "A D resume parser.", "libs" : ["Parser2"], "dflags" : ["-m32mscoff"], "lflags" : ["+C:\\Users\\antzy_000\\Documents\\Programming\\D\\Resume-Parser\\src\\Parser2.lib"], "dependencies" : { } } I attempted changing Parser2.lib to the unconverted Parser.lib but it gives a similar error.
Bug after update to 2.072?
Hi everybody, something strange is going on: trying compiling and running my code after an update to 2.072, I get a not very instructive segmentation fault (code -11). Setted up a debugger in Visual Studio Code, I managed to find out the last accessible code point before the error. And this is inside .../dmd/2.072.0/include/dlang/dmd/core/atomic.d line 657, at the declaration of private HeadUnshared!(T) atomicFetchAdd(T, V1) Indeed, this file was changed, compared to the last version (2.071.2) 1. I'm not sure, how the changes can affect the problem at all... However, as I can see, most of the changes were due to removing @trusted and @safe tags. 2. I'm aware, that the info I provided, is insufficient. But I have some difficulties to set a debugger properly on a mac... so just give me a hint how to get more information about the problem... 3. Compiling with LDC ldc2 --version LDC - the LLVM D compiler (3461e0): based on DMD v2.070.2 and LLVM 3.9.0 built with LDC - the LLVM D compiler (3461e0) Default target: x86_64-apple-darwin16.1.0 Host CPU: haswell does not give the same behavior, as my code runs without any problem Thanks for help :) Alex
Re: Error 42 When Trying to Interop with a C# Libary
On Saturday, 5 November 2016 at 21:02:14 UTC, Adam D. Ruppe wrote: coff2omf works with .obj files Well, that's not what the docs say! http://www.digitalmars.com/ctg/coff2omf.html "The input files can be either object files (.obj) or library files (.lib)" Apparently you have to convert them to an older COFF format first using Microsoft's linker. Not sure if I ever tried that though.
Re: Error 42 When Trying to Interop with a C# Libary
On Saturday, 5 November 2016 at 20:45:55 UTC, John C wrote: I have never had success trying to link with a lib file converted by COFF2OMF. coff2omf works with .obj files coffimplib works on .lib files
Re: Error 42 When Trying to Interop with a C# Libary
On Saturday, 5 November 2016 at 16:13:18 UTC, Sarcross wrote: If you're wondering, I did use the COFF2OMF tool on the library I got from the C# code, which is why in WordFileParser.d you'll see "pragma(lib, "Parser2")". I have never had success trying to link with a lib file converted by COFF2OMF. Are you able to use -m32mscoff? I was able to call a .NET DLL using the technique in the tutorial when I tried it a few months ago, using that DMD option instead.
Re: Map type to class instance at compile-time
On Thursday, 27 October 2016 at 19:16:03 UTC, Ali Çehreli wrote: The problem is with that line. In the previous design, ManagerRegistrationFor would generate a manage() template instance for T and mix it in to the scope. As a result manage(t) would be bound to it the correct template instance. Now, because manager.d does not have that instance here, it needs to refer to it with the full template name: ManagerRegistrationFor!(T, ???).manage(t); would work but we don't have the 'alias mgr' argument to refer to it (hence my question marks). I don't think it's ever possible to fully-qualify a template mixin that has an alias argument. (Yes, it would be possible if the user also had access to the same aliased symbol.) So, I think the problem is with the new design; we need to get rid of that alias parameter and pass the manager object as a runtime parameter. Ali Heck, I should have noticed that the overloads are created in the wrong module. I would like to use alias here, because instantiation via string mixin places arbitrary restrictions on my users' constructors. I hope a better way is possible. Nevertheless, thank you for your help, the examples were very useful for me.
Re: check instance of nested variadic template
On Saturday, 5 November 2016 at 13:43:34 UTC, Lodovico Giaretta wrote: On Saturday, 5 November 2016 at 13:34:51 UTC, Gianni Pisetta wrote: When i have time i will test it with ldc and see if the result is the same, then it will probably be a front-end bug and i will report it as an issue. I think it has already been reported. https://issues.dlang.org/show_bug.cgi?id=13372 Yes. Though the report is more generalized now. It applies to any eponymous type template.
Error 42 When Trying to Interop with a C# Libary
I do apologize if this has been covered before, but I haven't come across anyone with this particular issue. I'm using D for a class project in which we're making a rudimentary resume parser. We're using C# to handle pulling plaintext from .docx files and using D for the rest. The plan was to make a .dll and use the library with D. Unfortunately, after jumping through several hoops to get the linker to recognize the .lib, the compiler keeps giving me Error 42: Symbol Undefined _testLib App.d: https://gist.github.com/Sarcross/035376964b3256e7d48697947c09fbe7 WordFileParser.d: https://gist.github.com/Sarcross/0e124d7e3f6e6cca4efe16c29e53b027 DocumentParser.cs: https://gist.github.com/Sarcross/b508ae839ee543c7a8048fd827baeee5 I've been trying to work with this tutorial I came across: https://github.com/taylorh140/Calling-NET-from-D And the .cs code is based off of this tutorial: https://www.dotnetperls.com/word I have to say, I'm really at a loss. I've tried working on it with the Eclipse DDT plugin, then switched over to using the VisualD plugin for Visual Studio to see if there was something I may have been missing, but no dice. I tried using extern (C++), extern(Windows), and even extern(System) to see if there was any change, but it appears that extern (C) is the proper one to use, however still no luck. If you're wondering, I did use the COFF2OMF tool on the library I got from the C# code, which is why in WordFileParser.d you'll see "pragma(lib, "Parser2")".
Re: check instance of nested variadic template
On Saturday, 5 November 2016 at 14:37:53 UTC, Basile B. wrote: On Saturday, 5 November 2016 at 13:34:51 UTC, Gianni Pisetta wrote: [...] Indeed, I've been fighting against that since a few minutes. We cant select the Base of an eponymous template. template isEponymousTemplate(T) { static if (is(T == class) || is(T == interface) || is(T == struct) || is(T == union)) { enum p = __traits(parent, T).stringof == T.stringof; enum isEponymousTemplate = p && isTemplateInstance!T; } else enum isEponymousTemplate = false; } template TemplateBase(T : Base!Args, alias Base, Args...) if (is(T == class) || is(T == interface) || is(T == struct) || is(T == union)) { alias TemplateBase = Base; } To be more accurate the template base can be selected for template A(T) {class A{}} but not for class A(T){}
Re: check instance of nested variadic template
On Saturday, 5 November 2016 at 13:34:51 UTC, Gianni Pisetta wrote: When i have time i will test it with ldc and see if the result is the same, then it will probably be a front-end bug and i will report it as an issue. Indeed, I've been fighting against that since a few minutes. We cant select the Base of an eponymous template. template isEponymousTemplate(T) { static if (is(T == class) || is(T == interface) || is(T == struct) || is(T == union)) { enum p = __traits(parent, T).stringof == T.stringof; enum isEponymousTemplate = p && isTemplateInstance!T; } else enum isEponymousTemplate = false; } template TemplateBase(T : Base!Args, alias Base, Args...) if (is(T == class) || is(T == interface) || is(T == struct) || is(T == union)) { alias TemplateBase = Base; }
Re: Combining "chunkBy" and "until" algorithms
On 04.11.2016 09:04, Jacob Carlborg wrote: I have a file with a bunch of lines I want to process. I want to process these lines line by line. Most of these lines have the same pattern. Some of the lines have a different pattern. I want to bundle those lines, which have a non-standard pattern, together with the last line that had the standard pattern. The number of lines with a non-standard pattern is unknown. Are there some algorithms in Phobos that can help with this? Maybe an algorithm combining "chunkBy" and "until" could do it? Currently I'm using a standard for loop iterating over the lines. I'm always looking at the current line and the next line. When the current line is the standard pattern and the next line is is not, I do a separate loop until I see a standard pattern again, collecting the lines with the non-standard pattern in an array. "chunkBy" a predicate that checks whether a line is standard. Use 'zip' to focus two adjacent chunks at the same time. Use 'filter' to only consider adjacent chunks where the first chunk consists of standard lines. Then extract the last line of the first chunk and combine it with the second chunk. import std.algorithm, std.range, std.typecons; import std.stdio; void main(){ auto data=["standard1","standard2","non-standard1","standard3", "non-standard2","non-standard3","standard4"]; static bool isStandard(string s){ return s.startsWith("standard"); } auto chunks=data.chunkBy!isStandard; auto pairs=zip(chunks.save,chunks.dropOne); auto result=pairs.filter!(x=>x[0][0]) .map!(x=>tuple(last(x[0][1]),x[1][1])); result.each!(x=>writeln(x[0],", (",x[1].joiner(", "),")")); } auto last(R)(R r){ // missing from Phobos AFAIK return zip(r.save,r.dropOne.recurrence!"a[n-1].dropOne" .until!(x=>x.empty)) .filter!(x=>x[1].empty).front[0]; } Prints: standard2, (non-standard1) standard3, (non-standard2, non-standard3)
Re: check instance of nested variadic template
On Saturday, 5 November 2016 at 13:34:51 UTC, Gianni Pisetta wrote: When i have time i will test it with ldc and see if the result is the same, then it will probably be a front-end bug and i will report it as an issue. I think it has already been reported. https://issues.dlang.org/show_bug.cgi?id=13372
Re: check instance of nested variadic template
When i have time i will test it with ldc and see if the result is the same, then it will probably be a front-end bug and i will report it as an issue.
Re: check instance of nested variadic template
On Friday, 4 November 2016 at 17:37:10 UTC, Basile B. wrote: Hello, I'm not sure that's exactly what you want but check this: template A(As...) { template B(Bs...) { } } alias BI = A!(1,2).B!(3,4,5); import std.traits; template NestedTemplateArgsOf(alias T) { alias NestedTemplateArgsOf = TemplateArgsOf!(__traits(parent, T)); } alias Bs = TemplateArgsOf!BI; alias As = NestedTemplateArgsOf!BI; static if (is(typeof(BI) == typeof(A!As.B!Bs))) { pragma(msg, "for the win"); } The missing key was NestedTemplateArgsOf. With it you can solve the problem. Well, kind of. But i think i can make it with what i got from your example, so thanks. Another thing that I encountered and while messing with your code is that __traits( parent, T ) does not work as expected when you have structs instead of template. I think because something like struct A(As...) {} is downgraded to template A(As...) { struct A {} } when i use __traits( parent, A!(1,2) ) i get in return A!(1,2), looping around the same symbol. When you compile this struct A(As...) {} import std.conv; pragma( msg, "The parent symbol is the same? " ~ to!string( __traits( isSame, A!(1,2), __traits( parent, A!(1,2) ) ) ) ); void main() {} you get a really interesting result: The parent symbol is the same? true Gianni Pisetta
Re: Combining "chunkBy" and "until" algorithms
On 2016-11-04 16:23, Edwin van Leeuwen wrote: Could you filter [1] for the non standard pattern? Filter is lazy, so will only start looking for the next when the current one has been "handled". Hmm, no I don't think so. Do you have an example of how this would work? -- /Jacob Carlborg
Re: check instance of nested variadic template
On Friday, 4 November 2016 at 17:37:10 UTC, Basile B. wrote: On Friday, 4 November 2016 at 15:50:36 UTC, Gianni Pisetta wrote: Hi all, I am having issues finding a solution for this, i want to check if an alias is an istance of a variadic template nested in another variadic template. [...] there is some sort of workaround? Thanks, Gianni Hello, I'm not sure that's exactly what you want but check this: [...] A better generic solution: https://github.com/BBasile/iz/blob/1a6452b376a3a1977c8287f9ef294d2dde76952d/import/iz/types.d#L398
Re: system's "kill " signal
On Saturday, 5 November 2016 at 06:17:51 UTC, Basile B. wrote: On Saturday, 5 November 2016 at 02:24:00 UTC, Konstantin Kutsevalov wrote: Hi, is there a way to catch system signal of "kill" command or "shutdown"? During the Run-time: You can register a signal callback, like in this sample (hit CTRL+C once running in a terminal): import std.stdio; import core.sys.posix.signal; bool doQuit; extern(C) void handler(int num) nothrow @nogc @system { printf("Caught signal %d\n",num); doQuit = true; } void main(string[] args) { signal(SIGINT, ); while(true) { import core.thread; Thread.sleep(dur!"msecs"(50)); if (doQuit) break; } } After termination: == if (tryWait(PID)[0] == true) then the value carried by tryWait(PID)[1] will tell you if the process has exited because of a signal whatever it's, e.g SIGKILL, SIGTERM, SIGINT, ... 3rd option, from my Windows times I remember that people tend to use launchers to handle the real application, i.e a process that launches the main process. Then the launcher can have a thread that checks the PID (like in "After Term..."). If SIGKILL isn't handled by a signal() callback then this could be an option. Do you have to check if a server crashes or something like that ?
Re: system's "kill " signal
On Saturday, 5 November 2016 at 02:24:00 UTC, Konstantin Kutsevalov wrote: Hi, is there a way to catch system signal of "kill" command or "shutdown"? During the Run-time: You can register a signal callback, like in this sample (hit CTRL+C once running in a terminal): import std.stdio; import core.sys.posix.signal; bool doQuit; extern(C) void handler(int num) nothrow @nogc @system { printf("Caught signal %d\n",num); doQuit = true; } void main(string[] args) { signal(SIGINT, ); while(true) { import core.thread; Thread.sleep(dur!"msecs"(50)); if (doQuit) break; } } After termination: == if (tryWait(PID)[0] == true) then the value carried by tryWait(PID)[1] will tell you if the process has exited because of a signal whatever it's, e.g SIGKILL, SIGTERM, SIGINT, ...