changeset 1266:e1ddfb12566d

[project @ 1995-04-20 18:56:04 by jwe]
author jwe
date Thu, 20 Apr 1995 19:09:12 +0000
parents 86672dc517f3
children 69501f98669d
files info/xmalloc.c src/error.cc src/lex.l src/octave.cc src/parse.y src/pt-cmd.cc src/utils.cc
diffstat 7 files changed, 125 insertions(+), 20 deletions(-) [+]
line wrap: on
line diff
--- a/info/xmalloc.c	Wed Apr 12 02:20:53 1995 +0000
+++ b/info/xmalloc.c	Thu Apr 20 19:09:12 1995 +0000
@@ -43,6 +43,11 @@
 /* Return a pointer to free()able block of memory large enough
    to hold BYTES number of bytes.  If the memory cannot be allocated,
    print an error message and abort. */
+
+#if defined (DEBUG_MALLOC_FREE)
+int debug_malloc_free = 0;
+#endif
+
 void *
 xmalloc (bytes)
      int bytes;
@@ -51,6 +56,12 @@
 
   if (!temp)
     memory_error_and_abort ("xmalloc");
+
+#if defined (DEBUG_MALLOC_FREE)
+  if (debug_malloc_free)
+    printf ("%x\n", temp);
+#endif
+
   return (temp);
 }
 
@@ -69,6 +80,11 @@
   if (!temp)
     memory_error_and_abort ("xrealloc");
 
+#if defined (DEBUG_MALLOC_FREE)
+  if (debug_malloc_free)
+    printf ("%x\n", temp);
+#endif
+
   return (temp);
 }
 
--- a/src/error.cc	Wed Apr 12 02:20:53 1995 +0000
+++ b/src/error.cc	Thu Apr 20 19:09:12 1995 +0000
@@ -65,6 +65,10 @@
   delete [] msg;
 }
 
+// Note that we don't actually print any message if the error string
+// is just "" or "\n".  This allows error ("") and error ("\n") to
+// just set the error state.
+
 static void
 error_1 (const char *name, const char *fmt, va_list args)
 {
@@ -75,17 +79,29 @@
 
       if (! suppress_octave_error_messages)
 	{
-	  int len = 0;
-	  if (fmt && *fmt && fmt[(len = strlen (fmt)) - 1] == '\n')
+	  if (fmt)
 	    {
-	      error_state = -2;
-	      char *tmp_fmt = strsave (fmt);
-	      tmp_fmt[len - 1] = '\0';
-	      verror (name, tmp_fmt, args);
-	      delete [] tmp_fmt;
+	      if (*fmt)
+		{
+		  int len = strlen (fmt);
+		  if (fmt[len - 1] == '\n')
+		    {
+		      error_state = -2;
+
+		      if (len > 1)
+			{
+			  char *tmp_fmt = strsave (fmt);
+			  tmp_fmt[len - 1] = '\0';
+			  verror (name, tmp_fmt, args);
+			  delete [] tmp_fmt;
+			}
+		    }
+		  else
+		    verror (name, fmt, args);
+		}
 	    }
 	  else
-	    verror (name, fmt, args);
+	    panic ("error_1: invalid format");
 	}
     }
 }
@@ -168,7 +184,7 @@
 	{
 	  msg = args(0).string_value ();
 
-	  if (! msg || ! *msg)
+	  if (! msg)
 	    return retval;
 	}
       else if (args(0).is_empty ())
