public
Description: A very fast & simple Ruby web server
Homepage: http://code.macournoyer.com/thin/
Clone URL: git://github.com/macournoyer/thin.git
Search Repo:
use realloc to grow array
macournoyer (author)
Sun Apr 06 20:35:00 -0700 2008
commit  c9e64894ddd0f67cc5636924f710433d287d2ccf
tree    fbbb1c54a3c7f252b561a0842e8e4c07e22fd02b
parent  c07fdb176e82ed045c867bc153cdd7df05b738fb
...
21
22
23
24
25
 
26
27
28
 
 
 
 
29
30
31
 
32
33
34
35
36
 
37
38
39
40
41
42
43
...
21
22
23
 
 
24
25
26
27
28
29
30
31
32
33
 
34
35
36
 
 
 
37
38
39
 
 
40
41
42
0
@@ -21,23 +21,22 @@
0
 
0
 void * array_push(array_t *a)
0
 {
0
- void *item, *old, *new;
0
- size_t size;
0
+ void *item;
0
   
0
   if (a->nitems == a->nalloc) {
0
     /* array is full, double the size */
0
+
0
+ void *new;
0
+ size_t size;
0
+
0
     size = a->size * a->nalloc;
0
 
0
- new = malloc(2 * size);
0
+ new = realloc(a->items, 2 * size);
0
     if (new == NULL)
0
       return NULL;
0
-
0
- memcpy(new, a->items, size);
0
- old = a->items;
0
+
0
     a->items = new;
0
     a->nalloc *= 2;
0
-
0
- free(old);
0
   }
0
   
0
   item = (u_char *) a->items + a->size * a->nitems;
...
47
48
49
50
 
51
52
53
...
300
301
302
303
 
304
305
306
...
310
311
312
 
313
314
315
...
47
48
49
 
50
51
52
53
...
300
301
302
 
303
304
305
306
...
310
311
312
313
314
315
316
0
@@ -47,7 +47,7 @@
0
   connection_t *c = get_ev_data(connection, watcher, read);
0
   size_t n;
0
   char buf[BUFFER_SIZE];
0
-
0
+
0
   n = recv(c->fd, buf, BUFFER_SIZE, 0);
0
   
0
   if (n == -1) {
0
@@ -300,7 +300,7 @@
0
   /* Intern some Ruby string */
0
   sInternedCall = rb_intern("call");
0
   sInternedKeys = rb_intern("keys");
0
- sRackInput = rb_obj_freeze(rb_str_new2("rack.input"));
0
+ sRackInput = rb_obj_freeze(rb_str_new2("rack.input"));
0
 }
0
 
0
 void connections_create(array_t *connections, size_t num)
0
@@ -310,6 +310,7 @@
0
   
0
   for (i = 0; i <= num; ++i) {
0
     connection = array_push(connections);
0
+ assert(connection);
0
     connection->open = 0;
0
     parser_callbacks_setup(connection);
0
   }
...
32
33
34
35
36
37
38
39
...
32
33
34
 
 
35
36
37
0
@@ -32,8 +32,6 @@
0
 #define CONNECTIONS_SIZE 100
0
 #define BUFFER_SLICES (80 + 32) /* big enough so we can fit MAX_HEADER */
0
 #define BUFFER_SIZE 1024
0
-
0
-/* TODO move this to parser ... */
0
 #define MAX_HEADER 1024 * (80 + 32)
0
 
0
 

Comments

    No one has commented yet.