shithub: c9

Download patch

ref: 7de1a0ced784278b3d586496f78016a17a4495a6
parent: a5eae67d27af9422a4460f9e3137a6765ae02012
author: Sigrid <sigrid.haflinadottir@gmail.com>
date: Tue Jan 17 16:55:06 EST 2017

tag is two bytes

--- a/c9.c
+++ b/c9.c
@@ -104,7 +104,7 @@
 	}
 
 	if(c->lowfreetag < C9maxtags){
-		uint32_t d = c->lowfreetag / C9tagbits, m = c->lowfreetag % C9tagbits;
+		uint32_t d = c->lowfreetag / C9tagsbits, m = c->lowfreetag % C9tagsbits;
 		if((c->tags[d] & 1<<m) != 0){
 			c->tags[d] &= ~(1<<m);
 			*tag = c->lowfreetag++;
@@ -116,10 +116,10 @@
 		uint32_t x, j;
 		if((x = c->tags[i]) == 0)
 			continue;
-		for(j = 0; j < C9tagbits; j++){
+		for(j = 0; j < C9tagsbits; j++){
 			if((x & (1<<j)) != 0){
 				c->tags[i] &= ~(1<<j);
-				*tag = i*C9tagbits + j;
+				*tag = i*C9tagsbits + j;
 				c->lowfreetag = *tag + 1;
 				return 0;
 			}
@@ -134,7 +134,7 @@
 freetag(C9ctx *c, C9tag tag)
 {
 	if(tag != 0xffff){
-		uint32_t d = tag / C9tagbits, m = tag % C9tagbits;
+		uint32_t d = tag / C9tagsbits, m = tag % C9tagsbits;
 		if(tag >= C9maxtags){
 			c->error("freetag: invalid tag");
 			return -1;
--- a/c9.h
+++ b/c9.h
@@ -9,7 +9,7 @@
 typedef enum C9ttype C9ttype;
 typedef enum C9qt C9qt;
 typedef uint32_t C9fid;
-typedef uint32_t C9tag;
+typedef uint16_t C9tag;
 
 /* Stat field is not changed if it's set to this value when calling c9wstat. */
 #define C9nochange (~0)
@@ -256,7 +256,7 @@
 
 enum
 {
-	C9tagbits = sizeof(uint32_t) * 8,
+	C9tagsbits = sizeof(uint32_t) * 8,
 };
 
 struct C9ctx
@@ -292,8 +292,8 @@
 
 	/* private stuff */
 	uint32_t msize;
-	uint32_t tags[C9maxtags/C9tagbits];
 	uint32_t flush[C9maxflush];
+	uint32_t tags[C9maxtags/C9tagsbits];
 	union
 	{
 		C9tag lowfreetag;