* [PATCH] use rb_gc_register_mark_object
@ 2018-12-26 4:19 Eric Wong
0 siblings, 0 replies; only message in thread
From: Eric Wong @ 2018-12-26 4:19 UTC (permalink / raw)
To: kcar-public; +Cc: Eric Wong
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
^ permalink raw reply related [flat|nested] only message in thread
only message in thread, other threads:[~2018-12-26 4:19 UTC | newest]
Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-12-26 4:19 [PATCH] use rb_gc_register_mark_object Eric Wong
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).