raindrops RubyGem user+dev discussion/patches/pulls/bugs/help
 help / Atom feed
* [PATCH] linux_inet_diag: clarify *fprintf usage without GVL
@ 2015-01-14  0:25 Eric Wong
  0 siblings, 0 replies; 1+ messages in thread
From: Eric Wong @ 2015-01-14  0:25 UTC (permalink / raw)
  To: raindrops-public; +Cc: Eric Wong

A reviewer may wonder why fprintf is chosen instead of rb_warn,
so make it clear we're outside of the GVL when spewing the
warning message and cannot use most rb_* functions.
---
 ext/raindrops/linux_inet_diag.c | 15 ++++++++++-----
 1 file changed, 10 insertions(+), 5 deletions(-)

diff --git a/ext/raindrops/linux_inet_diag.c b/ext/raindrops/linux_inet_diag.c
index fa8de03..5f21295 100644
--- a/ext/raindrops/linux_inet_diag.c
+++ b/ext/raindrops/linux_inet_diag.c
@@ -1,4 +1,5 @@
 #include <ruby.h>
+#include <stdarg.h>
 #ifdef HAVE_RUBY_ST_H
 #  include <ruby/st.h>
 #else
@@ -213,8 +214,14 @@ static const char *addr_any(sa_family_t family)
 	return ipv6;
 }
 
-static void bug_warn(void)
+static void bug_warn_nogvl(const char *fmt, ...)
 {
+	va_list ap;
+
+	va_start(ap, fmt);
+	vfprintf(stderr, fmt, ap);
+	va_end(ap);
+
 	fprintf(stderr, "Please report how you produced this at "\
 	                "raindrops-public@bogomips.org\n");
 	fflush(stderr);
@@ -263,8 +270,7 @@ static struct listen_stats *stats_for(st_table *table, struct inet_diag_msg *r)
 		assert(0 && "unsupported address family, could that be IPv7?!");
 	}
 	if (rc != 0) {
-		fprintf(stderr, "BUG: getnameinfo: %s\n", gai_strerror(rc));
-		bug_warn();
+		bug_warn_nogvl("BUG: getnameinfo: %s\n", gai_strerror(rc));
 		*key = 0;
 	}
 
@@ -296,8 +302,7 @@ static struct listen_stats *stats_for(st_table *table, struct inet_diag_msg *r)
 				 addr_any(sa.ss.ss_family),
 				 ntohs(r->id.idiag_sport));
 		if (n <= 0) {
-			fprintf(stderr, "BUG: snprintf: %d\n", n);
-			bug_warn();
+			bug_warn_nogvl("BUG: snprintf: %d\n", n);
 		}
 		if (st_lookup(table, (st_data_t)key, (st_data_t *)&stats))
 			return stats;
-- 
EW


^ permalink raw reply	[flat|threaded] 1+ messages in thread

only message in thread, back to index

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-01-14  0:25 [PATCH] linux_inet_diag: clarify *fprintf usage without GVL Eric Wong

raindrops RubyGem user+dev discussion/patches/pulls/bugs/help

Archives are clonable:
	git clone --mirror https://bogomips.org/raindrops-public
	git clone --mirror http://ou63pmih66umazou.onion/raindrops-public

Newsgroups are available over NNTP:
	nntp://news.public-inbox.org/inbox.comp.lang.ruby.raindrops
	nntp://ou63pmih66umazou.onion/inbox.comp.lang.ruby.raindrops

 note: .onion URLs require Tor: https://www.torproject.org/
       or Tor2web: https://www.tor2web.org/

AGPL code for this site: git clone https://public-inbox.org/ public-inbox