poldek: trurlib/README, trurlib/n_array_clean.c, trurlib/n_array_m...

mis mis at pld-linux.org
Tue Jun 19 23:52:54 CEST 2007


Author: mis                          Date: Tue Jun 19 21:52:54 2007 GMT
Module: poldek                        Tag: HEAD
---- Log message:
- freeze feature for n_array

---- Files affected:
poldek/trurlib:
   README (1.2 -> 1.3) , n_array_clean.c (1.1 -> 1.2) , n_array_map.c (1.2 -> 1.3) , n_array_map_arg.c (1.2 -> 1.3) , n_array_pop.c (1.1 -> 1.2) , n_array_push.c (1.3 -> 1.4) , n_array_remove_ex.c (1.3 -> 1.4) , n_array_remove_nth.c (1.2 -> 1.3) , n_array_set_nth.c (1.2 -> 1.3) , n_array_shift.c (1.1 -> 1.2) , n_array_uniq_ex.c (1.1 -> 1.2) , n_array_unshift.c (1.2 -> 1.3) 
poldek/trurlib/include/trurl:
   narray.h (1.28 -> 1.29) , ndie.h (1.1 -> 1.2) , trurl.h (1.8 -> 1.9) 

---- Diffs:

================================================================
Index: poldek/trurlib/README
diff -u poldek/trurlib/README:1.2 poldek/trurlib/README:1.3
--- poldek/trurlib/README:1.2	Fri Apr 26 01:37:25 2002
+++ poldek/trurlib/README	Tue Jun 19 23:52:49 2007
@@ -13,11 +13,10 @@
 There is no docs, but interface is really simple so
 reading headers should be enough.  
 
-Project CVS: <http://cvs.pld.org.pl/installer/trurlib/>.  
-Download: <http://team.pld.org.pl/~mis/poldek/download/>.  
-Please send comments, bug reports, etc to me <mis at pld.org.pl>
+Library is internally used by poldek project.
+Project CVS repository: <http://cvs.pld-linux.org/cgi-bin/cvsweb/poldek/trurlib/>.  
 
-Copyright (C) 1999 - 2002 Pawel A. Gajda
+Copyright (C) 1999 - 2007 Pawel A. Gajda (mis at pld-linux.org)
 TRURLib is free software; you can redistribute it and/or modify
 it under the terms of the GNU Library General Public License, version 2 as
 published by the Free Software Foundation (see file COPYING for details).

