unicorn 5.3.1 → 5.5.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (54) hide show
  1. checksums.yaml +5 -5
  2. data/.manifest +2 -0
  3. data/.olddoc.yml +1 -1
  4. data/Application_Timeouts +4 -4
  5. data/Documentation/unicorn.1.txt +1 -1
  6. data/Documentation/unicorn_rails.1.txt +6 -8
  7. data/GIT-VERSION-FILE +1 -1
  8. data/GIT-VERSION-GEN +1 -1
  9. data/GNUmakefile +6 -1
  10. data/ISSUES +10 -10
  11. data/LATEST +22 -102
  12. data/LICENSE +2 -2
  13. data/Links +9 -7
  14. data/NEWS +107 -0
  15. data/README +13 -6
  16. data/Sandbox +2 -2
  17. data/bin/unicorn +3 -1
  18. data/bin/unicorn_rails +2 -2
  19. data/examples/logrotate.conf +1 -1
  20. data/examples/nginx.conf +3 -2
  21. data/ext/unicorn_http/common_field_optimization.h +24 -6
  22. data/ext/unicorn_http/extconf.rb +30 -0
  23. data/ext/unicorn_http/global_variables.h +2 -2
  24. data/ext/unicorn_http/httpdate.c +2 -2
  25. data/ext/unicorn_http/unicorn_http.c +229 -219
  26. data/ext/unicorn_http/unicorn_http.rl +19 -9
  27. data/lib/unicorn/configurator.rb +13 -2
  28. data/lib/unicorn/http_request.rb +2 -2
  29. data/lib/unicorn/http_response.rb +3 -2
  30. data/lib/unicorn/http_server.rb +21 -23
  31. data/lib/unicorn/launcher.rb +1 -1
  32. data/lib/unicorn/socket_helper.rb +4 -3
  33. data/lib/unicorn/util.rb +3 -3
  34. data/lib/unicorn/version.rb +1 -1
  35. data/lib/unicorn/worker.rb +16 -2
  36. data/lib/unicorn.rb +26 -9
  37. data/man/man1/unicorn.1 +7 -5
  38. data/man/man1/unicorn_rails.1 +11 -11
  39. data/t/README +4 -4
  40. data/t/hijack.ru +12 -0
  41. data/t/t0200-rack-hijack.sh +22 -1
  42. data/t/t0301-no-default-middleware-ignored-in-config.sh +25 -0
  43. data/t/t0301.ru +13 -0
  44. data/test/exec/test_exec.rb +6 -7
  45. data/test/unit/test_ccc.rb +1 -1
  46. data/test/unit/test_droplet.rb +1 -1
  47. data/test/unit/test_http_parser.rb +16 -0
  48. data/test/unit/test_request.rb +10 -10
  49. data/test/unit/test_server.rb +5 -5
  50. data/test/unit/test_signals.rb +2 -2
  51. data/test/unit/test_socket_helper.rb +4 -4
  52. data/test/unit/test_util.rb +25 -0
  53. data/unicorn.gemspec +1 -1
  54. metadata +5 -4
@@ -58,26 +58,44 @@ static struct common_field common_http_fields[] = {
58
58
 
59
59
  #define HTTP_PREFIX "HTTP_"
60
60
  #define HTTP_PREFIX_LEN (sizeof(HTTP_PREFIX) - 1)
61
+ static ID id_uminus;
62
+
63
+ /* this dedupes under Ruby 2.5+ (December 2017) */
64
+ static VALUE str_dd_freeze(VALUE str)
65
+ {
66
+ if (STR_UMINUS_DEDUPE)
67
+ return rb_funcall(str, id_uminus, 0);
68
+
69
+ /* freeze,since it speeds up older MRI slightly */
70
+ OBJ_FREEZE(str);
71
+ return str;
72
+ }
73
+
74
+ static VALUE str_new_dd_freeze(const char *ptr, long len)
75
+ {
76
+ return str_dd_freeze(rb_str_new(ptr, len));
77
+ }
61
78
 
62
79
  /* this function is not performance-critical, called only at load time */
63
- static void init_common_fields(VALUE mark_ary)
80
+ static void init_common_fields(void)
64
81
  {
65
82
  int i;
66
83
  struct common_field *cf = common_http_fields;
67
84
  char tmp[64];
85
+
86
+ id_uminus = rb_intern("-@");
68
87
  memcpy(tmp, HTTP_PREFIX, HTTP_PREFIX_LEN);
69
88
 
70
89
  for(i = ARRAY_SIZE(common_http_fields); --i >= 0; cf++) {
71
90
  /* Rack doesn't like certain headers prefixed with "HTTP_" */
72
91
  if (!strcmp("CONTENT_LENGTH", cf->name) ||
73
92
  !strcmp("CONTENT_TYPE", cf->name)) {
74
- cf->value = rb_str_new(cf->name, cf->len);
93
+ cf->value = str_new_dd_freeze(cf->name, cf->len);
75
94
  } else {
76
95
  memcpy(tmp + HTTP_PREFIX_LEN, cf->name, cf->len + 1);
77
- cf->value = rb_str_new(tmp, HTTP_PREFIX_LEN + cf->len);
96
+ cf->value = str_new_dd_freeze(tmp, HTTP_PREFIX_LEN + cf->len);
78
97
  }
79
- cf->value = rb_obj_freeze(cf->value);
80
- rb_ary_push(mark_ary, cf->value);
98
+ rb_gc_register_mark_object(cf->value);
81
99
  }
82
100
  }
83
101
 
@@ -105,7 +123,7 @@ static VALUE uncommon_field(const char *field, size_t flen)
105
123
  memcpy(RSTRING_PTR(f) + HTTP_PREFIX_LEN, field, flen);
106
124
  assert(*(RSTRING_PTR(f) + RSTRING_LEN(f)) == '\0' &&
107
125
  "string didn't end with \\0"); /* paranoia */
108
- return rb_obj_freeze(f);
126
+ return HASH_ASET_DEDUPE ? f : str_dd_freeze(f);
109
127
  }
