changeset 105:7abaf5c3959f

Merge
author David Bryant <bagnose@gmail.com>
date Sun, 20 Feb 2011 22:27:06 +1030
parents ab745d8b10e5 (diff) 345fb56d89fc (current diff)
children 5677ba065636 3005ec1ba0e2
files doodle/core/backtrace.d doodle/core/logging.d doodle/dia/icanvas.d doodle/tk/events.d nobuild/dot-hgrc
diffstat 7 files changed, 271 insertions(+), 48 deletions(-) [+]
line wrap: on
line diff
--- a/doodle/core/backtrace.d	Thu Nov 18 12:00:02 2010 +1030
+++ b/doodle/core/backtrace.d	Sun Feb 20 22:27:06 2011 +1030
@@ -1,15 +1,28 @@
 module doodle.core.backtrace;
 
 //
-// Register signal handlers and throw Error.
-// Technically we shouldn't be throwing an exception from
-// a signal handler, but it happens to work.
+// Provides support for a readable backtrace on a program crash.
+//
+// Everything is private - you build this into a library and
+// link to the library, and bingo (via static this).
+//
+// It works by registering a stacktrace handler with the runtime,
+// which, unlike the default one, provides demangled symbols
+// rather than just a list of addresses.
 //
 
 private {
+
     import core.stdc.signal;
+    import core.stdc.stdlib : free;
+    import core.stdc.string : strlen;
+    import core.runtime;
+    import std.demangle;
     import std.string;
 
+    extern (C) int    backtrace(void**, size_t);
+    extern (C) char** backtrace_symbols(void**, int);
+
     // signal handler for otherwise-fatal thread-specific signals 
     extern (C) void signalHandler(int sig) {
         string name() {
@@ -32,6 +45,69 @@
         signal(SIGFPE,  &signalHandler);
         signal(SIGILL,  &signalHandler);
         signal(SIGSEGV, &signalHandler);
-        signal(SIGINT,  &signalHandler);
+        signal(SIGINT, &signalHandler);
+    }
+
+    static this() {
+        // register our trace handler for each thread
+        Runtime.traceHandler = &traceHandler;
+    }
+
+    Throwable.TraceInfo traceHandler(void * ptr = null) {
+        return new TraceInfo;
+    }
+
+    class TraceInfo : Throwable.TraceInfo {
+        this() {
+            immutable MAXFRAMES = 128;
+            void*[MAXFRAMES] callstack;
+
+            numframes = backtrace(callstack.ptr, MAXFRAMES);
+            framelist = backtrace_symbols(callstack.ptr, numframes);
+        }
+
+        ~this() {
+            free(framelist);
+        }
+
+        override string toString() const { return null; }   // Why does toString require overriding?
+
+        override int opApply( scope int delegate(ref char[]) dg) {
+            return opApply( (ref size_t, ref char[] buf)
+                           {
+                           return dg( buf );
+                           } );
+        }
+
+
+        override int opApply(scope int delegate(ref size_t, ref char[]) dg) {
+            // NOTE: The first 5 frames with the current implementation are
+            //       inside core.runtime and the object code, so eliminate
+            //       these for readability.
+            immutable FIRSTFRAME = 5;
+            int ret = 0;
+
+            for(int i = FIRSTFRAME; i < numframes; ++i) {
+                size_t pos = i - FIRSTFRAME;
+                char[] text = framelist[i][0 .. strlen(framelist[i])];
+
+                auto a = text.lastIndexOf('(');
+                auto b = text.lastIndexOf('+');
+
+                if (a != -1 && b != -1) {
+                    ++a;
+                    text = format("%s%s%s", text[0..a], demangle(text[a..b].idup), text[b..$]).dup;
+                }
+
+                ret = dg(pos, text);
+                if (ret)
+                    break;
+            }
+            return ret;
+        }
+
+    private:
+        int    numframes; 
+        char** framelist;
     }
 }
--- a/doodle/core/logging.d	Thu Nov 18 12:00:02 2010 +1030
+++ b/doodle/core/logging.d	Sun Feb 20 22:27:06 2011 +1030
@@ -2,6 +2,7 @@
 
 private {
     import std.stdio;
+    import std.typecons;
     import std.traits;
 }
 
@@ -51,7 +52,14 @@
 }
 
 private {
-    enum Severity { TRACE, INFO, MESSAGE, WARNING, ERROR, FATAL }
+    enum Severity {
+        TRACE,
+        INFO,
+        MESSAGE,
+        WARNING,
+        ERROR,
+        FATAL
+    };
 
     string severityString(in Severity s) {
         switch (s) {
@@ -103,7 +111,7 @@
     string bgColorString(in Color c)     { return std.string.format("\033[%dm", 40 + c); }
 
     private string right(in string str, in int n) {
-        int pos = str.length < n ? 0 : str.length - n;
+        auto pos = str.length < n ? 0 : str.length - n;
         return str[pos..$];
     }
 }
--- a/doodle/core/undo.d	Thu Nov 18 12:00:02 2010 +1030
+++ b/doodle/core/undo.d	Sun Feb 20 22:27:06 2011 +1030
@@ -1,7 +1,7 @@
 module doodle.core.undo;
 
 import std.array;
-import std.date;
+import std.datetime;
 
 // An abstract framework for undo/redo.
 // Assume the application works on one document at a time,
@@ -31,22 +31,22 @@
 abstract class Edit {
     private {
         string _description;
-        d_time _timeStamp;
+        SysTime _timeStamp;
     }
 
     this(in string description) {
         _description = description;
-        _timeStamp = getUTCtime;
+        _timeStamp = Clock.currTime;
     }
 
-    this(in string description, d_time timeStamp) {
+    this(in string description, SysTime timeStamp) {
         assert(description);
         _description = description;
         _timeStamp = timeStamp;
     }
 
     string description() const { return _description; }
-    d_time timeStamp() const { return _timeStamp; }
+    const(SysTime) timeStamp() const { return _timeStamp; }
 
     final bool merge(Edit subsequent) {
         if (mergeImpl(subsequent)) {
--- a/doodle/dia/icanvas.d	Thu Nov 18 12:00:02 2010 +1030
+++ b/doodle/dia/icanvas.d	Sun Feb 20 22:27:06 2011 +1030
@@ -7,7 +7,16 @@
     import doodle.tk.screen_model;
 }
 
-enum Cursor { DEFAULT, HAND, CROSSHAIR, PENCIL }
+private {
+    import std.typecons;
+}
+
+enum Cursor {
+    DEFAULT,
+    HAND,
+    CROSSHAIR,
+    PENCIL
+}
 
 interface IViewport2 {
     void damageModel(in Rectangle area);
--- a/doodle/tk/events.d	Thu Nov 18 12:00:02 2010 +1030
+++ b/doodle/tk/events.d	Sun Feb 20 22:27:06 2011 +1030
@@ -10,13 +10,51 @@
     import std.conv;
 }
 
-enum ButtonAction { SINGLE_PRESS, DOUBLE_PRESS, TRIPLE_PRESS, RELEASE }
-enum ButtonName { LEFT, MIDDLE, RIGHT, FOUR, FIVE }
-enum ScrollDirection { UP, DOWN, LEFT, RIGHT }
-enum Modifier { SHIFT, CAPS_LOCK, CONTROL, ALT, NUM_LOCK, META, SCROLL_LOCK, LEFT_BUTTON, MIDDLE_BUTTON, RIGHT_BUTTON, UNUSED_BUTTON_1, UNUSED_BUTTON_2 }
+enum ButtonAction {
+    SINGLE_PRESS,
+    DOUBLE_PRESS,
+    TRIPLE_PRESS,
+    RELEASE
+}
+
+enum ButtonName {
+    LEFT,
+    MIDDLE,
+    RIGHT,
+    FOUR,
+    FIVE
+}
+
+enum ScrollDirection {
+    UP,
+    DOWN,
+    LEFT,
+    RIGHT
+}
 
-// FIXME what to do about GRAB2/UNGRAB2
-enum CrossingMode { NORMAL, GRAB, UNGRAB, GRAB2, UNGRAB2, STATE_CHANGED }
+enum Modifier {
+    SHIFT,
+    CAPS_LOCK,
+    CONTROL,
+    ALT,
+    NUM_LOCK,
+    META,
+    SCROLL_LOCK,
+    LEFT_BUTTON,
+    MIDDLE_BUTTON,
+    RIGHT_BUTTON,
+    UNUSED_BUTTON_1,
+    UNUSED_BUTTON_2
+}
+
+enum CrossingMode {           // FIXME what to do about GRAB2/UNGRAB2
+    NORMAL,
+    GRAB,
+    UNGRAB,
+    GRAB2,
+    UNGRAB2,
+    STATE_CHANGED
+}
 
 struct Mask {
     this(in Modifier[] modifiers) {
@@ -76,8 +114,7 @@
     uint value() const { return _value; }
 
     override string toString() const {
-        return std.string.format("Key event: %s, %d, %s",
-                                 _str, _value, _mask);
+        return std.string.format("Key event: %s, %d, %s", _str, _value, _mask);
     }
 
     private {
@@ -114,8 +151,7 @@
     CrossingMode crossingMode() const { return _crossingMode; }
 
     override string toString() const {
-        return std.string.format("Crossing event: %s, %s, %s, %s",
-                                 to!string(_crossingMode), screenPoint, modelPoint, mask);
+        return std.string.format("Crossing event: %s, %s, %s, %s", to!string(_crossingMode), screenPoint, modelPoint, mask);
     }
 
     private {
@@ -136,7 +172,8 @@
 
     override string toString() const {
         return std.string.format("Button event: %s, %s, %s, %s, %s",
-                                 to!string(_buttonAction), to!string(_buttonName), _screenPoint, _modelPoint, _mask);
+                                 to!string(_buttonAction), to!string(_buttonName),
+                                 _screenPoint, _modelPoint, _mask);
     }
 
     ButtonAction buttonAction() const { return _buttonAction; }
--- a/nobuild/dot-hgrc	Thu Nov 18 12:00:02 2010 +1030
+++ b/nobuild/dot-hgrc	Sun Feb 20 22:27:06 2011 +1030
@@ -1,3 +1,6 @@
+# --- Sample .hgrc file. Customize and drop as ~/.hgrc --- #
+
+# --- Mercurial's internal format --- #
 [revlog]
 # format = 0 for revlog; format = 1 for revlogng
 format = 1
@@ -6,13 +9,90 @@
 # revlogng needs flags = inline
 flags = inline
 
+[diff]
+ignorews = True
+
+# --- User interface --- #
 [ui]
 # show changed files and be a bit more verbose if True
 verbose = True
+# username data to appear in comits
+# it usually takes the form: "Joe User <joe.user at host.com>"
 username = David Bryant <bagnose@gmail.com>
 
-[diff]
-ignorews=True
-
+# --- Active Extensions --- #
+# each extension has its own 'extension_name = path' line
+# the default python library path is used when path is left blank
+# the hgext dir is used when 'hgext.extension_name = ' is written
 [extensions]
 hgk =
+# acl - Access control lists
+# hg help acl
+# hgext.acl =
+# ---
+# bisect - binary search changesets to detect (mis)features
+# hg help bisect
+# hgext.hbisect =
+# ---
+# bugzilla - update bugzilla bugs when changesets mention them
+# hg help bugzilla
+# hgext.bugzilla =
+# ---
+# extdiff - Use external diff application instead of builtin one
+# hgext.extdiff =
+# ---
+# gpg - GPG checks and signing
+# hg help gpg
+# hgext.gpg =
+# ---
+# hgk - GUI repository browser
+# hg help view
+# hgk = /home/pachi/program/hg/hg/contrib/hgk.py
+# ---
+# mq - Mercurial patch queues
+# hg help mq
+# hgext.mq =
+# ---
+# notify - Template driven e-mail notifications
+# hg help notify
+# hgext.notify =
+# ---
+# patchbomb - send changesets as a series of patch emails
+# hg help email
+# hgext.patchbomb =
+# ---
+# win32text - line ending conversion filters for the Windows platform
+# hgext.win32text =
+
+# --- hgk additional configuration --- #
+# set executable path
+#[hgk]
+#path = /home/pachi/program/hg/hg/contrib/hgk
+
+# Hook to Mercurial actions - See hgrc man page for avaliable hooks
+[hooks]
+#Example notify hooks
+#incoming.notify = python:hgext.notify.hook
+#changegroup.notify = python:hgext.notify.hook
+
+# --- notify extension configuration --- #
+# Email information for the notify extension
+[email]
+#from = your at email.address
+
+# smtp sever to send notifications to
+[smtp]
+#host = localhost
+
+# base url, or dummy value if repo isn't available via http
+[web]
+#baseurl = http://hgserver/...
+
+[notify]
+# multiple sources can be specified as a whitespace separated list
+#sources = serve push pull bundle
+# set this to False when you're ready for mail to start sending
+#test = True
+#config = /path/to/subscription/file
+
+# --- end of file --- #
--- a/nobuild/gtkd-patches.diff	Thu Nov 18 12:00:02 2010 +1030
+++ b/nobuild/gtkd-patches.diff	Sun Feb 20 22:27:06 2011 +1030
@@ -1,3 +1,25 @@
+Index: GNUmakefile
+===================================================================
+--- GNUmakefile	(revision 797)
++++ GNUmakefile	(working copy)
+@@ -1,6 +1,7 @@
+ #makeAll.sh
+ SHELL=/bin/sh
+-prefix=/usr/local
++#prefix=/usr/local
++prefix=/home/daveb/source/d/dmd
+ 
+ OS=$(shell uname || uname -s)
+ ARCH=$(shell arch || uname -m)
+@@ -19,7 +20,7 @@
+ endif
+ 
+ ifeq ("$(DC)","dmd")
+-    DCFLAGS=-O
++    DCFLAGS=-O -w -wi
+     output=-of$@
+ else ifeq ("$(DC)","ldc")
+     DCFLAGS=-O
 Index: src/gdkpixbuf/PixbufAnimation.d
 ===================================================================
 --- src/gdkpixbuf/PixbufAnimation.d	(revision 797)
@@ -251,6 +273,19 @@
  	{
  		// void gtk_object_unref (GtkObject *object);
  		gtk_object_unref(gtkObject);
+Index: src/gtk/TextBuffer.d
+===================================================================
+--- src/gtk/TextBuffer.d	(revision 797)
++++ src/gtk/TextBuffer.d	(working copy)
+@@ -119,7 +119,7 @@
+ version(Tango) {
+ 	private import tango.core.Vararg;
+ } else {
+-	private import std.stdarg;
++	private import core.vararg;
+ }
+ 
+ 
 Index: src/gtk/RecentChooserMenu.d
 ===================================================================
 --- src/gtk/RecentChooserMenu.d	(revision 797)
@@ -429,28 +464,6 @@
  	}
 +        +/
  }
-Index: GNUmakefile
-===================================================================
---- GNUmakefile	(revision 797)
-+++ GNUmakefile	(working copy)
-@@ -1,6 +1,7 @@
- #makeAll.sh
- SHELL=/bin/sh
--prefix=/usr/local
-+#prefix=/usr/local
-+prefix=/home/daveb/source/d/dmd
- 
- OS=$(shell uname || uname -s)
- ARCH=$(shell arch || uname -m)
-@@ -19,7 +20,7 @@
- endif
- 
- ifeq ("$(DC)","dmd")
--    DCFLAGS=-O
-+    DCFLAGS=-O -wi
-     output=-of$@
- else ifeq ("$(DC)","ldc")
-     DCFLAGS=-O
 Index: demos/dsss.conf
 ===================================================================
 --- demos/dsss.conf	(revision 797)