freebsd-ports/audio/tclmidi/files/patch-rb
Mikhail Teterin e4010ab91b Unbreak and fix:
* Use BSDmakefile (and bsd.lib.mk) instead of
	  configure/Makefile.in;
	* plug some (but not all!) ancient memory leaks;
	* make use of bsd.tcl.mk (now requires Tcl-8.4 or higher);
	* fix warnings and 64-bit issues;
	* bump PORTREVISION.

To do:
	* plug the remaining memory leak (valgrind is priceless!);
	* fix up the author's tests to uniformly report failure or
	  success and arrange for them to run post-build.

Feature safe:	yes
2012-04-11 06:18:00 +00:00

456 lines
12 KiB
Text

--- rb/rb.h 1994-12-05 16:57:58.000000000 -0500
+++ rb/rb.h 2012-04-07 13:21:08.000000000 -0400
@@ -34,38 +34,38 @@
} v;
} *Rb_node;
-#ifndef __P
-#if defined(__STDC__) || defined(__cplusplus)
-#define __P(protos) protos
-#else
-#define __P(protos) ()
-#endif
-#endif
-
+#ifndef EXTERN
#ifdef __cplusplus
#define EXTERN extern "C"
#else
#define EXTERN extern
#endif
+#endif
-EXTERN Rb_node make_rb __P(());
-EXTERN Rb_node rb_insert_b __P((Rb_node node, char *key, char *value));
-
-EXTERN Rb_node rb_find_key __P((Rb_node tree, char *key));
-EXTERN Rb_node rb_find_ikey __P((Rb_node tree, int ikey));
-EXTERN Rb_node rb_find_ukey __P((Rb_node tree, unsigned long ukey));
-EXTERN Rb_node rb_find_gkey __P((Rb_node tree, char *key, int (*fxn)()));
-
-EXTERN Rb_node rb_find_key_n __P((Rb_node tree, char *key, int *found));
-EXTERN Rb_node rb_find_ikey_n __P((Rb_node tree, int ikey, int *found));
-EXTERN Rb_node rb_find_ukey_n __P((Rb_node tree, unsigned long ukey,
- int *found));
-EXTERN Rb_node rb_find_gkey_n __P((Rb_node tree, char *key, int (*fxn)(),
- int *found));
-EXTERN void rb_delete_node __P((Rb_node node));
-EXTERN void rb_free_tree __P((Rb_node node)); /* Deletes and frees an entire tree */
-EXTERN char *rb_val __P((Rb_node node)); /* Returns node->v.val
+typedef int (*Rb_cmp)(const char *key1, const char *key2);
+EXTERN Rb_node make_rb(void);
+EXTERN Rb_node rb_insert_b(Rb_node node, char *key, char *value);
+
+EXTERN Rb_node rb_find_key(Rb_node tree, const char *key);
+EXTERN Rb_node rb_find_ikey(Rb_node tree, int ikey);
+EXTERN Rb_node rb_find_ukey(Rb_node tree, unsigned long ukey);
+EXTERN Rb_node rb_find_gkey(Rb_node tree, const char *key, Rb_cmp);
+
+EXTERN Rb_node rb_find_key_n(Rb_node tree, const char *key, int *found);
+EXTERN Rb_node rb_find_ikey_n(Rb_node tree, int ikey, int *found);
+EXTERN Rb_node rb_find_ukey_n(Rb_node tree, unsigned long ukey,
+ int *found);
+EXTERN Rb_node rb_find_gkey_n(Rb_node tree, const char *key, Rb_cmp,
+ int *found);
+EXTERN void rb_delete_node(Rb_node node);
+EXTERN void rb_free_tree(Rb_node node); /* Deletes and frees an entire tree */
+EXTERN char *rb_val(Rb_node node); /* Returns node->v.val
(this is to shut lint up */
+EXTERN void rb_print_tree(const struct rb_node * const t, int level);
+EXTERN void rb_iprint_tree(const struct rb_node * const t, int level);
+EXTERN void rb_uprint_tree(const struct rb_node * const t, int level);
+EXTERN int rb_nblack(const struct rb_node *t);
+EXTERN int rb_plength(const struct rb_node *t);
#define rb_insert_a(n, k, v) rb_insert_b(n->c.list.flink, k, v)
#define rb_insert(t, k, v) rb_insert_b(rb_find_key(t, k), k, v)
@@ -84,5 +84,5 @@
#define rb_traverse(ptr, lst) \
for(ptr = rb_first(lst); ptr != nil(lst); ptr = rb_next(ptr))
-EXTERN void recolor __P(());
-EXTERN void single_rotate __P(());
+EXTERN void recolor(Rb_node);
+EXTERN void single_rotate(Rb_node, int);
--- rb/rb.c 1994-12-05 16:57:57.000000000 -0500
+++ rb/rb.c 2012-04-07 13:22:05.000000000 -0400
@@ -37,10 +37,8 @@
setnormal(new);\
}
-void
-mk_new_int(l, r, p, il)
- Rb_node l, r, p;
- int il;
+static void
+mk_new_int(Rb_node l, Rb_node r, Rb_node p, int il)
{
Rb_node new;
@@ -71,9 +69,8 @@
}
-Rb_node
-lprev(n)
- Rb_node n;
+static Rb_node
+lprev(Rb_node n)
{
if (ishead(n))
return (n);
@@ -85,9 +82,8 @@
return (n->p.parent);
}
-Rb_node
-rprev(n)
- Rb_node n;
+static Rb_node
+rprev(Rb_node n)
{
if (ishead(n))
return (n);
@@ -109,24 +105,20 @@
head->c.list.flink = head;
head->c.list.blink = head;
head->p.root = head;
- head->k.key = "";
+ /* head->k.key = ""; */
head->v.val = NULL;
sethead(head);
return (head);
}
Rb_node
-rb_find_key_n(n, key, fnd)
- Rb_node n;
- char *key;
- int *fnd;
+rb_find_key_n(Rb_node n, const char *key, int *fnd)
{
int cmp;
*fnd = 0;
if (!ishead(n)) {
- fprintf(stderr, "rb_find_key_n called on non-head 0x%x\n",
- (int)n);
+ fprintf(stderr, "%s called on non-head %p\n", __func__, n);
exit(1);
}
if (n->p.root == n)
@@ -156,9 +148,7 @@
}
Rb_node
-rb_find_key(n, key)
- Rb_node n;
- char *key;
+rb_find_key(Rb_node n, const char *key)
{
int fnd;
@@ -173,8 +163,7 @@
{
*fnd = 0;
if (!ishead(n)) {
- fprintf(stderr, "rb_find_ikey_n called on non-head 0x%x\n",
- (int)n);
+ fprintf(stderr, "%s called on non-head %p\n", __func__, n);
exit(1);
}
if (n->p.root == n)
@@ -208,8 +197,7 @@
*fnd = 0;
if (!ishead(n)) {
- fprintf(stderr, "rb_find_ukey_n called on non-head 0x%x\n",
- (int)n);
+ fprintf(stderr, "%s called on non-head %p\n", __func__, n);
exit(1);
}
if (n->p.root == n)
@@ -255,18 +243,13 @@
}
Rb_node
-rb_find_gkey_n(n, key, fxn, fnd)
- Rb_node n;
- char *key;
- int (*fxn)();
- int *fnd;
+rb_find_gkey_n(Rb_node n, const char *key, Rb_cmp fxn, int *fnd)
{
int cmp;
*fnd = 0;
if (!ishead(n)) {
- fprintf(stderr, "rb_find_key_n called on non-head 0x%x\n",
- (int)n);
+ fprintf(stderr, "%s called on non-head %p\n", __func__, n);
exit(1);
}
if (n->p.root == n)
@@ -296,20 +279,15 @@
}
Rb_node
-rb_find_gkey(n, key, fxn)
- Rb_node n;
- char *key;
- int (*fxn)();
+rb_find_gkey(Rb_node n, const char *key, Rb_cmp fxn)
{
int fnd;
return (rb_find_gkey_n(n, key, fxn, &fnd));
}
+
Rb_node
-rb_insert_b(n, key, val)
- Rb_node n;
- char *key;
- char *val;
+rb_insert_b(Rb_node n, char *key, char *val)
{
Rb_node newleft, newright, newnode, p;
@@ -346,8 +324,7 @@
}
void
-recolor(n)
- Rb_node n;
+recolor(Rb_node n)
{
Rb_node p, gp, s;
int done = 0;
@@ -392,9 +369,7 @@
}
void
-single_rotate(y, l)
- Rb_node y;
- int l;
+single_rotate(Rb_node y, int l)
{
int rl, ir;
Rb_node x, yp;
@@ -440,20 +415,17 @@
}
void
-rb_delete_node(n)
- Rb_node n;
+rb_delete_node(Rb_node n)
{
Rb_node s, p, gp;
char ir;
if (isint(n)) {
- fprintf(stderr, "Cannot delete an internal node: 0x%x\n",
- (int)n);
+ fprintf(stderr, "Cannot delete an internal node: %p\n", n);
exit(1);
}
if (ishead(n)) {
- fprintf(stderr, "Cannot delete the head of an rb_tree: 0x%x\n",
- (int)n);
+ fprintf(stderr, "Cannot delete the head of an rb_tree: %p\n", n);
exit(1);
}
delete_item((List)n); /* Delete it from the list */
@@ -579,120 +551,112 @@
}
void
-rb_print_tree(t, level)
- Rb_node t;
- int level;
+rb_print_tree(const struct rb_node * const t, int level)
{
int i;
if (ishead(t) && t->p.parent == t) {
- printf("tree 0x%x is empty\n",
- (int)t);
+ printf("tree %p is empty\n", t);
} else if (ishead(t)) {
- printf("Head: 0x%x. Root = 0x%x\n", (int)t, (int)t->p.root);
+ printf("Head: %p. Root = %p\n", t, t->p.root);
rb_print_tree(t->p.root, 0);
} else {
if (isext(t)) {
for (i = 0; i < level; i++)
putchar(' ');
- printf("Ext node 0x%x: %c,%c: p=0x%x, k=%s\n", (int)t,
+ printf("Ext node %p: %c,%c: p=%p, k=%s\n", t,
isred(t) ? 'R' : 'B', isleft(t) ? 'l' : 'r',
- (int)t->p.parent, t->k.key);
+ t->p.parent, t->k.key);
} else {
rb_print_tree(t->c.child.left, level + 2);
rb_print_tree(t->c.child.right, level + 2);
for (i = 0; i < level; i++)
putchar(' ');
- printf("Int node 0x%x: %c,%c: l=0x%x, r=0x%x, p=0x%x, lr=(%s,%s)\n",
- (int)t, isred(t) ? 'R' : 'B', isleft(t) ? 'l' : 'r',
- (int)t->c.child.left, (int)t->c.child.right,
- (int)t->p.parent, t->k.lext->k.key,
+ printf("Int node %p: %c,%c: l=%p, r=%p, p=%p, lr=(%s,%s)\n",
+ t, isred(t) ? 'R' : 'B', isleft(t) ? 'l' : 'r',
+ t->c.child.left, t->c.child.right,
+ t->p.parent, t->k.lext->k.key,
t->v.rext->k.key);
}
}
}
void
-rb_iprint_tree(t, level)
- Rb_node t;
- int level;
+rb_iprint_tree(const struct rb_node * const t, int level)
{
int i;
if (ishead(t) && t->p.parent == t) {
- printf("tree 0x%x is empty\n", (int)t);
+ printf("tree %p is empty\n", t);
} else if (ishead(t)) {
- printf("Head: 0x%x. Root = 0x%x, < = 0x%x, > = 0x%x\n",
- (int)t, (int)t->p.root, (int)t->c.list.blink,
- (int)t->c.list.flink);
+ printf("Head: %p. Root = %p, < = %p, > = %p\n",
+ t, t->p.root, t->c.list.blink,
+ t->c.list.flink);
rb_iprint_tree(t->p.root, 0);
} else {
if (isext(t)) {
for (i = 0; i < level; i++)
putchar(' ');
- printf("Ext node 0x%x: %c,%c: p=0x%x, <=0x%x, >=0x%x k=%d\n",
- (int)t, isred(t) ? 'R' : 'B', isleft(t) ? 'l' : 'r',
- (int)t->p.parent, (int)t->c.list.blink,
- (int)t->c.list.flink, t->k.ikey);
+ printf("Ext node %p: %c,%c: p=%p, <=%p, >=%p k=%d\n",
+ t, isred(t) ? 'R' : 'B', isleft(t) ? 'l' : 'r',
+ t->p.parent, t->c.list.blink,
+ t->c.list.flink, t->k.ikey);
} else {
rb_iprint_tree(t->c.child.left, level + 2);
rb_iprint_tree(t->c.child.right, level + 2);
for (i = 0; i < level; i++)
putchar(' ');
- printf("Int node 0x%x: %c,%c: l=0x%x, r=0x%x, p=0x%x, lr=(%d,%d)\n",
- (int)t, isred(t) ? 'R' : 'B', isleft(t) ? 'l' : 'r',
- (int)t->c.child.left, (int)t->c.child.right,
- (int)t->p.parent, t->k.lext->k.ikey,
+ printf("Int node %p: %c,%c: l=%p, r=%p, p=%p, lr=(%d,%d)\n",
+ t, isred(t) ? 'R' : 'B', isleft(t) ? 'l' : 'r',
+ t->c.child.left, t->c.child.right,
+ t->p.parent, t->k.lext->k.ikey,
t->v.rext->k.ikey);
}
}
}
void
-rb_uprint_tree(t, level)
- Rb_node t;
- int level;
+rb_uprint_tree(const struct rb_node * const t, int level)
{
int i;
if (ishead(t) && t->p.parent == t) {
- printf("tree 0x%x is empty\n", (int)t);
+ printf("tree %p is empty\n", t);
} else if (ishead(t)) {
- printf("Head: 0x%x. Root = 0x%x, < = 0x%x, > = 0x%x\n",
- (int)t, (int)t->p.root, (int)t->c.list.blink,
- (int)t->c.list.flink);
+ printf("Head: %p. Root = %p, < = %p, > = %p\n",
+ t, t->p.root, t->c.list.blink,
+ t->c.list.flink);
rb_uprint_tree(t->p.root, 0);
} else {
if (isext(t)) {
for (i = 0; i < level; i++)
putchar(' ');
- printf("Ext node 0x%x: %c,%c: p=0x%x, <=0x%x, >=0x%x k=%lu\n",
- (int)t, isred(t) ? 'R' : 'B', isleft(t) ? 'l' : 'r',
- (int)t->p.parent, (int)t->c.list.blink,
- (int)t->c.list.flink, t->k.ukey);
+ printf("Ext node %p: %c,%c: p=%p, <=%p, >=%p k=%lu\n",
+ t, isred(t) ? 'R' : 'B', isleft(t) ? 'l' : 'r',
+ t->p.parent, t->c.list.blink,
+ t->c.list.flink, t->k.ukey);
} else {
rb_uprint_tree(t->c.child.left, level + 2);
rb_uprint_tree(t->c.child.right, level + 2);
for (i = 0; i < level; i++)
putchar(' ');
- printf("Int node 0x%x: %c,%c: l=0x%x, r=0x%x, p=0x%x, lr=(%lu,%lu)\n",
- (int)t, isred(t) ? 'R' : 'B', isleft(t) ? 'l' : 'r',
- (int)t->c.child.left, (int)t->c.child.right,
- (int)t->p.parent, t->k.lext->k.ukey,
+ printf("Int node %p: %c,%c: l=%p, r=%p, p=%p, lr=(%lu,%lu)\n",
+ t, isred(t) ? 'R' : 'B', isleft(t) ? 'l' : 'r',
+ t->c.child.left, t->c.child.right,
+ t->p.parent, t->k.lext->k.ukey,
t->v.rext->k.ukey);
}
}
}
int
-rb_nblack(n)
- Rb_node(n);
+rb_nblack(const struct rb_node *n)
{
int nb;
if (ishead(n) || isint(n)) {
fprintf(stderr,
- "ERROR: rb_nblack called on a non-external node 0x%x\n",
- (int)n);
+ "ERROR: %s called on a non-external node %p\n",
+ __func__, n);
exit(1);
}
nb = 0;
@@ -705,15 +669,14 @@
}
int
-rb_plength(n)
- Rb_node(n);
+rb_plength(const struct rb_node *n)
{
int pl;
if (ishead(n) || isint(n)) {
fprintf(stderr,
- "ERROR: rb_plength called on a non-external node 0x%x\n",
- (int)n);
+ "ERROR: %s called on a non-external node %p\n",
+ __func__, n);
exit(1);
}
pl = 0;
@@ -725,13 +688,11 @@
}
void
-rb_free_tree(n)
- Rb_node(n);
+rb_free_tree(Rb_node n)
{
if (!ishead(n)) {
- fprintf(stderr,
- "ERROR: Rb_free_tree called on a non-head node\n");
+ fprintf(stderr, "%s called on non-head %p\n", __func__, n);
exit(1);
}
while (rb_first(n) != nil(n)) {