Re: UFCS and overloading
On 4/6/15 12:23 PM, Szymon Gatner wrote: Hi, I am surprised that this doesn't work: class Foo { void bar(string) {} } void bar(Foo foo, int i) { } auto foo = new Foo(); foo.bar(123); // === error causing compilation error: main.d(24): Error: function main.Foo.bar (string _param_0) is not callable using argument types (int) does UFCS now work with method overloading? I know it is not a syntax error because changing the name of int version of bar to bar2 and calling foo.bar2(123) works fine. You can't do this. UFCS cannot add overloads, it can only add whole overload sets (if not already present). -Steve
Re: fromStringz problem with gdc
On Monday, 6 April 2015 at 17:47:27 UTC, chardetm wrote: Hello everyone, I have a problem with the fromStringz function (std.string.fromStringz) when I try to compile with the GDC compiler (it works fine with DMD). Here is a minimal code to see the error: import std.stdio, std.string, std.c.stdlib; int main () { char* s; s = cast(char*) malloc(2); s[0] = 'a'; s[1] = '\0'; writeln(fromStringz(s)); return 0; } Compiling with DMD (works fine): $ dmd testfsz.d Compiling with GDC: $ gdc testfsz.d -o testfsz testfsz.d:8: error: undefined identifier fromStringz It does the same thing on a friend's computer. I'm using GCC 4.9.1 on Kubuntu 14.10. Any idea where this comes from? Thanks in advance for your help! fromStringz (in std.string) was introduced in D 2.066, gdc-4.9 was shipped when 2.065 was released. Iain.
Re: UFCS and overloading
On Monday, 6 April 2015 at 17:53:13 UTC, Steven Schveighoffer wrote: On 4/6/15 12:23 PM, Szymon Gatner wrote: Hi, I am surprised that this doesn't work: class Foo { void bar(string) {} } void bar(Foo foo, int i) { } auto foo = new Foo(); foo.bar(123); // === error causing compilation error: main.d(24): Error: function main.Foo.bar (string _param_0) is not callable using argument types (int) does UFCS now work with method overloading? I know it is not a syntax error because changing the name of int version of bar to bar2 and calling foo.bar2(123) works fine. You can't do this. UFCS cannot add overloads, it can only add whole overload sets (if not already present). -Steve Why is that? The use case is to provide a set of convenience extension methods to a basic interface. Say, given: interface Subject { void add(SomeInterface obj); } // and then void add(Subject a, Type1 v1) { a.add(convertToSomeInterface(v1)); } void add(Subject a, Type2 v2) { a.add(convertToSomeInterface(v2)); } this way client can just implement Subject interface and still use it with types Type1 and Type2. C# allows that, why D does not?
Re: fromStringz problem with gdc
On Monday, 6 April 2015 at 17:55:42 UTC, Iain Buclaw wrote: On Monday, 6 April 2015 at 17:47:27 UTC, chardetm wrote: Hello everyone, I have a problem with the fromStringz function (std.string.fromStringz) when I try to compile with the GDC compiler (it works fine with DMD). Here is a minimal code to see the error: import std.stdio, std.string, std.c.stdlib; int main () { char* s; s = cast(char*) malloc(2); s[0] = 'a'; s[1] = '\0'; writeln(fromStringz(s)); return 0; } Compiling with DMD (works fine): $ dmd testfsz.d Compiling with GDC: $ gdc testfsz.d -o testfsz testfsz.d:8: error: undefined identifier fromStringz It does the same thing on a friend's computer. I'm using GCC 4.9.1 on Kubuntu 14.10. Any idea where this comes from? Thanks in advance for your help! fromStringz (in std.string) was introduced in D 2.066, gdc-4.9 was shipped when 2.065 was released. Iain. Thanks! I will make my own version and use conditional compilation to import it or not in that case...
fromStringz problem with gdc
Hello everyone, I have a problem with the fromStringz function (std.string.fromStringz) when I try to compile with the GDC compiler (it works fine with DMD). Here is a minimal code to see the error: import std.stdio, std.string, std.c.stdlib; int main () { char* s; s = cast(char*) malloc(2); s[0] = 'a'; s[1] = '\0'; writeln(fromStringz(s)); return 0; } Compiling with DMD (works fine): $ dmd testfsz.d Compiling with GDC: $ gdc testfsz.d -o testfsz testfsz.d:8: error: undefined identifier fromStringz It does the same thing on a friend's computer. I'm using GCC 4.9.1 on Kubuntu 14.10. Any idea where this comes from? Thanks in advance for your help!
D1 - D2 Code converter
Greetings! Has anyone written any quick program to convert d1 code to d2? I believe it will be a fine piece of program. :-) Thanks. josé
Re: D1 - D2 Code converter
On Monday, 6 April 2015 at 20:25:39 UTC, jicman wrote: Greetings! Has anyone written any quick program to convert d1 code to d2? I believe it will be a fine piece of program. :-) Thanks. josé It is surprisingly difficult, to the point of being almost impossible, to write such program. Problem is there are no simple 1-to-1 replacements for some of D1 concepts (like const storage class or array stomping) and adding const qualifiers automatically would require to effectively implement D1 compiler semantic stage with full code flow analysis. Combined, those 2 issues make creating such program hardly feasible. I will speaker about it in details in my DConf presentation (http://dconf.org/2015/talks/strasuns.html)
Re: How to generate D binding with SWIG?
some time ago I tried it, but without success http://forum.dlang.org/thread/hnlrhschfgumaxzgi...@forum.dlang.org
Static if to compare two types are the exact same
What's the best way to do this? I'm assuming this should be best practice: http://dlang.org/traits.html#isSame struct S { } writeln(__traits(isSame, S, S));
Re: Binary search in structs
I think I found solution using opBinaryRight import std.range; struct S { int i; string s; int opCmp(int i) { return this.i - i; } int opCmp(ref const S s) { return this.i - s.i; } int opBinaryRight(string op)(int i) if (op == ) { return i - this.i; } } void main(string [] args) { S[] structs = [{1,hello}, {2,world}, {3, !}]; //sorted by i auto sortedRange = assumeSorted(structs); auto t = sortedRange.trisect(2); }
Re: Static if to compare two types are the exact same
On Mon, 06 Apr 2015 19:16:33 +, Jonathan wrote: What's the best way to do this? I'm assuming this should be best practice: http://dlang.org/traits.html#isSame struct S { } writeln(__traits(isSame, S, S)); struct S {} auto s0 = S(); auto s1 = S(); static if (is(typeof(s0) == typeof(s1))) { pragma(msg, Woe to the Republic.); } signature.asc Description: PGP signature
D1: Out of memory problems
Greetings. I am using, 15:32:35.63dmd Digital Mars D Compiler v1.046 Copyright (c) 1999-2009 by Digital Mars written by Walter Bright Documentation: http://www.digitalmars.com/d/1.0/index.html And I have a program that reads a file into UTF8 and does a series of string handling to create reports using an Associative Array of Arrays. Then reads another file and does the same thing to each file and creates a report based on word usage, etc. The problem is that the program is not releasing the memory. Imagine this program: //start class TUCount { int[char[]] File; char[][char[]] Target; int Count; } void ConsistencyCheck(char[] dir) { TUCount[char[]] aTUs; char[][] allfiles = std.file.listdir(dir,*.txt); aTUs = GrabUnits(allfiles); PrepareReport(aTUs); } TUCount[char[]] GrabUnits(char[][] allfiles) { TUCount[char[]] aTUs; foreach (char[] f;allfiles) { char[] wText = ; wText = ReadFileData2UTF8(f, bom); //comes from another library and not in this file //--Out of memory is happening in here... while (wText.length 0) { // lots of some text handling and update aTUs base on text } } } void main { char[] dir = rC:\temp\LotsOfTextFiles; ConsistencyCheck(dir); } //end The out of memory is happening in the ReadFileData2UTF function. All that function does is to read the BOM and read the whole file into a variable and returns the UTF8 encoded string. The problem is that apparently, it is reading the files and keeping that data there and never releasing it. The taskmanager just keeps on growing and growing, etc. I know that the aTUs content, which is being used to keep track of words, etc., is really low on memory usage, and it is not the cause of the huge amount of memory shown by the taskmanager. I have 4G on a Win7 x32. Any help would be appreciated. Thanks. josé
Re: UFCS and overloading
On 4/6/15 2:00 PM, Szymon Gatner wrote: On Monday, 6 April 2015 at 17:53:13 UTC, Steven Schveighoffer wrote: On 4/6/15 12:23 PM, Szymon Gatner wrote: Hi, I am surprised that this doesn't work: class Foo { void bar(string) {} } void bar(Foo foo, int i) { } auto foo = new Foo(); foo.bar(123); // === error causing compilation error: main.d(24): Error: function main.Foo.bar (string _param_0) is not callable using argument types (int) does UFCS now work with method overloading? I know it is not a syntax error because changing the name of int version of bar to bar2 and calling foo.bar2(123) works fine. You can't do this. UFCS cannot add overloads, it can only add whole overload sets (if not already present). Why is that? The use case is to provide a set of convenience extension methods to a basic interface. Say, given: interface Subject { void add(SomeInterface obj); } // and then void add(Subject a, Type1 v1) { a.add(convertToSomeInterface(v1)); } void add(Subject a, Type2 v2) { a.add(convertToSomeInterface(v2)); } this way client can just implement Subject interface and still use it with types Type1 and Type2. C# allows that, why D does not? In D, the symbol itself is used to find the appropriate overload set and then the parameters are used within the set to figure out the specific overload to use. Overload sets have different precedence, with I think members having the highest precedent, and likely UFCS having the lowest. But once an overload set is found, anything defined outside that set is not seen. This is done in part to prevent hijacking of functions. For example, if you wanted to change the meaning of some code by defining a better overload match. This doesn't mean it couldn't be changed, but it is definitely implemented as designed. -Steve
Re: Static if to compare two types are the exact same
On 4/6/15, Jonathan via Digitalmars-d-learn digitalmars-d-learn@puremagic.com wrote: What's the best way to do this? I'm assuming this should be best practice: http://dlang.org/traits.html#isSame struct S { } writeln(__traits(isSame, S, S)); I'm not even sure when or why this trait was introduced, but you could use a simple is() expression for this, e.g.: static if (is(T == S)) { ... }
Re: fromStringz problem with gdc
On Monday, 6 April 2015 at 18:31:13 UTC, chardetm wrote: On Monday, 6 April 2015 at 17:55:42 UTC, Iain Buclaw wrote: On Monday, 6 April 2015 at 17:47:27 UTC, chardetm wrote: Hello everyone, I have a problem with the fromStringz function (std.string.fromStringz) when I try to compile with the GDC compiler (it works fine with DMD). Here is a minimal code to see the error: import std.stdio, std.string, std.c.stdlib; int main () { char* s; s = cast(char*) malloc(2); s[0] = 'a'; s[1] = '\0'; writeln(fromStringz(s)); return 0; } Compiling with DMD (works fine): $ dmd testfsz.d Compiling with GDC: $ gdc testfsz.d -o testfsz testfsz.d:8: error: undefined identifier fromStringz It does the same thing on a friend's computer. I'm using GCC 4.9.1 on Kubuntu 14.10. Any idea where this comes from? Thanks in advance for your help! fromStringz (in std.string) was introduced in D 2.066, gdc-4.9 was shipped when 2.065 was released. Iain. Thanks! I will make my own version and use conditional compilation to import it or not in that case... Looks like the function itself is very short: inout(char)[] fromStringz(inout(char)* cString) @system pure { import core.stdc.string : strlen; return cString ? cString[0 .. strlen(cString)] : null; }
Re: Troubles with devisualization/window
On Monday, 6 April 2015 at 22:56:15 UTC, Rikki Cattermole wrote: On 7/04/2015 10:34 a.m., ddos wrote: it's getting warmer, window doesnt freeze anymore and opengl calls don't crash the window, but it's still all white after calling glClearColor(1,0,1,1); glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); updated src: https://github.com/oggs91/OpenVG_D/blob/master/demo_DvisualizationWT/source/app.d Ohhh right, call swapBuffers on the context after drawing. Probably be in the run loop (while). thanks a lot, problems fixed now, i've missing your test example :) if anyone else has problems - this works https://github.com/Devisualization/window/blob/master/test/main.d to get the vector graphics working i had to make a small change in the pixelformatdescriptor https://github.com/Devisualization/window/blob/master/platforms/win32/devisualization/window/context/opengl.d PIXELFORMATDESCRIPTOR, changed stencil buffer bits from 0 to 8 you may want to change this to default 8 to avoid problems. http://imgur.com/ME4b6ZO
getting started with std.csv
Hi. I'm a D newbie(!) coming from a Fortran/C/Python background. I'm struggling with the many new concepts needed in order to make any sense out of the documentation or traceback messages (ranges/templates/...). For example, the std.csv documentation is great but all the examples read from a string rather than a file. I feel stupid but I'm having trouble with the simple step of modifying the examples to read from a file. I can read the whole file into a string in memory and then read the records from the string just fine with csvReader (example A below) or read a line at a time from the file and call csvReader using a single line (example B below), but neither solution is satisfactory. In practice I need to read files with up to 80 million records so I'd like to understand how to do this properly/efficiently. tia, Gerald Example A = import std.stdio, std.file, std.csv; void main() { std.file.write(test.csv, 0,1,abc\n2,3,def); scope(exit) std.file.remove(test.csv); auto lines = readText!(string)(test.csv); struct Rec { int a,b; char[] c; } foreach (Rec r; csvReader!Rec(lines)) { writeln(struct - , r); } } Example B = import std.stdio, std.file, std.csv; void main() { std.file.write(test.csv, 0,1,abc\n2,3,def); scope(exit) std.file.remove(test.csv); struct Rec { int a,b; char[] c; } Rec r; foreach (line; File(test.csv, r).byLine) { r = csvReader!Rec(line).front; writeln(struct - , r); } } Output == struct - Rec(0, 1, abc) struct - Rec(2, 3, def)
Re: Troubles with devisualization/window
On 7/04/2015 10:34 a.m., ddos wrote: it's getting warmer, window doesnt freeze anymore and opengl calls don't crash the window, but it's still all white after calling glClearColor(1,0,1,1); glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); updated src: https://github.com/oggs91/OpenVG_D/blob/master/demo_DvisualizationWT/source/app.d Ohhh right, call swapBuffers on the context after drawing. Probably be in the run loop (while).
Re: Troubles with devisualization/window
it's getting warmer, window doesnt freeze anymore and opengl calls don't crash the window, but it's still all white after calling glClearColor(1,0,1,1); glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); updated src: https://github.com/oggs91/OpenVG_D/blob/master/demo_DvisualizationWT/source/app.d
Re: Troubles with devisualization/window
On 7/04/2015 10:07 a.m., ddos wrote: Hi! i'm trying to get devisualization/window [1] working with some simple opengl calls. I have created a windows with opengl context using Window window = new Window(800, 600, My window!w, WindowContextType.Opengl); If i run writeln(type: , context.type); writeln(toolkit version: , context.toolkitVersion); writeln(shading language version: , context.shadingLanguageVersion); i get correct information has context type: Opengl toolkit version: 4.5.0 NVIDIA 347.09 shading language version: 4.50 NVIDIA First i tried to simply call glClearColor(1,0,0,1);, this crashes the application (Program exited with code -1073741819) I checked the function pointer with if(cast(void*)glClearColor !is null){...} and well ... it's a nullpointer the first two frames. Then i checked for nullpointer and called glClearColor(...) and glClear(...) - no crash but the window was just frozen. Does anyone use Devisualization/window on Windows with success? Fyi, if i dont do any opengl calls the window seems to work, i can close it normally, it's completely white. My example sourcecode can be found here: https://github.com/oggs91/OpenVG_D/blob/master/demo_DvisualizationWT/source/app.d [1] https://github.com/Devisualization/window 1) You need to check that the context has been created window.addOnDraw((Windowable window2) { IContext context = window.context; if (context !is null) { 2) The context needs to be activated bool hitContext; while(true) { import core.thread : Thread; import core.time : dur; Window.messageLoopIteration(); IContext context = window.context; if (window.hasBeenClosed) break; else if (context !is null) { if (!hitContext) { context.activate; // init opengl stuff hitContext = true; } window.onDraw; } Thread.sleep(dur!msecs(25)); } 2 handles 1 already, so you don't need to add 1 only 2.
Troubles with devisualization/window
Hi! i'm trying to get devisualization/window [1] working with some simple opengl calls. I have created a windows with opengl context using Window window = new Window(800, 600, My window!w, WindowContextType.Opengl); If i run writeln(type: , context.type); writeln(toolkit version: , context.toolkitVersion); writeln(shading language version: , context.shadingLanguageVersion); i get correct information has context type: Opengl toolkit version: 4.5.0 NVIDIA 347.09 shading language version: 4.50 NVIDIA First i tried to simply call glClearColor(1,0,0,1);, this crashes the application (Program exited with code -1073741819) I checked the function pointer with if(cast(void*)glClearColor !is null){...} and well ... it's a nullpointer the first two frames. Then i checked for nullpointer and called glClearColor(...) and glClear(...) - no crash but the window was just frozen. Does anyone use Devisualization/window on Windows with success? Fyi, if i dont do any opengl calls the window seems to work, i can close it normally, it's completely white. My example sourcecode can be found here: https://github.com/oggs91/OpenVG_D/blob/master/demo_DvisualizationWT/source/app.d [1] https://github.com/Devisualization/window
Re: Strange behavior std.range.takeNone
On Tuesday, 7 April 2015 at 02:24:00 UTC, Dennis Ritchie wrote: Is it OK? Although, perhaps, everything is fine. I just thought that creates takeNone not string type string, and the string array of type string[]. import std.stdio : writeln; void main() { string s; s ~= 5; writeln(s); // prints ♣ } So I mixed up with this case. Everything is OK. import std.range : takeNone; void main() { auto s = takeNone([test]); // s ~= 5; // Error: cannot append type int to type string[] }
Re: Troubles with devisualization/window
On 7/04/2015 12:10 p.m., ddos wrote: On Monday, 6 April 2015 at 22:56:15 UTC, Rikki Cattermole wrote: On 7/04/2015 10:34 a.m., ddos wrote: it's getting warmer, window doesnt freeze anymore and opengl calls don't crash the window, but it's still all white after calling glClearColor(1,0,1,1); glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); updated src: https://github.com/oggs91/OpenVG_D/blob/master/demo_DvisualizationWT/source/app.d Ohhh right, call swapBuffers on the context after drawing. Probably be in the run loop (while). thanks a lot, problems fixed now, i've missing your test example :) if anyone else has problems - this works https://github.com/Devisualization/window/blob/master/test/main.d to get the vector graphics working i had to make a small change in the pixelformatdescriptor https://github.com/Devisualization/window/blob/master/platforms/win32/devisualization/window/context/opengl.d PIXELFORMATDESCRIPTOR, changed stencil buffer bits from 0 to 8 you may want to change this to default 8 to avoid problems. http://imgur.com/ME4b6ZO Tagged v0.1.1
Re: D1 - D2 Code converter
On Monday, 6 April 2015 at 20:48:05 UTC, Dicebot wrote: On Monday, 6 April 2015 at 20:25:39 UTC, jicman wrote: Greetings! Has anyone written any quick program to convert d1 code to d2? I believe it will be a fine piece of program. :-) Thanks. josé It is surprisingly difficult, to the point of being almost impossible, to write such program. Problem is there are no simple 1-to-1 replacements for some of D1 concepts (like const storage class or array stomping) and adding const qualifiers automatically would require to effectively implement D1 compiler semantic stage with full code flow analysis. Combined, those 2 issues make creating such program hardly feasible. I will speaker about it in details in my DConf presentation (http://dconf.org/2015/talks/strasuns.html) Very interesting. It's like another complete language all by itself. :-) Thanks.
Strange behavior std.range.takeNone
Hi, Is it OK? - import std.stdio : writeln; import std.range : takeNone; void main() { auto s = takeNone(test); s ~= 5; writeln(s); // prints ♣ } - Windows 8.1 x64, DMD 2.067.0
Re: getting started with std.csv
On Tuesday, 7 April 2015 at 05:49:48 UTC, yazd wrote: I got this to work with: ``` import std.stdio, std.file, std.csv, std.range; void main() { std.file.write(test.csv, 0,1,abc\n2,3,def); scope(exit) std.file.remove(test.csv); static struct Rec { int a, b; char[] c; } auto file = File(test.csv, r); foreach (s; csvReader!Rec(file.byLine().joiner(\n))) { writeln(struct - , s); } } ``` I am not sure about using `file.byLine()` here, because `byLine` reuses its buffer, but this is working correctly (for some reason, anyone can comment?) as far as I tested. Btw, joiner is a lazy algorithm. In other words, it doesn't join the whole file when it is called but only when needed. This reduces the memory requirements as you won't need the whole file in memory at once.
Re: getting started with std.csv
I got this to work with: ``` import std.stdio, std.file, std.csv, std.range; void main() { std.file.write(test.csv, 0,1,abc\n2,3,def); scope(exit) std.file.remove(test.csv); static struct Rec { int a, b; char[] c; } auto file = File(test.csv, r); foreach (s; csvReader!Rec(file.byLine().joiner(\n))) { writeln(struct - , s); } } ``` I am not sure about using `file.byLine()` here, because `byLine` reuses its buffer, but this is working correctly (for some reason, anyone can comment?) as far as I tested.
How to generate D binding with SWIG?
I am still trying to get GDAL[1] work with D. I found tool for automatic binding generation it's named SWIG[2]. I looked at gdal binding examples, and look like all of them are automatically generated with SWIG. I am not sure, but possible binding is generation by one few lines, like is binding for C#. makefile.vs: csharp: gdalvars cd csharp $(MAKE) /f makefile.vc interface $(MAKE) /f makefile.vc Could anybody help to help me to do шею I have not enough knowledge to understand what I should to do. If anybody can generate it's for me I would very pleased for it. Because gdal is very needed lib for geoinformaic tasks. [1] http://trac.osgeo.org/gdal/wiki/DownloadSource [2] http://www.swig.org/
Conditional compilation for debug/release
How do conditionally compile code for either release (-release) or debug (-debug)? Something like this: version(Debug) { pragma(lib, libcmtd.lib); } else { pragma(lib, libcmt.lib); } In the documentation [1], I don't see any predefined version identifiers for this purpose. Thanks, Johan [1] http://dlang.org/version.html
vibed - blocking file I/O via library?
So a very basic question about using vibed for a REST service. I am serving data using REST to another application. For the time being it is internal so it is not a disaster if the fiber blocks. But I wanted to understand what I should be doing - the small server app calls library code to retrieve data for a selected series from a large data store (several files, each up to 45G). This library code uses the standard C/posix APIs for file I/O so isn't written with asynchronous access in mind What do I need to do to make sure that if the library code to retrieve the data takes a long time to return that the whole vibed event loop does not block? Should I start a worker task on another thread and wait for it to return? Or will vibed start another thread to serve a new incoming connection if I am still waiting for data in the meantime. Thanks. Laeeth,
Re: Conditional compilation for debug/release
On Monday, 6 April 2015 at 14:50:29 UTC, Johan Engelen wrote: How do conditionally compile code for either release (-release) or debug (-debug)? Something like this: version(Debug) { pragma(lib, libcmtd.lib); } else { pragma(lib, libcmt.lib); } In the documentation [1], I don't see any predefined version identifiers for this purpose. Thanks, Johan [1] http://dlang.org/version.html debug { pragma(lib, libcmtd.lib); } else { pragma(lib, libcmt.lib); }
Re: Conditional compilation for debug/release
On Monday, 6 April 2015 at 15:15:48 UTC, Johan Engelen wrote: On Monday, 6 April 2015 at 14:55:58 UTC, Namespace wrote: debug { pragma(lib, libcmtd.lib); } else { pragma(lib, libcmt.lib); } Thanks for the quick reply! Worth adding an example like that to http://dlang.org/version.html ? It's there already: http://dlang.org/version.html#debug ;)
Re: Conditional compilation for debug/release
On Monday, 6 April 2015 at 15:24:53 UTC, Namespace wrote: On Monday, 6 April 2015 at 15:15:48 UTC, Johan Engelen wrote: On Monday, 6 April 2015 at 14:55:58 UTC, Namespace wrote: debug { pragma(lib, libcmtd.lib); } else { pragma(lib, libcmt.lib); } Thanks for the quick reply! Worth adding an example like that to http://dlang.org/version.html ? It's there already: http://dlang.org/version.html#debug ;) It was not obvious to me that else would work. But reading the whole page again (not just the debug part), I see that indeed the info is already there.
Re: How to generate D binding with SWIG?
Do you even need to use swig? It looks like gdal has a C interface. I think that htod would be what you're looking for http://dlang.org/htod.html
Re: Conditional compilation for debug/release
On Monday, 6 April 2015 at 14:55:58 UTC, Namespace wrote: debug { pragma(lib, libcmtd.lib); } else { pragma(lib, libcmt.lib); } Thanks for the quick reply! Worth adding an example like that to http://dlang.org/version.html ?
Re: Issue with free() for linked list implementation
On 4/3/15 6:08 PM, Kitt wrote: On Friday, 3 April 2015 at 22:06:06 UTC, Namespace wrote: On Friday, 3 April 2015 at 22:02:13 UTC, Kitt wrote: Hello. I’m trying to write my own version of a list that doesn’t rely on the garbage collector. I’m working on a very bare bones implementation using malloc and free, but I’m running into an exception when I attempt to call free. Here is a very minimal code sample to illustrate the issue: // Some constant values we can use static const int two = 2, ten = 10; // Get memory for two new nodes Node* head = cast(Node*)malloc(two.sizeof); Node* node1 = cast(Node*)malloc(ten.sizeof); // Initialize the nodes node1.value = ten; node1.next = null; head.value = two; head.next = node1; // Attempt to free the head node Node* temp = head.next; head.next = null; free(head); // Exception right here head = temp; Note, if I comment out the line ‘head.next = node1’, this code works. Does anyone know what I’m doing wrong with my manual memory management? Why did you allocate only 2 / 10 bytes and not Node.sizeof bytes? Since your Node struct has at least one pointer (nexT) and a value (I assume of type int) you must allocate at least 8 bytes for one Node. I'm sure that is at least one of your problems. Wow, I can't even begin to explain how red my cheeks are right now. You're completely right; I have no idea what my head was thinking. Sure enough, call malloc with the correct type, and the error goes away =P Thanks for the help =) I guess I've been in C# land at work for way too long now, my low level C skills are evaporating! I'm not here to redden your cheeks any further, but I did want to make sure you understood what actually was happening above: 1. you have established 2 integers named 'two' and 'ten'. These are simply integers. 2. When you malloc, you use 'two.sizeof' and 'ten.sizeof'. Integers are 4 bytes, so you were allocating 4 bytes for each of these (not 2 or 10 bytes as is alluded to above). 3. Then you are casting the resulting pointer as pointing at a Node *. I'm assuming, having implemented linked lists many times and seeing your usage of Node, that it has at least a pointer and a value. Best case, this needs at least 8 bytes of space (32-bit CPU), and worst case 16 bytes (64-bit CPU). 4. When you access the Node * flavored pointer to your 4-byte block, you were corrupting memory in any case. Why does the free fail? Probably due to corrupted memory, be careful when using casts and C malloc. -Steve
Re: Issue with free() for linked list implementation
2. When you malloc, you use 'two.sizeof' and 'ten.sizeof'. Integers are 4 bytes, so you were allocating 4 bytes for each of these (not 2 or 10 bytes as is alluded to above). Yeah, my mistake. I saw the mistake but could not describe it correctly. :)
Re: How to generate D binding with SWIG?
On Monday, 6 April 2015 at 15:46:32 UTC, Jeremy DeHaan wrote: Do you even need to use swig? It looks like gdal has a C interface. I think that htod would be what you're looking for http://dlang.org/htod.html +1 for htod if there is a c interface!
UFCS and overloading
Hi, I am surprised that this doesn't work: class Foo { void bar(string) {} } void bar(Foo foo, int i) { } auto foo = new Foo(); foo.bar(123); // === error causing compilation error: main.d(24): Error: function main.Foo.bar (string _param_0) is not callable using argument types (int) does UFCS now work with method overloading? I know it is not a syntax error because changing the name of int version of bar to bar2 and calling foo.bar2(123) works fine.