From: Eric Wong <normalperson@yhbt.net>
To: kcar@librelist.org
Subject: [PATCH] use rb_fstring from Ruby 2.1.0dev if available
Date: Sat, 12 Oct 2013 03:18:36 +0000 [thread overview]
Message-ID: <1381547916-7599-1-git-send-email-normalperson@yhbt.net> (raw)
In-Reply-To: <1381547916-7599-1-git-send-email-normalperson@yhbt.net>
This should be safe after r43210 from ruby trunk
---
ext/kcar/extconf.rb | 1 +
ext/kcar/kcar.rl | 12 +++++++++++-
2 files changed, 12 insertions(+), 1 deletion(-)
diff --git a/ext/kcar/extconf.rb b/ext/kcar/extconf.rb
index 4f19c4a..1ac6847 100644
--- a/ext/kcar/extconf.rb
+++ b/ext/kcar/extconf.rb
@@ -7,6 +7,7 @@ have_macro("SIZEOF_OFF_T", "ruby.h") or check_sizeof("off_t", "sys/types.h")
have_macro("SIZEOF_LONG", "ruby.h") or check_sizeof("long", "sys/types.h")
have_func("rb_str_set_len", "ruby.h")
have_func("rb_str_modify", "ruby.h")
+have_func("rb_fstring", "ruby.h")
# -fPIC is needed for Rubinius, MRI already uses it regardless
with_cflags($CFLAGS + " -fPIC ") do
diff --git a/ext/kcar/kcar.rl b/ext/kcar/kcar.rl
index e812279..7d3f9ae 100644
--- a/ext/kcar/kcar.rl
+++ b/ext/kcar/kcar.rl
@@ -192,6 +192,16 @@ static void write_cont_value(struct http_parser *hp,
rb_str_buf_cat(hp->cont, vptr, end + 1);
}
+#ifndef HAVE_RB_FSTRING
+static VALUE my_fstring(VALUE str)
+{
+ OBJ_FREEZE(str);
+
+ return str;
+}
+#define rb_fstring(str) my_fstring((str))
+#endif /* !HAVE_RB_FSTRING */
+
static void write_value(VALUE hdr, struct http_parser *hp,
const char *buffer, const char *p)
{
@@ -273,7 +283,7 @@ static void write_value(VALUE hdr, struct http_parser *hp,
if (NIL_P(e)) {
/* new value, freeze it since it speeds up MRI slightly */
- OBJ_FREEZE(f);
+ f = rb_fstring(f);
if (hclass == rb_cHash)
rb_hash_aset(hdr, f, v);
--
1.8.4
next parent reply other threads:[~2013-10-12 3:18 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-10-12 3:18 Eric Wong [this message]
2013-10-12 6:59 ` [PATCH] use rb_fstring from Ruby 2.1.0dev if available Eric Wong
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=1381547916-7599-1-git-send-email-normalperson@yhbt.net \
--to=normalperson@yhbt.net \
--cc=kcar@librelist.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).