110
128
 
111
129
  #endif /* common_field_optimization_h */
@@ -8,4 +8,34 @@ have_func("rb_str_set_len", "ruby.h") or abort 'Ruby 1.9.3+ required'
8
8
  have_func("rb_hash_clear", "ruby.h") # Ruby 2.0+
9
9
  have_func("gmtime_r", "time.h")
10
10
 
11
+ message('checking if String#-@ (str_uminus) dedupes... ')
12
+ begin
13
+ a = -(%w(t e s t).join)
14
+ b = -(%w(t e s t).join)
15
+ if a.equal?(b)
16
+ $CPPFLAGS += ' -DSTR_UMINUS_DEDUPE=1 '
17
+ message("yes\n")
18
+ else
19
+ $CPPFLAGS += ' -DSTR_UMINUS_DEDUPE=0 '
20
+ message("no, needs Ruby 2.5+\n")
21
+ end
22
+ rescue NoMethodError
23
+ $CPPFLAGS += ' -DSTR_UMINUS_DEDUPE=0 '
24
+ message("no, String#-@ not available\n")
25
+ end
26
+
27
+ message('checking if Hash#[]= (rb_hash_aset) dedupes... ')
28
+ h = {}
29
+ x = {}
30
+ r = rand.to_s
31
+ h[%W(#{r}).join('')] = :foo
32
+ x[%W(#{r}).join('')] = :foo
33
+ if x.keys[0].equal?(h.keys[0])
34
+ $CPPFLAGS += ' -DHASH_ASET_DEDUPE=1 '
35
+ message("yes\n")
36
+ else
37
+ $CPPFLAGS += ' -DHASH_ASET_DEDUPE=0 '
38
+ message("no, needs Ruby 2.6+\n")
39
+ end
40
+
11
41
  create_makefile("unicorn_http")
@@ -56,7 +56,7 @@ NORETURN(static void parser_raise(VALUE klass, const char *));
56
56
  /** Defines global strings in the init method. */
57
57
  #define DEF_GLOBAL(N, val) do { \
58
58
  g_##N = rb_obj_freeze(rb_str_new(val, sizeof(val) - 1)); \
59
- rb_ary_push(mark_ary, g_##N); \
59
+ rb_gc_register_mark_object(g_##N); \
60
60
  } while (0)
61
61
 
62
62
  /* Defines the maximum allowed lengths for various input elements.*/
@@ -67,7 +67,7 @@ DEF_MAX_LENGTH(FRAGMENT, 1024); /* Don't know if this length is specified somewh
67
67
  DEF_MAX_LENGTH(REQUEST_PATH, 4096); /* common PATH_MAX on modern systems */
68
68
  DEF_MAX_LENGTH(QUERY_STRING, (1024 * 10));
69
69
 
70
- static void init_globals(VALUE mark_ary)
70
+ static void init_globals(void)
71
71
  {
72
72
  DEF_GLOBAL(rack_url_scheme, "rack.url_scheme");
73
73
  DEF_GLOBAL(request_method, "REQUEST_METHOD");
@@ -64,13 +64,13 @@ static VALUE httpdate(VALUE self)
64
64
  return buf;
65
65
  }
66
66
 
67
- void init_unicorn_httpdate(VALUE mark_ary)
67
+ void init_unicorn_httpdate(void)
68
68
  {
69
69
  VALUE mod = rb_define_module("Unicorn");
70
70
  mod = rb_define_module_under(mod, "HttpResponse");
71
71
 
72
72
  buf = rb_str_new(0, buf_capa - 1);
73
- rb_ary_push(mark_ary, buf);
73
+ rb_gc_register_mark_object(buf);
74
74
  buf_ptr = RSTRING_PTR(buf);
75
75
  httpdate(Qnil);
76
76