about summary refs log tree commit homepage
diff options
context:
space:
mode:
authorEric Wong <e@80x24.org>2018-12-26 04:15:27 +0000
committerEric Wong <e@80x24.org>2018-12-26 04:15:27 +0000
commit979187f20e341831055a752fcfa9fce1fe56274c (patch)
tree0e289d8c72a9e98c0f7e6f4a44689f8f54ab8e45
parent94bc4406455923acecb532714c9643cf9940722c (diff)
downloadkcar-979187f20e341831055a752fcfa9fce1fe56274c.tar.gz
Since Ruby 2.6, it's a documented part of the API and we may depend
on it: https://bugs.ruby-lang.org/issues/9894

(it's been around since the early Ruby 1.9 days)
-rw-r--r--ext/kcar/kcar.rl50
1 files changed, 23 insertions, 27 deletions
diff --git a/ext/kcar/kcar.rl b/ext/kcar/kcar.rl
index 32b29d5..684466e 100644
--- a/ext/kcar/kcar.rl
+++ b/ext/kcar/kcar.rl
@@ -1076,7 +1076,6 @@ static VALUE filter_body(VALUE self, VALUE dst, VALUE src)
 
 void Init_kcar_ext(void)
 {
-  static VALUE globals;
   VALUE mKcar = rb_define_module("Kcar");
   VALUE cParser = rb_define_class_under(mKcar, "Parser", rb_cObject);
 
@@ -1123,34 +1122,31 @@ void Init_kcar_ext(void)
   id_uminus = rb_intern("-@");
 
   /* TODO: gperf to make a perfect hash of common strings */
-#define C(ary, var, cstr) do { \
+#define C(var, cstr) do { \
   var = str_new_dd_freeze((cstr), sizeof(cstr) - 1); \
-  rb_ary_push((ary), (var)); \
+  rb_gc_register_mark_object((var)); \
 } while (0);
 
-  globals = rb_ary_new();
-  rb_global_variable(&globals);
-  C(globals, g_CONTENT_LENGTH, "CONTENT_LENGTH");
-  C(globals, g_CONTENT_TYPE, "CONTENT_TYPE");
-  C(globals, g_FRAGMENT, "FRAGMENT");
-  C(globals, g_HTTP_HOST, "HTTP_HOST");
-  C(globals, g_HTTP_CONNECTION, "HTTP_CONNECTION");
-  C(globals, g_HTTP_TRAILER, "HTTP_TRAILER");
-  C(globals, g_HTTP_TRANSFER_ENCODING, "HTTP_TRANSFER_ENCODING");
-  C(globals, g_HTTP_VERSION, "HTTP_VERSION");
-  C(globals, g_PATH_INFO, "PATH_INFO");
-  C(globals, g_QUERY_STRING, "QUERY_STRING");
-  C(globals, g_REQUEST_METHOD, "REQUEST_METHOD");
-  C(globals, g_REQUEST_PATH, "REQUEST_PATH");
-  C(globals, g_REQUEST_URI, "REQUEST_URI");
-  C(globals, g_SERVER_NAME, "SERVER_NAME");
-  C(globals, g_SERVER_PORT, "SERVER_PORT");
-  C(globals, g_SERVER_PROTOCOL, "SERVER_PROTOCOL");
-  C(globals, g_rack_url_scheme, "rack.url_scheme");
-  C(globals, g_http, "http");
-  C(globals, g_https, "https");
-  C(globals, g_80, "80");
-  C(globals, g_443, "443");
-  OBJ_FREEZE(globals);
+  C(g_CONTENT_LENGTH, "CONTENT_LENGTH");
+  C(g_CONTENT_TYPE, "CONTENT_TYPE");
+  C(g_FRAGMENT, "FRAGMENT");
+  C(g_HTTP_HOST, "HTTP_HOST");
+  C(g_HTTP_CONNECTION, "HTTP_CONNECTION");
+  C(g_HTTP_TRAILER, "HTTP_TRAILER");
+  C(g_HTTP_TRANSFER_ENCODING, "HTTP_TRANSFER_ENCODING");
+  C(g_HTTP_VERSION, "HTTP_VERSION");
+  C(g_PATH_INFO, "PATH_INFO");
+  C(g_QUERY_STRING, "QUERY_STRING");
+  C(g_REQUEST_METHOD, "REQUEST_METHOD");
+  C(g_REQUEST_PATH, "REQUEST_PATH");
+  C(g_REQUEST_URI, "REQUEST_URI");
+  C(g_SERVER_NAME, "SERVER_NAME");
+  C(g_SERVER_PORT, "SERVER_PORT");
+  C(g_SERVER_PROTOCOL, "SERVER_PROTOCOL");
+  C(g_rack_url_scheme, "rack.url_scheme");
+  C(g_http, "http");
+  C(g_https, "https");
+  C(g_80, "80");
+  C(g_443, "443");
 #undef C
 }