kcar RubyGem user+dev discussion/patches/pulls/bugs/help
 help / color / mirror / code / Atom feed
From: Eric Wong <e@80x24.org>
To: kcar-public@bogomips.org
Cc: Eric Wong <e@80x24.org>
Subject: [PATCH] use rb_gc_register_mark_object
Date: Wed, 26 Dec 2018 04:19:31 +0000	[thread overview]
Message-ID: <20181226041931.31075-1-e@80x24.org> (raw)

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)
---
 ext/kcar/kcar.rl | 50 ++++++++++++++++++++++--------------------------
 1 file 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
 }
-- 
EW


                 reply	other threads:[~2018-12-26  4:19 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://yhbt.net/kcar/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20181226041931.31075-1-e@80x24.org \
    --to=e@80x24.org \
    --cc=kcar-public@bogomips.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://yhbt.net/kcar.git/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).