--- a/src/lex.l	Wed Apr 12 02:20:53 1995 +0000
+++ b/src/lex.l	Thu Apr 20 19:09:12 1995 +0000
@@ -1339,7 +1339,11 @@
 static char *
 strip_trailing_whitespace (char *s)
 {
-  char *retval = strsave (s);
+  static char *retval = 0;
+
+  delete [] retval;
+
+  retval = strsave (s);
 
   char *t = strchr (retval, ' ');
   if (t)
--- a/src/octave.cc	Wed Apr 12 02:20:53 1995 +0000
+++ b/src/octave.cc	Thu Apr 20 19:09:12 1995 +0000
@@ -989,6 +989,44 @@
 
 DEFALIAS (shell_cmd, system);
 
+#if defined (__GNUG__) && defined (DEBUG_NEW_DELETE)
+int debug_new_delete = 0;
+
+typedef void (*vfp)(void);
+extern vfp __new_handler;
+
+void *
+__builtin_new (size_t sz)
+{
+  void *p;
+
+  /* malloc (0) is unpredictable; avoid it.  */
+  if (sz == 0)
+    sz = 1;
+  p = (void *) malloc (sz);
+  while (p == 0)
+    {
+      (*__new_handler) ();
+      p = (void *) malloc (sz);
+    }
+
+  if (debug_new_delete)
+    cout << "__builtin_new: " << p << endl;
+
+  return p;
+}
+
+void
+__builtin_delete (void *ptr)
+{
+  if (debug_new_delete)
+    cout << "__builtin_delete: " << ptr << endl;
+
+  if (ptr)
+    free (ptr);
+}
+#endif
+
 /*
 ;;; Local Variables: ***
 ;;; mode: C++ ***
--- a/src/parse.y	Wed Apr 12 02:20:53 1995 +0000
+++ b/src/parse.y	Thu Apr 20 19:09:12 1995 +0000
@@ -1353,10 +1353,14 @@
     }
   else
     {
+      // XXX FIXME XXX -- making ans_id static, passing its address to
+      // tree_simple_assignment_expression along with a flag to not
+      // delete it seems to create a memory leak.  Hmm.
+
       static symbol_record *sr = global_sym_tab->lookup ("ans", 1, 0);
-      static tree_identifier ans_id (sr);
+      tree_identifier *ans_id = new tree_identifier (sr);
 
-      return new tree_simple_assignment_expression (&ans_id, expr, 1, 1);
+      return new tree_simple_assignment_expression (ans_id, expr, 0, 1);
     }
 }
 
--- a/src/pt-cmd.cc	Wed Apr 12 02:20:53 1995 +0000
+++ b/src/pt-cmd.cc	Thu Apr 20 19:09:12 1995 +0000
@@ -651,12 +651,40 @@
   // ignored.
 
   unwind_protect_int (error_state);
+  error_state = 0;
 
-  error_state = 0;
+  // Similarly, if we have seen a return or break statement, allow all
+  // the cleanup code to run before returning or handling the break.
+  // We don't have to worry about continue statements because they can
+  // only occur in loops.
+
+  unwind_protect_int (returning);
+  returning = 0;
+
+  unwind_protect_int (breaking);
+  breaking = 0;
 
   if (list)
     list->eval (1);
 
+  // This is the one for breaking.  (The unwind_protects are popped
+  // off the stack in the reverse of the order they are pushed on).
+
+  // XXX FIXME XXX -- inside an unwind_protect, should break work like
+  // a return, or just jump to the end of the unwind_protect block?
+  // The following code makes it just jump to the end of the block.
+
+  run_unwind_protect ();
+  if (breaking)
+    breaking--;
+
+  // This is the one for returning.
+
+  if (returning)
+    discard_unwind_protect ();
+  else
+    run_unwind_protect ();
+
   // We don't want to ignore errors that occur in the cleanup code, so
   // if an error is encountered there, leave error_state alone.
   // Otherwise, set it back to what it was before.
--- a/src/utils.cc	Wed Apr 12 02:20:53 1995 +0000
+++ b/src/utils.cc	Thu Apr 20 19:09:12 1995 +0000
@@ -124,7 +124,8 @@
   int len = strlen (s) + strlen (t);
   char *tmp = new char [len+1];
   strcpy (tmp, s);
-  return strcat (tmp, t);
+  strcat (tmp, t);
+  return tmp;
 }
 
 // Throw away input until a given character is read.
@@ -694,14 +695,12 @@
 {
   char *retval = 0;
 
-  char *nm = strsave (name);
+  char *nm = 0;
 
   if (suffix)
-    {
-      char *tmp = nm;
-      nm = strconcat (tmp, suffix);
-      delete [] tmp;
-    }
+    nm = strconcat (name, suffix);
+  else
+    nm = strsave (name);
 
   if (! the_current_working_directory)
     get_working_directory ("file_in_path");