Re: setAssertHandler (druntime) segfaults
http://d.puremagic.com/issues/show_bug.cgi?id=3208
Re: D-ObjC error in D2 (was: Re: How to see result of a mixin?)
> Error I'm trying to fix is: > cocoa/foundation/object.d(74): Error: function > cocoa.foundation.object.NSObject.ObjcMethodInfo!(objcForward_isEqual_,byte,"isEqual:",objc_ob > ject*).ObjcSubclassIfNeeded!().ObjcSubclass!().ObjcSubclass!("NSObject"c).objcHardWired > multiple overrides of same function Solved! I've sprinkled the code with pragma(msg,"I'm not dead yet") and it led me to the actual source of problem. Thanks for the tip!
Re: setAssertHandler (druntime) segfaults
On Fri, Jul 24, 2009 at 5:46 PM, Lutger wrote: > Jarrett Billingsley wrote: > >> On Fri, Jul 24, 2009 at 4:37 PM, Lutger >> wrote: >>> There is a function setAssertHandler in druntime, but when I try to use >>> it it segfaults. I'm not sure how it should be used, this is a complete >>> example of what I try to do: >>> >>> import std.stdio; >>> import core.exception; >>> >>> void handleAssertion(string file, size_t line, string msg = null) >>> { >>> writefln("assert in %s at line %s", file, line); >>> }; >>> >>> static this() >>> { >>> setAssertHandler( &handleAssertion ); >>> } >>> >>> unittest { assert(false); } >>> >>> void main() {} >>> >>> >>> output: >>> assert in test at line 16 >>> Segmentation fault >>> >>> This is with dmd 2.031 on linux. Is this a bug, am I doing something >>> wrong? >> >> Hm, it might - and I'm just taking a wild guess here - be that >> std.stdio hasn't yet been initialized when you do the writefln in your >> assertion handler. But you really should try using a debugger to get >> a stacktrace. > > Ok I tried. Funny thing, with -g enabled it doesn't segfault anymore. > Without -g, the trace is not intelligible to me. Segfault also occurs when > commenting out writefln. > > This is useless I assume but anyway, this is what gdb gives me: > > #0 0x0805292e in _TMP257 () > #1 0x000e in ?? () > #2 0xd02c in ?? () > #3 0x08048f79 in _D4test11__unittest1FZv () > Backtrace stopped: previous frame inner to this frame (corrupt stack?) I'm.. utterly at a loss. It seems that exiting the assertion handler by doing anything other than throwing an exception causes the segfault. And like you said, -g makes the problem disappear. I have no idea what's going on.
Re: setAssertHandler (druntime) segfaults
Jarrett Billingsley wrote: > On Fri, Jul 24, 2009 at 4:37 PM, Lutger > wrote: >> There is a function setAssertHandler in druntime, but when I try to use >> it it segfaults. I'm not sure how it should be used, this is a complete >> example of what I try to do: >> >> import std.stdio; >> import core.exception; >> >> void handleAssertion(string file, size_t line, string msg = null) >> { >> writefln("assert in %s at line %s", file, line); >> }; >> >> static this() >> { >> setAssertHandler( &handleAssertion ); >> } >> >> unittest { assert(false); } >> >> void main() {} >> >> >> output: >> assert in test at line 16 >> Segmentation fault >> >> This is with dmd 2.031 on linux. Is this a bug, am I doing something >> wrong? > > Hm, it might - and I'm just taking a wild guess here - be that > std.stdio hasn't yet been initialized when you do the writefln in your > assertion handler. But you really should try using a debugger to get > a stacktrace. Ok I tried. Funny thing, with -g enabled it doesn't segfault anymore. Without -g, the trace is not intelligible to me. Segfault also occurs when commenting out writefln. This is useless I assume but anyway, this is what gdb gives me: #0 0x0805292e in _TMP257 () #1 0x000e in ?? () #2 0xd02c in ?? () #3 0x08048f79 in _D4test11__unittest1FZv () Backtrace stopped: previous frame inner to this frame (corrupt stack?)
D-ObjC error in D2 (was: Re: How to see result of a mixin?)
thanks for quick response! Lutger Wrote: > Not directly except with descent. It's worth it to try descent compile time > debugger (and compile time view!), really awesome stuff. It's indeed pretty nice, but unfortunately it doesn't seem to show mixins: > public void STARTS_HERE() {} > > mixin ObjcMethodInfo!(objcForward_isEqual_, BOOL, "isEqual:", id); > > public void ENDS_HERE(int h) {} is displayed in Descent's Compile-Time view as: > void STARTS_HERE() { > } > > void ENDS_HERE(int h) { > } Error I'm trying to fix is: cocoa/foundation/object.d(74): Error: function cocoa.foundation.object.NSObject.ObjcMethodInfo!(objcForward_isEqual_,byte,"isEqual:",objc_ob ject*).ObjcSubclassIfNeeded!().ObjcSubclass!().ObjcSubclass!("NSObject"c).objcHardWired multiple overrides of same function My guess is that I need to make this mixin to insert override keyword when neccessary, but haven't figured out yet how.
Re: setAssertHandler (druntime) segfaults
On Fri, Jul 24, 2009 at 4:37 PM, Lutger wrote: > There is a function setAssertHandler in druntime, but when I try to use it > it segfaults. I'm not sure how it should be used, this is a complete example > of what I try to do: > > import std.stdio; > import core.exception; > > void handleAssertion(string file, size_t line, string msg = null) > { > writefln("assert in %s at line %s", file, line); > }; > > static this() > { > setAssertHandler( &handleAssertion ); > } > > unittest { assert(false); } > > void main() {} > > > output: > assert in test at line 16 > Segmentation fault > > This is with dmd 2.031 on linux. Is this a bug, am I doing something wrong? Hm, it might - and I'm just taking a wild guess here - be that std.stdio hasn't yet been initialized when you do the writefln in your assertion handler. But you really should try using a debugger to get a stacktrace.
Re: formatting && precision
I just want to format in full precision. As far as I can see 6 digits is not the full precision e.g. 0x7EAB = 1.1342746e38
setAssertHandler (druntime) segfaults
There is a function setAssertHandler in druntime, but when I try to use it it segfaults. I'm not sure how it should be used, this is a complete example of what I try to do: import std.stdio; import core.exception; void handleAssertion(string file, size_t line, string msg = null) { writefln("assert in %s at line %s", file, line); }; static this() { setAssertHandler( &handleAssertion ); } unittest { assert(false); } void main() {} output: assert in test at line 16 Segmentation fault This is with dmd 2.031 on linux. Is this a bug, am I doing something wrong?
Re: How to see result of a mixin? (equivalent of running C preprocessor)
asd wrote: > I'm trying to get D-ObjC bridge working and I'm getting weird errors > triggered somewhere deeply in a mix of templates and mixins that's too > hard for me to understand. > > How can I analyze such problem in D? Is it possible to tell dmd to run > only compile-time functions/templates and output that as a D source? Not directly except with descent. It's worth it to try descent compile time debugger (and compile time view!), really awesome stuff. Other than that, you can use pragma(msg, ...) where you have several options for ... depending on what you want to debug and whether it's D1 or D2. .stringof property and typeof() are useful for this. Take a look at std.traits and for D2 at __traits. Generally the error messages with such code is not so friendly. String mixins can also just be printed with writeln / Stdout.
Re: How to see result of a mixin? (equivalent of running C preprocessor)
Ary Borenszweig wrote: asd wrote: I'm trying to get D-ObjC bridge working and I'm getting weird errors triggered somewhere deeply in a mix of templates and mixins that's too hard for me to understand. How can I analyze such problem in D? Is it possible to tell dmd to run only compile-time functions/templates and output that as a D source? You can debug templates and mixins using Descent: http://dsource.org/project/descent I mean... http://dsource.org/projects/descent
Re: How to see result of a mixin? (equivalent of running C preprocessor)
asd wrote: I'm trying to get D-ObjC bridge working and I'm getting weird errors triggered somewhere deeply in a mix of templates and mixins that's too hard for me to understand. How can I analyze such problem in D? Is it possible to tell dmd to run only compile-time functions/templates and output that as a D source? You can debug templates and mixins using Descent: http://dsource.org/project/descent
How to see result of a mixin? (equivalent of running C preprocessor)
I'm trying to get D-ObjC bridge working and I'm getting weird errors triggered somewhere deeply in a mix of templates and mixins that's too hard for me to understand. How can I analyze such problem in D? Is it possible to tell dmd to run only compile-time functions/templates and output that as a D source?
Re: .patch
BCS Wrote: > Hello Dimitar, > > > Hello I am new to D. > > Hello, welcome. > > > My question is: > > > > How do you apply a .patch file? > > this seems to be somewhat usefull: > > http://docs.moodle.org/en/Development:How_to_apply_a_patch > > windows tools (linux will already have them): > http://gnuwin32.sourceforge.net/packages/patch.htm > > > And then I guess I have to compile the compiler again? > > > > If yes which file do I pass to bud? > > Unless you are primarily interested in compiler development, I'd suggest > you just use DMD as is. (I'm assuming you are referring to patching DMD.) > > I would like to apply patch for 2569.
formatting && precision
Isn't the precision of a float 8 decimal digits? .dig reports 6 Why isn't "%.100g" cropped to the max decimal digits of the accompanying type? floating point types are printed with 20 digits.
C++ auto_ptr equivilant (Reddit)
On the "Reddit: Why no one uses D" post someone seems to be genuinely interested in D's abilities and requested information on equivalents to std::map and std::auto_ptr I've done the best I can to point him in the correct directions. In any case here is the link. http://www.reddit.com/r/programming/comments/93jh5/ask_proggit_the_d_programming_language_looks/c0bd2m1
Re: .patch
Hello Dimitar, Hello I am new to D. Hello, welcome. My question is: How do you apply a .patch file? this seems to be somewhat usefull: http://docs.moodle.org/en/Development:How_to_apply_a_patch windows tools (linux will already have them): http://gnuwin32.sourceforge.net/packages/patch.htm And then I guess I have to compile the compiler again? If yes which file do I pass to bud? Unless you are primarily interested in compiler development, I'd suggest you just use DMD as is. (I'm assuming you are referring to patching DMD.)
Re: Pointer to method C++ style
Fri, 24 Jul 2009 02:51:45 +0400, Sergey Gromov wrote: > Thu, 23 Jul 2009 19:07:43 +0200, BLS wrote: > >> Sergey Gromov wrote: >>> Sorry, I'm not a guru at all, so ActiveX was a misnomer. What I'm >>> writing is a simple in-process server DLL which implements a couple of >>> interfaces. >> >> Oh, that's sad. :( >> >> well, especially in this case I would suggest to have a look on this page : >> http://www.dsource.org/projects/juno/wiki/ComProgramming > > Thanks, I'll look into it when I have time. Juno is nice, and implements a lot of boilerplate. But it doesn't seem to care enough about exceptions in user code. My own code wraps every interface function in an exception catching block, and I'd better leave it that way.
Re: Pointer to method C++ style
Fri, 24 Jul 2009 09:07:30 -0400, Steven Schveighoffer wrote: > On Thu, 23 Jul 2009 22:09:12 -0400, Sergey Gromov > wrote: > >> Thu, 23 Jul 2009 11:54:40 -0400, Steven Schveighoffer wrote: >> >>> LOOKUP_TABLE[0] = Method("method1", &Component.method1); >>> LOOKUP_TABLE[1] = Method("method2", &Component.method2); >> >> These two lines are weird. ``pragma(msg)`` shows that type of >> ``&method1`` is ``void function()`` while it must be ``void delegate()`` >> for a non-static member because of difference in calling convention. >> Actually I think that taking an address of a non-static member in a >> static context must be a compile time error. > > It's because I'm taking the address of the function on the type, not on an > instance. It's not a delegate because there's no "this" pointer yet. > > It makes sense to me anyways. A delegate is a normal function pointer > coupled with a hidden context parameter. The ``Type.`` part does not change anything. It simply directs compiler to use overloads from a particular class hierarchy level. Here: static Method[] LOOKUP_TABLE2 = [ { name : "method1", method : &Component.method1 }, { name : "method2", method : &method2 } ]; This code compiled with DMD 1.046 gives the following errors: test2.d(30): Error: non-constant expression & method1 test2.d(30): Error: non-constant expression & method2 Also if you add this code: pragma(msg, "outside: " ~ typeof(&method1).stringof); void method1() { writefln("method1"); pragma(msg, "inmeth: " ~ typeof(&method1).stringof); } you get: outside: void function() inmeth: void delegate() So the type of a non-static method address taken in a static context is obviously wrong.
.patch
Hello I am new to D. My question is: How do you apply a .patch file? And then I guess I have to compile the compiler again? If yes which file do I pass to bud? Well more than 1 question.
Re: Pointer to method C++ style
On Fri, 24 Jul 2009 09:56:41 -0400, grauzone wrote: LOOKUP_TABLE[0] = Method("method1", &Component.method1); LOOKUP_TABLE[1] = Method("method2", &Component.method2); These two lines are weird. ``pragma(msg)`` shows that type of ``&method1`` is ``void function()`` while it must be ``void delegate()`` for a non-static member because of difference in calling convention. Actually I think that taking an address of a non-static member in a static context must be a compile time error. It's because I'm taking the address of the function on the type, not on an instance. It's not a delegate because there's no "this" pointer yet. It makes sense to me anyways. A delegate is a normal function pointer coupled with a hidden context parameter. But you can't call that function pointer. Actually, you can probably subvert type safety, because functions have a different calling conventions from delegates. This also means that SafeD should disallow taking the address of methods from a type (without instance). That's really silly. A nicer way would be to make &Type.method return a delegate with ptr set to null. Then calling this delegate would result in a (harmless) null pointer exception. But even then, there's no safe way to construct a real delegate out of the method pointer. You can't simply assign an object instance to ptr, because you can't statically know if the funcptr of the delegate really is a method of that object instance. You mean no *compiler verifyable* safe way. Of course there are provably safe ways to do it (my code is one of them). Looks like SafeD proves to be unfeasible again. That's why there are system modules ;) Note that a delegate's ptr method is a pointer, so you can't assign it/use it from SafeD anyways. I'd propose a system module that defines an "unbound delegate" type. This would be a function pointer coupled parameterized with a type, which has an opCall(T, ...) that would call the function properly. I think it can be done, but I'm not enough of a template guru to do it myself. That could be used in SafeD. -Steve
Re: Pointer to method C++ style
LOOKUP_TABLE[0] = Method("method1", &Component.method1); LOOKUP_TABLE[1] = Method("method2", &Component.method2); These two lines are weird. ``pragma(msg)`` shows that type of ``&method1`` is ``void function()`` while it must be ``void delegate()`` for a non-static member because of difference in calling convention. Actually I think that taking an address of a non-static member in a static context must be a compile time error. It's because I'm taking the address of the function on the type, not on an instance. It's not a delegate because there's no "this" pointer yet. It makes sense to me anyways. A delegate is a normal function pointer coupled with a hidden context parameter. But you can't call that function pointer. Actually, you can probably subvert type safety, because functions have a different calling conventions from delegates. This also means that SafeD should disallow taking the address of methods from a type (without instance). That's really silly. A nicer way would be to make &Type.method return a delegate with ptr set to null. Then calling this delegate would result in a (harmless) null pointer exception. But even then, there's no safe way to construct a real delegate out of the method pointer. You can't simply assign an object instance to ptr, because you can't statically know if the funcptr of the delegate really is a method of that object instance. Looks like SafeD proves to be unfeasible again.
Re: Pointer to method C++ style
On Thu, 23 Jul 2009 22:09:12 -0400, Sergey Gromov wrote: Thu, 23 Jul 2009 11:54:40 -0400, Steven Schveighoffer wrote: On Wed, 22 Jul 2009 23:47:30 -0400, Sergey Gromov wrote: Is there a way to declare and statically initialize some sort of pointer to method, and later call it for an actual object instance? I don't know why the "non constant expression error" happens, but constructing a delegate from function pointers is pretty simple: It's my understanding that you cannot construct a delegate from a function pointer because they use different calling conventions. Though you show here that it *is* possible to construct a delegate from another delegate you dissected earlier. LOOKUP_TABLE[0] = Method("method1", &Component.method1); LOOKUP_TABLE[1] = Method("method2", &Component.method2); These two lines are weird. ``pragma(msg)`` shows that type of ``&method1`` is ``void function()`` while it must be ``void delegate()`` for a non-static member because of difference in calling convention. Actually I think that taking an address of a non-static member in a static context must be a compile time error. It's because I'm taking the address of the function on the type, not on an instance. It's not a delegate because there's no "this" pointer yet. It makes sense to me anyways. A delegate is a normal function pointer coupled with a hidden context parameter. I think it should be possible to construct the table statically, since the functions exist statically (without 'this' pointers). Either I can't find the right syntax, or it is a bug. -Steve