[Commit] nickle ChangeLog, 1.73, 1.74 func.c, 1.24, 1.25 mem.c, 1.17, 1.18 sched.c, 1.57, 1.58 stack.c, 1.8, 1.9 stack.h, 1.5, 1.6 symbol.c, 1.20, 1.21 util.c, 1.8, 1.9

Keith Packard commit at keithp.com
Fri Jul 9 11:48:38 PDT 2004


Committed by: keithp

Update of /local/src/CVS/nickle
In directory home.keithp.com:/tmp/cvs-serv31104

Modified Files:
	ChangeLog func.c mem.c sched.c stack.c stack.h symbol.c util.c 
Log Message:
2004-07-09  Keith Packard  <keithp at keithp.com>

	* func.c: (MarkFuncCode), (MarkBuiltinCode):
	* symbol.c: (SymbolLocalMark):
	Missed a few pointers in mark code
	
	* mem.c: (MemInitialize):
	* sched.c: (RaiseException):
	A nasty one -- jumping into a continuation that is referenced
	from the thread object itself (catch) drops the reference to the
	continuation before finishing the jump.  Combined with careful
	MemCollect timing, this can break the resulting thread state.
	
	* stack.c: (StackPush), (StackPop), (StackDrop), (StackReset),
	(StackReturn), (StackElt), (StackCopy), (stackMark):
	* stack.h:
	Add assertions to make sure the stack pointer is in range
	
	* util.c: (wait_write), (debug), (panic):
	Deal with non-blocking file descriptors


Index: ChangeLog
===================================================================
RCS file: /local/src/CVS/nickle/ChangeLog,v
retrieving revision 1.73
retrieving revision 1.74
diff -u -d -r1.73 -r1.74
--- ChangeLog	7 Jul 2004 07:32:47 -0000	1.73
+++ ChangeLog	9 Jul 2004 18:48:35 -0000	1.74
@@ -1,3 +1,24 @@
+2004-07-09  Keith Packard  <keithp at keithp.com>
+
+	* func.c: (MarkFuncCode), (MarkBuiltinCode):
+	* symbol.c: (SymbolLocalMark):
+	Missed a few pointers in mark code
+	
+	* mem.c: (MemInitialize):
+	* sched.c: (RaiseException):
+	A nasty one -- jumping into a continuation that is referenced
+	from the thread object itself (catch) drops the reference to the
+	continuation before finishing the jump.  Combined with careful
+	MemCollect timing, this can break the resulting thread state.
+	
+	* stack.c: (StackPush), (StackPop), (StackDrop), (StackReset),
+	(StackReturn), (StackElt), (StackCopy), (stackMark):
+	* stack.h:
+	Add assertions to make sure the stack pointer is in range
+	
+	* util.c: (wait_write), (debug), (panic):
+	Deal with non-blocking file descriptors
+
 2004-07-07  Keith Packard  <keithp at keithp.com>
 
 	* compile.c: (CompileCountCatches), (CompileCatch), (InstDump):

Index: func.c
===================================================================
RCS file: /local/src/CVS/nickle/func.c,v
retrieving revision 1.24
retrieving revision 1.25
diff -u -d -r1.24 -r1.25
--- func.c	19 Jun 2004 19:56:45 -0000	1.24
+++ func.c	9 Jul 2004 18:48:35 -0000	1.25
@@ -14,6 +14,9 @@
 
     MemReference (fc->base.type);
     MemReference (fc->base.args);
+    MemReference (fc->base.name);
+    MemReference (fc->base.previous);
+    MemReference (fc->base.func);
     MemReference (fc->base.doc);
     MemReference (fc->code);
     MemReference (fc->body.obj);
@@ -73,6 +76,9 @@
 
     MemReference (bc->base.type);
     MemReference (bc->base.args);
+    MemReference (bc->base.name);
+    MemReference (bc->base.previous);
+    MemReference (bc->base.func);
     MemReference (bc->base.doc);
 }
 

