From a99145ebabf00c78313dcff105325bd60d4f44c3 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Fredrik=20H=C3=BCbinette=20=28Hubbe=29?= <hubbe@hubbe.net>
Date: Tue, 8 Jul 1997 17:57:07 -0700
Subject: [PATCH] some bugfixes

Rev: src/.cvsignore:1.12
Rev: src/ChangeLog:1.111
Rev: src/configure.in:1.102
Rev: src/dynamic_load.c:1.18
Rev: src/gc.c:1.10
Rev: src/stralloc.c:1.16
Rev: src/testsuite.in:1.45
---
 src/.cvsignore     |  1 +
 src/.gitignore     |  1 +
 src/ChangeLog      |  6 ++++++
 src/configure.in   | 10 ++++++++--
 src/dynamic_load.c |  2 ++
 src/gc.c           |  5 ++++-
 src/stralloc.c     | 21 +++++++++++++++++++++
 src/testsuite.in   |  3 ++-
 8 files changed, 45 insertions(+), 4 deletions(-)

diff --git a/src/.cvsignore b/src/.cvsignore
index 052a12327b..f693a5edb4 100644
--- a/src/.cvsignore
+++ b/src/.cvsignore
@@ -4,6 +4,7 @@ config.h.in
 config.log
 config.status
 configure
+conftest.c
 conftest.h
 dependencies
 language.c
diff --git a/src/.gitignore b/src/.gitignore
index 48b552bef0..51c6f0f67c 100644
--- a/src/.gitignore
+++ b/src/.gitignore
@@ -4,6 +4,7 @@
 /config.log
 /config.status
 /configure
+/conftest.c
 /conftest.h
 /dependencies
 /language.c
diff --git a/src/ChangeLog b/src/ChangeLog
index 802458d4c5..fab8219ccf 100644
--- a/src/ChangeLog
+++ b/src/ChangeLog
@@ -1,3 +1,9 @@
+Tue Jul  8 17:51:06 1997  Fredrik Hubinette  <hubbe@cytocin.hubbe.net>
+
+	* stralloc.c: fixed a bug in replace() (if 'from' is an empty string)
+	* testsuite.in: added a test for the above
+	* configure.in: added more debug to dynamic module tests
+
 Fri Jun 27 19:30:52 1997  Henrik Grubbstr�m  <grubba@infovav.se>
 
 	* modules/Sql/sql.pike (create): The host argument can now use the
diff --git a/src/configure.in b/src/configure.in
index c189b15cea..f2cb9eb11e 100644
--- a/src/configure.in
+++ b/src/configure.in
@@ -1,4 +1,4 @@
-AC_REVISION("$Id: configure.in,v 1.101 1997/06/12 14:59:05 grubba Exp $")
+AC_REVISION("$Id: configure.in,v 1.102 1997/07/09 00:57:04 hubbe Exp $")
 AC_INIT(interpret.c)
 AC_CONFIG_HEADER(machine.h)
 
@@ -1507,7 +1507,13 @@ AC_MSG_RESULT($LINKFORSHARED)
 #############################################################################
 
 cat >conftest.c <<EOF
-void testfunc(void) { testfunc2(); exit(1); }
+#include <stdio.h>
+void testfunc(void) {
+  fprintf(stderr,"Calling testfunc2\n");
+  testfunc2();
+  fprintf(stderr,"testfunc2 returned!\n");
+  exit(1);
+}
 EOF
 
 AC_MSG_CHECKING(if dynamic loading works)
diff --git a/src/dynamic_load.c b/src/dynamic_load.c
index 93d4896b9e..e9d8478ccb 100644
--- a/src/dynamic_load.c
+++ b/src/dynamic_load.c
@@ -183,7 +183,9 @@ int main()
     fprintf(stderr,"Failed to find function testfunc: %s\n",dlerror());
     exit(1);
   }
+  fprintf(stderr,"Calling testfunc\n");
   ((void (*)(void))fun)();
+  fprintf(stderr,"testfunc returned!\n");
   exit(1);
 }
 #endif
diff --git a/src/gc.c b/src/gc.c
index 6b33fc6d70..c857796a23 100644
--- a/src/gc.c
+++ b/src/gc.c
@@ -257,7 +257,8 @@ void do_gc()
   hash=(struct marker **)xalloc(sizeof(struct marker **)*hashsize);
   MEMSET((char *)hash,0,sizeof(struct marker **)*hashsize);
   markers_left_in_chunk=0;
-  
+
+  /* First we count internal references */
   gc_check_all_arrays();
   gc_check_all_multisets();
   gc_check_all_mappings();
@@ -265,6 +266,7 @@ void do_gc()
   gc_check_all_objects();
   call_callback(& gc_callbacks, (void *)0);
 
+  /* Next we mark anything with external references */
   gc_mark_all_arrays();
   gc_mark_all_multisets();
   gc_mark_all_mappings();
@@ -274,6 +276,7 @@ void do_gc()
   if(d_flag)
     gc_mark_all_strings();
 
+  /* Now we free the unused stuff */
   gc_free_all_unreferenced_arrays();
   gc_free_all_unreferenced_multisets();
   gc_free_all_unreferenced_mappings();
diff --git a/src/stralloc.c b/src/stralloc.c
index ba03109b9e..4e71ee19dd 100644
--- a/src/stralloc.c
+++ b/src/stralloc.c
@@ -510,6 +510,27 @@ struct pike_string *string_replace(struct pike_string *str,
   char *s,*tmp,*r,*end;
   struct mem_searcher searcher;
 
+  if(!str->len)
+  {
+    str->refs++;
+    return str;
+  }
+
+  if(!del->len)
+  {
+    int e;
+    ret=begin_shared_string(str->len + to->len * (str->len -1));
+    s=ret->str;
+    *(s++)=str->str[0];
+    for(e=1;e<str->len;e++)
+    {
+      MEMCPY(s,to->str,to->len);
+      s+=to->len;
+      *(s++)=str->str[e];
+    }
+    return end_shared_string(ret);
+  }
+
   s=str->str;
   end=s+str->len;
 
diff --git a/src/testsuite.in b/src/testsuite.in
index b5c18f0fa2..94f40bda80 100644
--- a/src/testsuite.in
+++ b/src/testsuite.in
@@ -1,4 +1,4 @@
-test_true([["$Id: testsuite.in,v 1.44 1997/06/12 23:08:10 grubba Exp $"]])
+test_true([["$Id: testsuite.in,v 1.45 1997/07/09 00:57:07 hubbe Exp $"]])
 test_eq(1e1,10.0)
 test_eq(1E1,10.0)
 test_eq(1e+1,10.0)
@@ -20,6 +20,7 @@ test_compile_error([[int a() { switch(random(2)) { case 3: if(random(2)) { case
 test_true(encode_value(0))
 test_true(encode_value(0)[0]=='\266')
 define(test_encode, [[ test_equal($1, decode_value(encode_value($1))) ]])
+test_eq(replace("foobar","","X"),"fXoXoXbXaXr")
 test_encode(0)
 test_encode("")
 test_encode(0.0)
-- 
GitLab