================================================================
Index: poldek/trurlib/n_array_clean.c
diff -u poldek/trurlib/n_array_clean.c:1.1 poldek/trurlib/n_array_clean.c:1.2
--- poldek/trurlib/n_array_clean.c:1.1	Sun Oct 29 22:12:21 2000
+++ poldek/trurlib/n_array_clean.c	Tue Jun 19 23:52:49 2007
@@ -5,6 +5,8 @@
 tn_array *n_array_clean(tn_array *arr)
 {
     register unsigned int i;
+    
+    trurl_die__if_frozen(arr);
 
     for (i = 0; i < arr->allocated; i++) {
         if (arr->data[i] != NULL) {

================================================================
Index: poldek/trurlib/n_array_map.c
diff -u poldek/trurlib/n_array_map.c:1.2 poldek/trurlib/n_array_map.c:1.3
--- poldek/trurlib/n_array_map.c:1.2	Thu Feb  8 13:41:27 2001
+++ poldek/trurlib/n_array_map.c	Tue Jun 19 23:52:49 2007
@@ -2,7 +2,7 @@
 
 #include "n_array_int.h"
 
-void n_array_map(tn_array *arr, void (*map_fn) (void *))
+void n_array_map(const tn_array *arr, void (*map_fn) (void *))
 {
     register size_t i, n;
 
@@ -10,6 +10,6 @@
     n = arr->items;
 
     for (i = arr->start_index; i < n; i++)
-	map_fn(arr->data[i]);
-
+        map_fn(arr->data[i]);
+    
 }

================================================================
Index: poldek/trurlib/n_array_map_arg.c
diff -u poldek/trurlib/n_array_map_arg.c:1.2 poldek/trurlib/n_array_map_arg.c:1.3
--- poldek/trurlib/n_array_map_arg.c:1.2	Thu Feb  8 13:41:27 2001
+++ poldek/trurlib/n_array_map_arg.c	Tue Jun 19 23:52:49 2007
@@ -2,7 +2,7 @@
 
 #include "n_array_int.h"
 
-void n_array_map_arg(tn_array *arr, void (*map_fn) (void *, void *), void *arg)
+void n_array_map_arg(const tn_array *arr, void (*map_fn) (void *, void *), void *arg)
 {
     register size_t i, n;
 

================================================================
Index: poldek/trurlib/n_array_pop.c
diff -u poldek/trurlib/n_array_pop.c:1.1 poldek/trurlib/n_array_pop.c:1.2
--- poldek/trurlib/n_array_pop.c:1.1	Sun Oct 29 22:12:21 2000
+++ poldek/trurlib/n_array_pop.c	Tue Jun 19 23:52:49 2007
@@ -7,13 +7,15 @@
     register void *ptr;
     register size_t pos = arr->start_index + arr->items - 1;
 
+    trurl_die__if_frozen(arr);
+    
     if (arr->items <= 0) {
-	trurl_die("tn_array_pop: pop from empty array\n");
-	return NULL;
+        trurl_die("tn_array_pop: pop from empty array\n");
+        return NULL;
     }
 
     if (arr->items > 0)
-	arr->items--;
+        arr->items--;
 
     ptr = arr->data[pos];
 

================================================================
Index: poldek/trurlib/n_array_push.c
diff -u poldek/trurlib/n_array_push.c:1.3 poldek/trurlib/n_array_push.c:1.4
--- poldek/trurlib/n_array_push.c:1.3	Mon Mar 22 18:32:47 2004
+++ poldek/trurlib/n_array_push.c	Tue Jun 19 23:52:49 2007
@@ -5,7 +5,8 @@
 
 tn_array *n_array_push(tn_array *arr, void *data)
 {
-    //printf("n_array_push\n");
+    trurl_die__if_frozen(arr);
+    
     if (arr->items == arr->allocated) {
         if (n_array_grow_priv_(arr, arr->allocated + 1) == NULL)
             return NULL;
@@ -21,6 +22,8 @@
 tn_array *n_array_concat_ex(tn_array *arr, tn_array *src, tn_fn_dup dup_fn)
 {
     register int i;
+
+    trurl_die__if_frozen(arr);
     
     for (i=0; i < n_array_size(src); i++) {
         void *item = n_array_nth(src, i);

================================================================
Index: poldek/trurlib/n_array_remove_ex.c
diff -u poldek/trurlib/n_array_remove_ex.c:1.3 poldek/trurlib/n_array_remove_ex.c:1.4
--- poldek/trurlib/n_array_remove_ex.c:1.3	Mon Nov  4 18:49:21 2002
+++ poldek/trurlib/n_array_remove_ex.c	Tue Jun 19 23:52:49 2007
@@ -7,11 +7,13 @@
     register int i, items, n;
     register void *ptr;
 
+    trurl_die__if_frozen(arr);
+    
     if (arr->items == 0)
         return arr;
     
     if (cmpf == NULL)
-	cmpf = arr->cmp_fn;
+        cmpf = arr->cmp_fn;
 
     n_assert(cmpf != NULL);
     

================================================================
Index: poldek/trurlib/n_array_remove_nth.c
diff -u poldek/trurlib/n_array_remove_nth.c:1.2 poldek/trurlib/n_array_remove_nth.c:1.3
--- poldek/trurlib/n_array_remove_nth.c:1.2	Thu Feb  8 13:41:27 2001
+++ poldek/trurlib/n_array_remove_nth.c	Tue Jun 19 23:52:49 2007
@@ -7,21 +7,23 @@
     register unsigned int pos = arr->start_index + i;
     register void *ptr;
 
+    trurl_die__if_frozen(arr);
+    
     n_assert(i >= 0);
     n_assert(arr->allocated > 0);
     n_assert(arr->items > 0);
 
     if ((size_t) i >= arr->items || i < 0) {
-	trurl_die("n_array_remove_nth: index(%d) out of bounds(0 - %d)\n", i,
-		  arr->items);
-	return NULL;
+        trurl_die("n_array_remove_nth: index(%d) out of bounds(0 - %d)\n", i,
+                  arr->items);
+        return NULL;
     }
     
     ptr = arr->data[pos];
 
     /* if slot is not empty, free node data */
     if (arr->data[pos] != NULL && arr->free_fn != NULL)
-	arr->free_fn(arr->data[pos]);
+        arr->free_fn(arr->data[pos]);
 
     if (pos == arr->items) 
         arr->data[pos] = NULL;

================================================================
Index: poldek/trurlib/n_array_set_nth.c
diff -u poldek/trurlib/n_array_set_nth.c:1.2 poldek/trurlib/n_array_set_nth.c:1.3
--- poldek/trurlib/n_array_set_nth.c:1.2	Fri Dec 13 18:27:38 2002
+++ poldek/trurlib/n_array_set_nth.c	Tue Jun 19 23:52:49 2007
@@ -9,6 +9,8 @@
     n_assert(i >= 0);
     n_assert(arr->allocated > 0);
 
+    trurl_die__if_frozen(arr);
+    
     if (i < 0) {
         trurl_die("n_array_set_nth: index(%d) out of bounds(%d)\n", i,
                   arr->items);

================================================================
Index: poldek/trurlib/n_array_shift.c
diff -u poldek/trurlib/n_array_shift.c:1.1 poldek/trurlib/n_array_shift.c:1.2
--- poldek/trurlib/n_array_shift.c:1.1	Sun Oct 29 22:12:21 2000
+++ poldek/trurlib/n_array_shift.c	Tue Jun 19 23:52:49 2007
@@ -6,9 +6,11 @@
 {
     void *ptr;
 
+    trurl_die__if_frozen(arr);
+    
     if (arr->items <= 0) {
-	trurl_die("tn_array_shift: shift from empty array\n");
-	return NULL;
+        trurl_die("tn_array_shift: shift from empty array\n");
+        return NULL;
     }
     arr->items--;
 

================================================================
Index: poldek/trurlib/n_array_uniq_ex.c
diff -u poldek/trurlib/n_array_uniq_ex.c:1.1 poldek/trurlib/n_array_uniq_ex.c:1.2
--- poldek/trurlib/n_array_uniq_ex.c:1.1	Sun Oct 29 22:12:21 2000
+++ poldek/trurlib/n_array_uniq_ex.c	Tue Jun 19 23:52:49 2007
@@ -6,23 +6,25 @@
 {
     register size_t i = 1;
 
+    trurl_die__if_frozen(arr);
+    
     if (cmpf == NULL)
-	cmpf = arr->cmp_fn;
+        cmpf = arr->cmp_fn;
 
     n_assert(cmpf != NULL);
 
     if (cmpf == NULL) {
-	trurl_die("n_array_uniq_ex: compare function is NULL\n");
-	return NULL;
+        trurl_die("n_array_uniq_ex: compare function is NULL\n");
+        return NULL;
     }
     
     while (i < arr->items) {
-	if (cmpf(arr->data[i - 1], arr->data[i]) == 0) {
-	    n_array_remove_nth(arr, i);
+        if (cmpf(arr->data[i - 1], arr->data[i]) == 0) {
+            n_array_remove_nth(arr, i);
 
-	} else {
-	    i++;
-	}
+        } else {
+            i++;
+        }
     }
     return arr;
 }

================================================================
Index: poldek/trurlib/n_array_unshift.c
diff -u poldek/trurlib/n_array_unshift.c:1.2 poldek/trurlib/n_array_unshift.c:1.3
--- poldek/trurlib/n_array_unshift.c:1.2	Fri Dec 13 18:27:38 2002
+++ poldek/trurlib/n_array_unshift.c	Tue Jun 19 23:52:49 2007
@@ -4,18 +4,20 @@
 
 tn_array *n_array_unshift(tn_array *arr, void *data)
 {
+    trurl_die__if_frozen(arr);
+
     if(arr->start_index > 0) {
-	arr->start_index--;
-	arr->data[arr->start_index] = data;
+        arr->start_index--;
+        arr->data[arr->start_index] = data;
 
     } else {
-	if (arr->items == arr->allocated) {
-	    if (n_array_grow_priv_(arr, arr->allocated + 1) == NULL)
-		return NULL;
-	}
+        if (arr->items == arr->allocated) {
+            if (n_array_grow_priv_(arr, arr->allocated + 1) == NULL)
+                return NULL;
+        }
         
-	memmove(&arr->data[1], &arr->data[0], arr->items * sizeof(*arr->data));
-	arr->data[0] = data;
+        memmove(&arr->data[1], &arr->data[0], arr->items * sizeof(*arr->data));
+        arr->data[0] = data;
     }
 
     arr->items++;

================================================================
Index: poldek/trurlib/include/trurl/narray.h
diff -u poldek/trurlib/include/trurl/narray.h:1.28 poldek/trurlib/include/trurl/narray.h:1.29
--- poldek/trurlib/include/trurl/narray.h:1.28	Sun Nov  6 20:29:52 2005
+++ poldek/trurlib/include/trurl/narray.h	Tue Jun 19 23:52:49 2007
@@ -18,6 +18,8 @@
 #define TN_ARRAY_AUTOSORTED        (1 << 1) /* an array sorts itself in bsearch_*
                                                functions;  don't work with
                                                external cmp functions */
+#define TN_ARRAY_FROZEN             (1 << 2)
+
 #define TN_ARRAY_INTERNAL_ISSORTED  (1 << 8)
 #define TN_ARRAY_INTERNAL_NA        (1 << 9)
 /* WARN: _never_ ever access array members directly */
@@ -56,6 +58,11 @@
     return arr;
 }
 #endif
+
+#define n_array_freeze(arr) (arr)->flags |= TN_ARRAY_FROZEN
+#define n_array_unfreeze(arr) (arr)->flags &= ~(TN_ARRAY_FROZEN)
+
+
 #define n_array_ctl_growth(arr, inctype)  ((void) 0) /* backward API compat */
 #define n_array_has_free_fn(arr) (arr)->free_fn /* -"- */
 
@@ -144,8 +151,8 @@
 tn_array *n_array_concat_ex(tn_array *arr, tn_array *src, tn_fn_dup dup_fn);
 #define n_array_concat(arr, src) n_array_concat_ex(arr, src, NULL) 
 
-/* internal macros don't use */
 
+/* internal macros, do not use them */
 #define TN_ARRAY_set_sorted(arr) ((arr)->flags |= TN_ARRAY_INTERNAL_ISSORTED)
 #define TN_ARRAY_clr_sorted(arr) ((arr)->flags &= ~TN_ARRAY_INTERNAL_ISSORTED)
 #define TN_ARRAY_is_sorted(arr)  ((arr)->flags &  TN_ARRAY_INTERNAL_ISSORTED)
@@ -155,6 +162,8 @@
 #define n_array_push(a, d) n_array_push_inl(a, d)
 static inline tn_array *n_array_push_inl(tn_array *arr, void *data) {
 
+    trurl_die__if_frozen(arr);
+    
     if (arr->items == arr->allocated) {
         if (n_array_grow_priv_(arr, arr->allocated + 1) == 0)
             return 0;
@@ -237,9 +246,6 @@
 int n_array_bsearch_idx_ex(const tn_array *arr, const void *data, t_fn_cmp cmpf);
 #define n_array_bsearch_idx(arr, data) n_array_bsearch_idx_ex(arr, data, NULL)
 
-
-
-
 tn_array *n_array_remove_ex(tn_array *arr, const void *data, t_fn_cmp cmpf);
 #define n_array_remove(arr, data) n_array_remove_ex(arr, data, NULL)
 
@@ -247,14 +253,14 @@
    for(i=0; i<n_array_size(arr); i++) 
        map_fn(arr[i])
 */
-void n_array_map(tn_array *arr, void (*map_fn)(void *));
+void n_array_map(const tn_array *arr, void (*map_fn)(void *));
 
 
 /* 
    for(i=0; i<n_array_size(arr); i++) 
        map_fn(arr[i], arg)
 */
-void n_array_map_arg(tn_array *arr, void (*map_fn)(void *, void *), void *arg);
+void n_array_map_arg(const tn_array *arr, void (*map_fn)(void *, void *), void *arg);
 
 
 /* for debugging */

================================================================
Index: poldek/trurlib/include/trurl/ndie.h
diff -u poldek/trurlib/include/trurl/ndie.h:1.1 poldek/trurlib/include/trurl/ndie.h:1.2
--- poldek/trurlib/include/trurl/ndie.h:1.1	Mon May  6 23:05:46 2002
+++ poldek/trurlib/include/trurl/ndie.h	Tue Jun 19 23:52:49 2007
@@ -13,4 +13,11 @@
 t_fn_die_hook n_die_set_hook(t_fn_die_hook hook);
 void n_die(const char *fmt, ...);
 
+/* internal macro, do not use  */
+#define trurl_die__if_frozen(arr) \
+    do {                                    \
+        if ((arr)->flags & TN_ARRAY_FROZEN) \
+            n_die("array is frozen");   \
+    } while (0)
+
 #endif

================================================================
Index: poldek/trurlib/include/trurl/trurl.h
diff -u poldek/trurlib/include/trurl/trurl.h:1.8 poldek/trurlib/include/trurl/trurl.h:1.9
--- poldek/trurlib/include/trurl/trurl.h:1.8	Wed Nov  3 21:12:57 2004
+++ poldek/trurlib/include/trurl/trurl.h	Tue Jun 19 23:52:49 2007
@@ -1,6 +1,6 @@
 /* 
   TRURLib
-  Copyright (C) 1999, 2000 Pawel A. Gajda (mis at k2.net.pl)
+  Copyright (C) 1999 - 2007 Pawel A. Gajda (mis at pld-linux.org)
  
   This library is free software; you can redistribute it and/or
   modify it under the terms of the GNU Library General Public
================================================================

---- CVS-web:
    http://cvs.pld-linux.org/poldek/trurlib/README?r1=1.2&r2=1.3&f=u
    http://cvs.pld-linux.org/poldek/trurlib/n_array_clean.c?r1=1.1&r2=1.2&f=u
    http://cvs.pld-linux.org/poldek/trurlib/n_array_map.c?r1=1.2&r2=1.3&f=u
    http://cvs.pld-linux.org/poldek/trurlib/n_array_map_arg.c?r1=1.2&r2=1.3&f=u
    http://cvs.pld-linux.org/poldek/trurlib/n_array_pop.c?r1=1.1&r2=1.2&f=u
    http://cvs.pld-linux.org/poldek/trurlib/n_array_push.c?r1=1.3&r2=1.4&f=u
    http://cvs.pld-linux.org/poldek/trurlib/n_array_remove_ex.c?r1=1.3&r2=1.4&f=u
    http://cvs.pld-linux.org/poldek/trurlib/n_array_remove_nth.c?r1=1.2&r2=1.3&f=u
    http://cvs.pld-linux.org/poldek/trurlib/n_array_set_nth.c?r1=1.2&r2=1.3&f=u
    http://cvs.pld-linux.org/poldek/trurlib/n_array_shift.c?r1=1.1&r2=1.2&f=u
    http://cvs.pld-linux.org/poldek/trurlib/n_array_uniq_ex.c?r1=1.1&r2=1.2&f=u
    http://cvs.pld-linux.org/poldek/trurlib/n_array_unshift.c?r1=1.2&r2=1.3&f=u
    http://cvs.pld-linux.org/poldek/trurlib/include/trurl/narray.h?r1=1.28&r2=1.29&f=u
    http://cvs.pld-linux.org/poldek/trurlib/include/trurl/ndie.h?r1=1.1&r2=1.2&f=u
    http://cvs.pld-linux.org/poldek/trurlib/include/trurl/trurl.h?r1=1.8&r2=1.9&f=u



More information about the pld-cvs-commit mailing list