Index: mem.c
===================================================================
RCS file: /local/src/CVS/nickle/mem.c,v
retrieving revision 1.17
retrieving revision 1.18
diff -u -d -r1.17 -r1.18
--- mem.c	2 Apr 2004 07:06:17 -0000	1.17
+++ mem.c	9 Jul 2004 18:48:35 -0000	1.18
@@ -586,6 +586,10 @@
 void
 MemInitialize (void)
 {
+#ifdef DEBUG
+    if (getenv ("NICKLE_MEM_DEBUG"))
+	GCdebug=1;
+#endif
     if (!MemStack)
     {
 	MemStack = StackCreate ();

Index: sched.c
===================================================================
RCS file: /local/src/CVS/nickle/sched.c,v
retrieving revision 1.57
retrieving revision 1.58
diff -u -d -r1.57 -r1.58
--- sched.c	7 Jul 2004 07:32:47 -0000	1.57
+++ sched.c	9 Jul 2004 18:48:35 -0000	1.58
@@ -1076,6 +1076,11 @@
 	if (catch->exception == except)
 	{
 	    continuation = &catch->continuation;
+	    /*
+	     * Hold a reference to this nested value because
+	     * ContinuationJump is about to smash the thread
+	     */
+	    REFERENCE (catch);
 	    break;
 	}
     }

Index: stack.c
===================================================================
RCS file: /local/src/CVS/nickle/stack.c,v
retrieving revision 1.8
retrieving revision 1.9
diff -u -d -r1.8 -r1.9
--- stack.c	27 Feb 2004 03:50:16 -0000	1.8
+++ stack.c	9 Jul 2004 18:48:35 -0000	1.9
@@ -54,6 +54,7 @@
 void *
 StackPush (StackObject *stack, StackElement object)
 {
+    STACK_ASSERT (stack);
     if (STACK_TOP(stack) == STACK_MIN(stack))
     {
 	stack->temp = object;
@@ -66,6 +67,7 @@
 void *
 StackPop (StackObject *stack)
 {
+    STACK_ASSERT (stack);
     if (STACK_TOP(stack) == STACK_MAX(stack))
     {
 	StackChunk  *previous = stack->current->previous;
@@ -88,6 +90,7 @@
 {
     int		this;
     StackChunk	*previous;
+    STACK_ASSERT (stack);
     while (i)
     {
 	this = STACK_MAX(stack) - STACK_TOP(stack);
@@ -109,11 +112,13 @@
 	    panic ("Stack underflow");
 	STACK_TOP(stack) = CHUNK_MIN(previous);
     }
+    STACK_ASSERT (stack);
 }
 
 void
 StackReset (StackObject *stack, StackPointer stackPointer)
 {
+    STACK_ASSERT (stack);
     while (!(STACK_TOP(stack) <= stackPointer && stackPointer <= STACK_MAX(stack)))
     {
 	StackChunk  *previous = stack->current->previous;
@@ -129,11 +134,13 @@
 	STACK_TOP(stack) = CHUNK_MIN(previous);
     }
     STACK_TOP(stack) = stackPointer;
+    STACK_ASSERT (stack);
 }
 
 StackElement
 StackReturn (StackObject *stack, StackPointer stackPointer, StackElement object)
 {
+    STACK_ASSERT (stack);
     STACK_RESET(stack, stackPointer);
     return STACK_PUSH(stack,object);
 }
@@ -144,6 +151,7 @@
     StackChunk	    *chunk;
     StackPointer    stackPointer;
 
+    STACK_ASSERT (stack);
     chunk = stack->current;
     stackPointer = STACK_TOP(stack);
     while (stackPointer + i >= CHUNK_MAX(chunk))
@@ -164,14 +172,21 @@
     StackObject	*new;
     StackChunk	*chunk, *nchunk, **prev;
 
+    STACK_ASSERT (stack);
     new = StackCreate ();
     chunk = stack->current;
     nchunk = new->current;
     prev = &new->current;
     while (chunk)
     {
+	STACK_ASSERT (new);
+	STACK_ASSERT (stack);
 	if (!nchunk)
 	    nchunk = MemAllocate (&stackChunkType, sizeof (StackChunk));
+	else
+	    STACK_TOP(new) = (new->current->elements + 
+			      (STACK_TOP(stack) - stack->current->elements));
+	    
 	/*
 	 * Copy stack data and fix stack pointer
 	 */
@@ -185,7 +200,7 @@
 	chunk = chunk->previous;
 	nchunk = 0;
     }
-    STACK_TOP(new) = new->current->elements + (STACK_TOP(stack) - stack->current->elements);
+    STACK_ASSERT (new);
     RETURN (new);
 }
 
@@ -196,6 +211,7 @@
     StackChunk	    *chunk;
     StackPointer    stackPointer;
 
+    STACK_ASSERT (stack);
     MemReference (stack->temp);
     MemReference (stack->save);
     chunk = stack->current;

Index: stack.h
===================================================================
RCS file: /local/src/CVS/nickle/stack.h,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -d -r1.5 -r1.6
--- stack.h	27 Feb 2004 03:50:16 -0000	1.5
+++ stack.h	9 Jul 2004 18:48:35 -0000	1.6
@@ -57,6 +57,16 @@
 			 STACK_TOP(s)[i] : StackElt(s,i))
 
 #if 0
+#define STACK_VALID(s)	((!(s)->stackPointer && !(s)->current) || \
+			 (STACK_MIN(s) <= STACK_TOP(s) && \
+			  STACK_TOP(s) <= STACK_MAX(s)))
+
+#define STACK_ASSERT(s)	if (!STACK_VALID(s)) panic ("invalid stack\n");
+#else
+#define STACK_ASSERT(s)
+#endif
+
+#if 0
 /*
  * Can't work -- o gets evaluated after the stack overflow check, 
  * if o also uses the stack, this will break
@@ -69,6 +79,7 @@
 static inline StackElement
 StackPushInline(StackObject *s, StackElement o)
 {
+    STACK_ASSERT (s);
     if (STACK_TOP(s) == STACK_MIN(s))
 	return StackPush (s, o);
     return *--STACK_TOP(s) = o;
@@ -77,7 +88,9 @@
 static inline StackElement
 StackReturnInline(StackObject *s, StackPointer sp, StackElement o)
 {
+    STACK_ASSERT(s);
     STACK_RESET(s, sp);
+    STACK_ASSERT(s);
     if (STACK_TOP(s) == STACK_MIN(s))
 	return StackPush (s, o);
     return *--STACK_TOP(s) = o;

Index: symbol.c
===================================================================
RCS file: /local/src/CVS/nickle/symbol.c,v
retrieving revision 1.20
retrieving revision 1.21
diff -u -d -r1.20 -r1.21
--- symbol.c	8 Jun 2004 09:30:54 -0000	1.20
+++ symbol.c	9 Jul 2004 18:48:35 -0000	1.21
@@ -34,6 +34,7 @@
 
     MemReference (sl->symbol.next);
     MemReference (sl->symbol.type);
+    MemReference (sl->code);
 }
 
 static void

Index: util.c
===================================================================
RCS file: /local/src/CVS/nickle/util.c,v
retrieving revision 1.8
retrieving revision 1.9
diff -u -d -r1.8 -r1.9
--- util.c	27 Feb 2004 03:50:16 -0000	1.8
+++ util.c	9 Jul 2004 18:48:35 -0000	1.9
@@ -45,6 +45,9 @@
 
 #ifdef HAVE_VPRINTF
 
+#include	<sys/poll.h>
+#include	<errno.h>
+
 /*
  * Currently vfprintf() is required.  It would
  * be easy to do a _doprnt() version if necessary,
@@ -52,24 +55,67 @@
  * non-varargs versions of these.  Contributed code welcome.
  */
 
+static int
+wait_write (int fd, char *buf, int len)
+{
+    int	n;
+    int w = 0;
+
+    while (len)
+    {
+	n = write (fd, buf, len);
+	if (n < 0)
+	{
+	    if (errno == EINTR)
+	    {
+		struct pollfd   f;
+    
+		f.fd = fd;
+		f.events = POLLOUT;
+    
+		(void) poll (&f, 1, -1);
+	    }
+	    else
+	    {
+		if (w)
+		    return w;
+		return -1;
+	    }
+	}
+	else
+	{
+	    w += n;
+	    buf += n;
+	    len -= n;
+	}
+    }
+    return w;
+}
+
 void
 debug (char *format, ...)
 {
     va_list	ap;
+    char	buf[4096];
+    int		len;
 
     va_start (ap, format);
-    vfprintf (stderr, format, ap);
+    len = vsnprintf (buf, sizeof (buf), format, ap);
     va_end (ap);
+    wait_write (2, buf, len);
 }
 
 void
 panic (char *format, ...)
 {
     va_list	ap;
+    char	buf[4096];
+    int		len;
 
     va_start (ap, format);
-    vfprintf (stderr, format, ap);
+    len = vsnprintf (buf, sizeof (buf), format, ap);
     va_end (ap);
+    wait_write (2, buf, len);
     abort ();
 }
 




More information about the Commit mailing list