Re: [OT] Information about "Access to site You requested denied by Federal Law"
23.03.2013 16:59, Michael пишет: Тема есть на Хабрахабре. Дело в Роскомнадзоре или как-то. Блокируют айпи адреса кусками. Прокси в помощь. Сам сайт открывается отлично. Каким макаром Роскомнадзор обидел нерусский блоггер? Причём блога нет в реестре http://zapret-info.gov.ru/ -- Денис В. Шеломовский Denis V. Shelomovskij
[OT] Information about "Access to site You requested denied by Federal Law"
I get this message instead of some sites content: "Access to site You requested denied by Federal Law" E.g. see this IT blog by Felipe Contreras: http://felipec.wordpress.com/ From Google cache: http://webcache.googleusercontent.com/search?hl=ru&newwindow=1&output=search&sclient=psy-ab&q=cache%3Ahttp%3A%2F%2Ffelipec.wordpress.com%2F&oq=cache%3Ahttp%3A%2F%2Ffelipec.wordpress.com%2F&gs_l=hp.3..0l4.198.1430.0.1533.7.7.0.0.0.0.127.356.4j1.5.0...0.2...1c.1.7.psy-ab.YTuLtZgEbrc&pbx=1 It's very strange, but Google keeps silence when searching for this quoted string. Can anyone here give me more information (e.g. block registry with reasons etc.)? -- Денис В. Шеломовский Denis V. Shelomovskij
[OT] Re: How to read fastly files ( I/O operation)
06.02.2013 19:40, bioinfornatics пишет: On Wednesday, 6 February 2013 at 13:20:58 UTC, bioinfornatics wrote: I agree the spec format is really bad but it is heavily used in biology so i would like a fast parser to develop some D application instead to use C++. Yes, lets also create 1 GiB XML files and ask for fast encoding/decoding! The situation can be improved only if: 1. We will find and kill every text format creator; 2. We will create a really good binary format for each such task and support it in every application we create. So after some time text formats will just die because of evolution as everything will support better formats. (the second proposal is a real recommendation) -- Денис В. Шеломовский Denis V. Shelomovskij
Re: Allocating large 2D array in D
04.02.2013 20:54, bearophile пишет: Steven Schveighoffer: Wow, this is something I didn't know was possible. Very useful! It's it cute when you use a language almost daily for few years, and then you see a new way to allocate built-in arrays? :-) Just a small obvious note that this trick will work for every n-dimentional array. And it's not cute when there is a sliceable multidimensional rectangular array implementation for a few years and almost nobody knows about it. http://denis-sh.github.com/phobos-additions/unstd.multidimensionalarray.html From examples: --- // The head array can be dynamic int[4][3][] darr3 = sarr3[]; auto matrix31 = mdimArray(darr3); // Works like previous one --- -- Денис В. Шеломовский Denis V. Shelomovskij
Re: Stupid scope destruction question
20.09.2012 15:35, monarch_dodra пишет: On Thursday, 20 September 2012 at 09:31:45 UTC, Denis Shelomovskij wrote: 20.09.2012 13:27, Denis Shelomovskij пишет: Is there any guaranties that `ScopeTemp` will not be destroyed before `f` call because it isn't used? --- ... f(ScopeTemp(...).value); } --- According to http://dlang.org/struct.html#StructDestructor "Destructors are called when an object goes out of scope." So I understand it as "it will not be destroyed before scope exit even if not used". Is it correct? So the question is if `ScopeTemp`'s scope is `main` scope, not some possibly generated "temp scope" (don't now what documentation statements prohibit compiler from doing so). AFAIK, if the rules are the same in C++ (which they probably are), then: "Any object constructed during argument passing will remain valid for the duration of the call. It will go out of scope once the function has finished returning, and after the return value has itself gone out of scope and been destroyed." Thanks, looks like D does have C++ behaviour here. But your last statement about return value is incorrect. More than that function call doesn't change anything. Correct answers are here: * `12.2 Temporary objects [class.temporary]` section of C++ standard * http://stackoverflow.com/questions/2506793/c-life-span-of-temporary-arguments * http://stackoverflow.com/questions/5459759/full-expression-boundaries-and-lifetime-of-temporaries -- Денис В. Шеломовский Denis V. Shelomovskij
Re: Stupid scope destruction question
20.09.2012 13:27, Denis Shelomovskij пишет: Is there any guaranties that `ScopeTemp` will not be destroyed before `f` call because it isn't used? --- struct ScopeTemp { ... // allocates value this(...) { ... } @property void* value() { ... } // destroys value ~this() { ... } } void f(void* ptr) { ... } void main() { f(ScopeTemp(...).value); } --- According to http://dlang.org/struct.html#StructDestructor "Destructors are called when an object goes out of scope." So I understand it as "it will not be destroyed before scope exit even if not used". Is it correct? So the question is if `ScopeTemp`'s scope is `main` scope, not some possibly generated "temp scope" (don't now what documentation statements prohibit compiler from doing so). Working code: --- import std.exception; import std.c.stdlib; struct ScopeTemp { private int* p; // allocates value this(int i) in { assert(i); } body { *(p = cast(int*) enforce(malloc(int.sizeof))) = i; } @disable this(this); @property int* value() { return p; } // destroys value ~this() { *p = 0; p = null; /*free(p);*/ } } void f(int* ptr) { assert(*ptr == 1); } void main() { f(ScopeTemp(1).value); } --- Wow, this `main` works fine too: --- // same ScopeTemp definition as above int* gptr; void f(int* ptr) { assert(*ptr == 1); gptr = ptr; } void g() { assert(*gptr == 0); } void main() { f(ScopeTemp(1).value); // Here `ScopeTemp` value is already destroyed g(); } --- So `ScopeTemp`'s scope definitely isn't a `main` scope. So the question: what do we know about this "temp scope"? -- Денис В. Шеломовский Denis V. Shelomovskij
Re: auto limitation?
11.09.2012 22:48, Ali Çehreli пишет: return to!(ReturnType!(typeof(&foo)))(42); typeof(return) See http://dlang.org/declaration.html#typeof Anyway don't use it as a type of the first return. You will get: --- Error: cannot use typeof(return) inside function foo with inferred return type --- -- Денис В. Шеломовский Denis V. Shelomovskij
Re: Missing destructor call using clear and base interface ref.
09.08.2012 12:36, Roberto Delfiore пишет: Thank you for your analysis, it's a very strange behavior. I still can not figure out if there is something I don't know or if it's is simply a bug. Good answer: Shouldn't destroy() work on an interface? Filled an issue: http://d.puremagic.com/issues/show_bug.cgi?id=8527 -- Денис В. Шеломовский Denis V. Shelomovskij
Re: What was the reason for not including std.net.curl in the Windows phobos library?
07.07.2012 17:11, Kevin Cox пишет: On Jul 7, 2012 8:45 AM, "Gary Willoughby" mailto:d...@kalekold.net>> wrote: > > What was the reason for not including 'std.net.curl' in the Windows phobos library? IIRC it is licencing issues, they can't include curl in the distribution without certain requirements that were deemed to awkward to implement. No, it was a bug in AutoTester. Se discussion at pull 613: https://github.com/D-Programming-Language/phobos/pull/613 CURL licence permits us from including CURL _binaries_ only so one have to download it manually from "Other Downloads" section of http://dlang.org/download.html -- Денис В. Шеломовский Denis V. Shelomovskij
Re: Garbage Collection Pitfall in C++ but not in D?
06.07.2012 17:43, akaz пишет: Hi, Reading about the C++11, I stumbled upon this: http://www2.research.att.com/~bs/C++0xFAQ.html#gc-abi Specifically (quote): int* p = new int; p+=10; // ... collector may run here ... p-=10; *p = 10;// can we be sure that the int is still there? How does the D garbage collector solves (answers) that? Thank you. If you are interested in D read this first: http://dlang.org/garbage.html You can find there e.g.: > Do not add or subtract an offset to a pointer such that the result points outside of the bounds of the garbage collected object originally allocated. So `p+=10;` is already "undefined behavior". -- Денис В. Шеломовский Denis V. Shelomovskij
Re: Winamp plugin
05.07.2012 18:13, dnewbie пишет: On Thursday, 5 July 2012 at 08:55:33 UTC, Denis Shelomovskij wrote: What's your OS? If Windows XP, than D DLL can't be unloaded because of non-perfect TLS fixing technique (I created a "perfect" one but I never managed to prepare such projects for release so nobody knows about them). And on any Windows Digital Mars C runtime behaves very nasty when it's dynamically loaded. IIRC, it do bad things when loaded in non-main with TLS index != 0 thread and when unloaded (IIRC, again, at least it closes handles). Hi. OS is Windows7-64bit. When I run Winamp in windbg, windbg crashes. The last information I can see is 'Module Unload: C:\WINDOWS\WINSXS\X86_\MSVCR90.DLL' Thanks. I don't think I can add anything to my previous post. Sorry. -- Денис В. Шеломовский Denis V. Shelomovskij
Re: Winamp plugin
05.07.2012 8:37, dnewbie пишет: I'm writing a Winamp plugin in D. Winamp loads my plugin and everything is fine until I close Winamp. At this point, Winamp calls the Quit() function of my plugin and *after* that, Winamp crashes. Here is the code. D source http://dpaste.dzfl.pl/e2b2f886 myplugin.def - .DEF file --- LIBRARY "ml_myplugind.dll" EXETYPE NT SUBSYSTEM WINDOWS EXPORTS winampGetMediaLibraryPlugin --- Compile: dmd myplugin.d myplugin.def -ofml_myplugind.dll -L/IMPLIB Copy ml_myplugind.dll to 'C:\Program Files (x86)\Winamp\Plugins' Restart Winamp and go to Options -> Preferences -> Plugins -> Media Library. You'll see 'My Cool Plugin D' [ml_myplugind.dll]' that means the plugin was loaded. Close Winamp. You'll see a message box 'Quit() from D', from the plugin and MS-Windows displays a error dialog. Click more information and it says APPCRASH module ml_myplugind.dll. I have tried the following C code which does the same thing, and I've got no APPCRASHES http://pastebin.com/7t8jkfn8 I can't see what is wrong. Any help is appreciated. More information about Winamp plugin: http://wiki.winamp.com/wiki/Media_Library_Plugin What's your OS? If Windows XP, than D DLL can't be unloaded because of non-perfect TLS fixing technique (I created a "perfect" one but I never managed to prepare such projects for release so nobody knows about them). And on any Windows Digital Mars C runtime behaves very nasty when it's dynamically loaded. IIRC, it do bad things when loaded in non-main with TLS index != 0 thread and when unloaded (IIRC, again, at least it closes handles). -- Денис В. Шеломовский Denis V. Shelomovskij
Re: Fixed size multidimensional array at runtime
01.07.2012 16:02, Vidar Wahlberg пишет: On Sunday, 1 July 2012 at 09:46:52 UTC, Denis Shelomovskij wrote: I'm curious why do you need such syntax? `matrix[x][y][z]` expression means that `matrix[x]` is also a valid expression but it shouldn't. It's not a syntax I need, it's a syntax I desire as that's the syntax I'm used to for multidimensional arrays. No, that is the syntax you used for arrays of arrays. -- Денис В. Шеломовский Denis V. Shelomovskij
Re: Fixed size multidimensional array at runtime
01.07.2012 0:06, Vidar Wahlberg пишет: On Saturday, 30 June 2012 at 19:35:33 UTC, Denis Shelomovskij wrote: Thanks for the tip, that is interesting (I'm surprised I didn't come across this post when searching for this issue earlier). Although it seems to me that you still end up with "matrix[x, y, z]" instead of "matrix[x][y][z]", so it will only solve one half of the problem :) I'm curious why do you need such syntax? `matrix[x][y][z]` expression means that `matrix[x]` is also a valid expression but it shouldn't. Slicing can be done using something like my implementation: `matrix[x, R[], R[]][y, R[]][z]` where `matrix[x, R[], R[]]` is obviously a valid slice. So I deliberately disallow rule "`matrix[x]` means `matrix[x, R[]...]`" and made `byTopDimension` property for such iteration: `matrix.byTopDimension[x].byTopDimension[y].byTopDimension[z]` See: http://deoma-cmd.ru/d/docs/src/my/rarray.html#byTopDimension -- Денис В. Шеломовский Denis V. Shelomovskij
Re: Fixed size multidimensional array at runtime
30.06.2012 22:21, Vidar Wahlberg пишет: I know multidimensional arrays has been brought up many times, although I was not able to find a clear answer to my question. My knowledge of what's going on behind the curtains is somewhat lacking, please correct me if my assumptions are incorrect. Creating a dynamic multidimensional array can be easily achieved with for example "auto matrix = new int[][](4, 2);", although if I've understood it correct this would create a "jagged" array (as explained on page 112 in TDPL) which may cause efficiency issues due to two indirections as opposed to only one indirection which you would have in a "rectangular" array (as explained at http://dlang.org/arrays.html). If you at compile time know the dimensions of the array you could write "int[2][4] matrix;", and I've understood this as creating a "rectangular" array. In my case I don't know the dimensions at compile time, but I'm still interested in creating a multidimensional array with only one indirection (i.e. allocated contiguously in memory) at runtime, where I'm not going to modify the size of the array. Is this impossible* in D? *I know I could create a one-dimensional array and programmatically convert from multiple dimensions to one dimension, yet this is not as satisfactory as a "true" multidimensional array. Obviously it's the efficiency I worry about, I would much appreciate if someone could shed light upon this. You could be interested in my answer on this thread: http://forum.dlang.org/thread/mailman.1578.1339962782.24740.digitalmars-d-le...@puremagic.com But looks like nobody really need such implementation (nobody asked me to make it up-to-date or put under VCS). -- Денис В. Шеломовский Denis V. Shelomovskij
Re: Simulating rectangular array
17.06.2012 23:50, Andrej Mitrovic пишет: Has anyone come up with a template that can simulate a rectangular array and allow one to override opAssign to do special work? E.g.: Array!(2, 4) arr; arr[1][3] = "foo"; This would invoke opAssign in some templated struct "Array". This would be super-easy to implement if I had an opIndex that could work with the above syntax. I know there's a "[1, 3]" syntax but I really need the array "[1][3]" syntax. Maybe Philippe has this in his templates book? (If not it would be a great addition to it) Full-featured, tested, multidimensional rectangular arrays with slicing support (yes, like in FORTRAN): http://deoma-cmd.ru/d/docs/src/my/rarray.html (may require all files from http://deoma-cmd.ru/d/src/my/) I really thought it's just not needed, but if it is, I will make it up-to-date with current compiler and put under version control. Original thread: http://forum.dlang.org/thread/j864es$2gi0$1...@digitalmars.com -- Денис В. Шеломовский Denis V. Shelomovskij
COM-Interfaces
Here http://dlang.org/interface.html#COM-Interfaces we have a link to Lionello Lunesu's article http://lunesu.com/uploads/ModernCOMProgramminginD.pdf Is it correct that he hasn't managed to convince Microsoft to release his sources and one of us has to rewrite his library if we want to use it? -- Денис В. Шеломовский Denis V. Shelomovskij
Re: DMD can't link opengl32.lib
13.06.2012 17:53, Zhenya пишет: Те которые с DMC идут он проглотит Да. В FAQ есть ссылка на coff2omf, но он проприетарный. Может помочь coffimplib: http://www.digitalmars.com/ctg/coffimplib.html ftp://ftp.digitalmars.com/coffimplib.zip -- Денис В. Шеломовский Denis V. Shelomovskij
Re: DMD can't link opengl32.lib
13.06.2012 17:03, Zhenya пишет: When I wanted to use native opengl binding ... DMD wrote:opengl32.lib Error 43: Not a Valid Library File But why can't dmd link it? http://dlang.org/faq.html#omf -- Денис В. Шеломовский Denis V. Shelomovskij
Re: druntime investigation troubles
23.05.2012 10:21, Jacob Carlborg написал: On 2012-05-22 23:01, Steven Schveighoffer wrote: It looks like code that is not called on Windows. Which doesn't make sense. It would seem that you must initialize a critical section in order to use it. I can't find any reference to STI_monitor in dmd, dmc, or druntime source code, except those calls that are done for Posix only. This isn't some closed-source mystery, I think it is just unused code. Sean, does this make sense? Are we using uninitialized critical sections? -Steve I found a call now, it's in "_d_criticalenter", both in critical.c and critical_.d. What call have you found in "_d_criticalenter"? By the way, `_STI_critical_init` is called before C main (uncomment printf's and check), so it is definitely called not by druntime. -- Денис В. Шеломовский Denis V. Shelomovskij
Re: druntime investigation troubles
21.05.2012 2:13, Alex Rønne Petersen написал: On 20-05-2012 22:13, Jacob Carlborg wrote: On 2012-05-20 18:25, Alex Rønne Petersen wrote: Seems like I misunderstood what you were saying. Right, the C runtime on *Windows* is closed source. But, I don't know why you think that function is called by the C runtime; see src/rt/dmain2.d. Have a look again. It's only called on Posix: https://github.com/D-Programming-Language/druntime/blob/7d663821d39cfe8874cb95b0df46b5065a770cef/src/rt/dmain2.d#L364 I stand corrected. I had no idea about the magic involved here! The proprietary Windows tool chain is seriously problematic... So can anybody do something with it? At least document a bit what does proprietary part do. -- Денис В. Шеломовский Denis V. Shelomovskij
druntime investigation troubles
Looks like `_STI_monitor_staticctor` is called by C runtime on Windows. And C runtime isn't open-source. It creates troubles for investigation druntime (for me at least). Why is it so? Why not to call everything in C `main`, what's the reason? If there is no list of stuff done before C `main` druntime isn't open-source for me because I can't understand what is taking place just with druntime sources. -- Денис В. Шеломовский Denis V. Shelomovskij
Re: Derelict2 openGL3 issues
One day I'll finish my OpenGL wrapper for D. It will give you better abilities in creating OpenGL 3 contexts than most C++ frameworks (SDL, GLFW etc.) and, I hope, will get rid of passing pointers to functions. It will be done soon after I'll finish Scintilla wrapper for D. And it will be done soon after I'll conquer the world (or a bit earlier). Dreams, dreams... P.S. OpenGL context creating has been done a long time ago but then I decided to create full wrapper to supersede Derelict's one and it still not finished because that I decided to create general wrapping back-end. And I've done it (CWrap), but than I decided to create Scintilla wrapper... P.P.S. Sorry for the flood... -- Денис В. Шеломовский Denis V. Shelomovskij
Re: A "general" tag
15.04.2012 0:31, Xan написал: On Saturday, 14 April 2012 at 19:40:06 UTC, Aleksandar Ružičić wrote: On Saturday, 14 April 2012 at 19:17:52 UTC, Xan wrote: Hi, I try to translate a script I wrote in Fantom [www.fantom.org]. In my script, I have a type "Tag" defined as a triple of: - String (the name of the tag), - Type (the type of the tag: could be Str, Date, Int, etc.) - Obj (the value of the tag; Fantom has Objects of Top-Class hierachy). (normally the tag has Type = Obj.Type, but you can manually set). For example, you could have: (name, Str#, "John") or (date, Date#, 2011-09-02) (# is the Fantom way for specifying type: Str# is the sys::Str type) Is there any way for emulating this? My main trouble is how to define Type and Object in D. Thanks in advance, Xan. PS: Please, be patient, I'm a newbee. For "Type" look at enum (http://dlang.org/enum.html) and for "Object" look at std.variant (http://dlang.org/phobos/std_variant.html). And since Variant can tell you what type it contains you might no longer need that "Type" parameter. I think it's not what I expect. Can I have a generic object type? Something like an assigment like: Any a ? With templates? Please, guide me. I'm a newbee What you are looking for is a boxing. http://en.wikipedia.org/wiki/Boxing_(computer_science)#Boxing D doesn't support auto boxing/unboxing. For a reason see, e.g. this thread: http://forum.dlang.org/thread/ckoaum$1lbg$1...@digitaldaemon.com http://forum.dlang.org/thread/cr7njl$18j3$1...@digitaldaemon.com There was std.boxer module, but it was deprecated and removed, this is the last version before removal: https://github.com/D-Programming-Language/phobos/blob/c20d454d63861a0c4bab647b37c01b0dd981a3f8/std/boxer.d std.variant is really what you are looking for. See example: --- import std.stdio; import std.variant; import std.string: format; struct Tag { string name; Variant entity; } class C { int i; this(int i) { this.i = i; } string toString() { return format("C(i: %s)", i); } } struct SmallStruct { int a; } struct Huge { real a, b, c, d, e, f, g; } void writeTag(Tag tag) { writeln(tag); with(tag.entity) if(auto intVal = peek!int()) { writeln(" Contains int: ", *intVal); // Arithmetic is supported too writeln(" + 3: ", tag.entity + 3); writeln(" * 2: ", tag.entity * 2); } else if(auto hugeVal = peek!Huge()) // Don't use *hugeVal for now, there is a bug in peek writeln(" Contains Huge struct: ", tag.entity.get!Huge()); else if(auto classInfo = cast(TypeInfo_Class)type) writefln(" Contains class %s: %s", classInfo.name, get!Object()); else if(auto structInfo = cast(TypeInfo_Struct)type) writefln(" Contains struct %s: %s", structInfo.name, tag.entity); // else if etc. } void main() { writeTag(Tag("tag1", Variant(12))); writeTag(Tag("tag2", Variant("str"))); writeTag(Tag("tag3", Variant(["str1", "str2"]))); writeTag(Tag("tag4", Variant(new C(17; writeTag(Tag("tag4", Variant(SmallStruct(3; // Variant isn't enough to hold Huge so a copy // will be accocated in GC heap. // Yes, this isn't documented yet and `peek` will give you garbage // for this case because of a bug. writeTag(Tag("tag4", Variant(Huge(1.1, 2.2, 3.3, 4.4, 5.5, 6.6, 7.7; } --- std.variant has some bugs for now but is usable: http://d.puremagic.com/issues/buglist.cgi?query_format=advanced&short_desc=variant&bug_status=NEW&bug_status=ASSIGNED&bug_status=REOPENED&short_desc_type=allwords Templates are usable in other cases, not this. -- Денис В. Шеломовский Denis V. Shelomovskij
Re: [Inline assembler] Sequential `asm` blocks and return via EAX
08.03.2012 14:00, Alex Rønne Petersen пишет: On 08-03-2012 10:42, Denis Shelomovskij wrote: 1. Is there any guaranties that no code will be added between sequential inline assembler blocks, e.g.: --- void f() { static if(x) asm { mov EBX, 3; } else asm { mov EBX, 7; } asm { mov EAX, EBX; } // Is EBX value defined here? } I don't think you can rely on this. --- Is it documented? Probably not. 2. Such question about return via EAX (is the following use legal/documented): --- int g() { asm { mov EAX, 4; } } --- Such use of `asm` to return a value is used here and there in http://dlang.org/iasm.html As long as you follow whatever ABI your function uses (cdecl, stdcall, the D ABI, whatever), I don't see anything wrong with this. All given answers looks like: --- int g() { asm { mov EAX, 4; } } --- will work and --- int g() { asm { mov EAX, 4; } asm { } } --- will not. I'm pretty sure returning value is like relying on saving registers between sequential inline assembler blocks and even worse because "end of function" is and action and there are no actions between sequential inline assembler blocks.
[Inline assembler] Sequential `asm` blocks and return via EAX
1. Is there any guaranties that no code will be added between sequential inline assembler blocks, e.g.: --- void f() { static if(x) asm { mov EBX, 3; } else asm { mov EBX, 7; } asm { mov EAX, EBX; } // Is EBX value defined here? } --- Is it documented? 2. Such question about return via EAX (is the following use legal/documented): --- int g() { asm { mov EAX, 4; } } --- Such use of `asm` to return a value is used here and there in http://dlang.org/iasm.html
Re: temp file
18.02.2012 6:59, bioinfornatics пишет: hi, when i try to use tmpfile from std.stdio i get this error char 0x00ad not allowed in identifier I use dmdfe 2.058, i do just: File tmp = tmpfile(); Full source, please. And you should use `File.tmpfile()` instead of `tmpfile()` (unless you are already in `with(File)`?). This compiles: --- import std.stdio; void main() { with(File) File tmp = tmpfile(); } --- Anyway, 0x00ad is 'SOFT HYPHEN' (not a '_' char) and is valid but ignorable in a Java identifier. Looks like your editor added it. http://www.fileformat.info/info/unicode/char/ad/index.htm By the way, you just inspired me to fill this: http://d.puremagic.com/issues/show_bug.cgi?id=7537
Re: A GUI library to begin with
08.02.2012 7:55, Mr. Anonymous пишет: Why does GTK suck (I read that a couple of times). GtkD (+OpenGL) worked stable in my rather big D1+Tango project 2 years ago (and do it now). Looks like it has lots of memory leaks (in almost every function call) but it didn't lead to crash after few hours of program work (but my program have no big text buffers).
Strict aliasing in D
Is there a strict aliasing rule in D? I just saw https://bitbucket.org/goshawk/gdc/changeset/b44331053062
Re: do-while loops
28.12.2011 16:29, bearophile пишет: One thing that I often find not handy in the design of do-while loops: the scope of their body ends before the "while": void main() { do { int x = 5; } while (x != 5); // Error: undefined identifier x } So I can't define inside them variables that I test in the while(). This keeps the scope clean, but it's not nice looking: void main() { { int x; do { x = 5; } while (x != 5); } } Bye, bearophile +1 I faced it a few days ago too. An enhancement request should be filled. Even if it will be resolved as WONTFIX, at least we will know a reason.
Re: Reading about D: few questions
25.12.2011 0:48, Mr. Anonymous пишет: Actually, when I think of it: int a_orig = a++; int[] arr_orig = arr[]++; Should be read as: int a_orig = a; ++a; int[] arr_orig = arr[]; ++arr[]; (If I'm not mistaken, it was written in the TDPL book) Which means no copy of arr is made, and both arrays (which reference to the same block) are affected. OK. As I wrote: "Yes, this allocation sometimes can be optimized out but not always.". Consider this: --- void main() { int[] a = new int[5]; void f(int[] b) { // Here we assume that b is unchanged a. // As these array differ we need a copy. assert(b[0] == 0); assert(a[0] == 1); } f(a[]++); // Note: compilation error now } --- Why not to rewrite `f(a[]++);` as `f(a); ++a[];`? Because postincrement is expected to increment its argument when it is executed. It just returns an unchanged copy. Analogous D code with integers illustrates this: --- void main() { int a; void f(int b) { assert(b == 0); assert(a == 1); } f(a++); } ---
Re: Reading about D: few questions
23.12.2011 22:51, bearophile пишет: ++a[] works, but a[]++ doesn't. Already known compiler bug. Is it a joke? Array expression in D are for performance reasons to generate x2-x100 faster code without any compiler optimisations. Link to one of these epic comments (even x100 more epic because of '%' use instead of 'x###'): https://github.com/D-Programming-Language/druntime/blob/master/src/rt/arraybyte.d#L1127 But `a[]++` should store a copy of `a`, increment elements and return stored copy. It is hidden GC allocation. We already have a silent allocation in closures, but here a _really large_ peace of data can be allocated. Yes, this allocation sometimes can be optimized out but not always. IMHO, D should not have `a[]++` operator.
Re: About File.rawWrite
29.11.2011 15:57, bearophile пишет: This D2 program runs in about 5.13 seconds on my PC: import std.stdio; void main() { auto f = File("bytes_test.dat", "wb"); ubyte[3] RGB; foreach (_; 0 .. 1_000_000) f.rawWrite(RGB); } While this C program runs in about 0.14 seconds: #include int main() { FILE *f = fopen("bytes_test.dat", "wb"); unsigned char RGB[3] = {0}; int i; for (i = 0; i< 100; i++) fwrite(RGB, 1, 3, f); return 0; } Is my D2 program wrong, or is File.rawWrite in need of some improvements? (Writing 3 bytes at a time is not efficient, but the C code shows that the runtime is acceptable for me for small files). Bye, bearophile Your OS is Windows, right? On Windows, rawWrite and rawRead always flushes stream, sets binary mode, reads/writes, flushes stream again, sets previous mode. This is definitely unnecessary slow - at least it should change mode only if needed (the file is opened in a text mode). The better solution is to change all other functions so the file mode will be changed lazily (for a text file, raw* functions will change file mode and leave file in this mode until a call of a function, that really needs a file to be in a text mode). By the way, why this changing mode behaviour is Windows only? Yes, it is clearly documented that this is the case, but it isn't documented _why_ this is the case. Quick link to the current rawRead implementation (for happy owners of Google's Chrome, the fastest beautiful web browser that can BSOD your Windows even without administrator rights) (the link isn't for Firefox: it will slow down the browser and be displayed incorrectly): https://github.com/D-Programming-Language/phobos/blob/master/std/stdio.d#L458
Re: Can't free memory on exiting?
01.11.2011 10:27, breezes пишет: Thanks Andrej. That bug says that you can not alloc memory during GC. However i don't alloc but free memory in ~this. But anyway, as you said, I should use malloc/free in core.stdc.stdlib to manage memory manually. I modified the code to use that malloc/free, and it works without crashing. However, the following little bit more complex test got a Bus error. import core.stdc.stdlib; class Allocator { void* alloc(size_t size) { return malloc(size); } void free(void *block) { core.stdc.stdlib.free(block); } } class Pages { this(Allocator allocator) { _allocator = allocator; void *p = _allocator.alloc(1000); _pages ~= p; } ~this() { _allocator.free(_pages[0]);// Bus error there } Allocator _allocator; void*[] _pages; size_t _a; size_t _b; size_t _c; size_t _d; size_t _e; size_t _f; } void main() { auto a = new Allocator(); auto pg = new Pages(a); } I got the following bus error: Bus error: 10 What's the problem? Does it mean that I can not access _allocator during the deconstruction of pg? And the most mythical thing is that if I comment out the declaration of _a to _f of Pages, then the bus error will go. (I use the most recent dmd 2.0.056.) From http://d-programming-language.org/class.html#destructors (this page is a bit broken now): "The garbage collector is not guaranteed to run the destructor for all unreferenced objects. Furthermore, the order in which the garbage collector calls destructors for unreference objects is not specified. This means that *when the garbage collector calls a destructor for an object of a class that has members that are references to garbage collected objects, those references may no longer be valid*. This means that *destructors cannot reference sub objects*. This rule does not apply to auto objects or objects deleted with the DeleteExpression, as the destructor is not being run by the garbage collector, meaning all references are valid." Make your `free` function static to avoid problem that it needs `this` pointer (of course it may work with damaged `this` but it isn't guaranteed). And your pages array should be allocated with `malloc` too (`~=` allocates in GC heap of course).
Re: Calling D code from C
20.09.2011 9:55, Jonathan M Davis пишет: Someone who has actually done a C or C++ application or two which used D code should answer this question. I know that there are at least a few folks around here who have done that, but I've never done it myself. http://stackoverflow.com/questions/7480046/implementing-a-c-api-in-d Is smb. reading my mind? Just a few hours ago I had the same question. So, I have written an answer at stackoverflow.com. It isn't about _shared libraries_, but about calling D from C with static linking.