clogger RubyGem user+dev discussion/patches/pulls/bugs/help
 help / Atom feed
* [PATCH] ext: avoid clobbering existing system functions
@ 2016-07-28  0:06 Eric Wong
  0 siblings, 0 replies; 1+ messages in thread
From: Eric Wong @ 2016-07-28  0:06 UTC (permalink / raw)
  To: clogger-public

These defines may cause incompatibilities if Ruby or other
system headers decide to clobber these.  It's also confusing to
override existing, well-known-and-standardized functions.
---
 ext/clogger_ext/blocking_helpers.h | 7 +++++--
 ext/clogger_ext/clogger.c          | 4 ++--
 2 files changed, 7 insertions(+), 4 deletions(-)

diff --git a/ext/clogger_ext/blocking_helpers.h b/ext/clogger_ext/blocking_helpers.h
index c03c2f5..15634b8 100644
--- a/ext/clogger_ext/blocking_helpers.h
+++ b/ext/clogger_ext/blocking_helpers.h
@@ -54,6 +54,9 @@ static ssize_t my_write(int fd, const void *buf, size_t count)
 
 	return r;
 }
-#  define stat(path,buf) my_stat((path),(buf))
-#  define write(fd,buf,count) my_write((fd),(buf),(count))
+#  define nogvl_stat(path,buf) my_stat((path),(buf))
+#  define nogvl_write(fd,buf,count) my_write((fd),(buf),(count))
+#else /* !WITHOUT_GVL, for Ruby 1.8 users: */
+#  define nogvl_stat(path,buf) stat((path),(buf))
+#  define nogvl_write(fd,buf,buf) write((fd),(buf),(count))
 #endif /* !WITHOUT_GVL */
diff --git a/ext/clogger_ext/clogger.c b/ext/clogger_ext/clogger.c
index 3db9235..f29cf26 100644
--- a/ext/clogger_ext/clogger.c
+++ b/ext/clogger_ext/clogger.c
@@ -243,7 +243,7 @@ static void write_full(int fd, const char *buf, size_t count)
 	ssize_t r;
 
 	while (count > 0) {
-		r = write(fd, buf, count);
+		r = nogvl_write(fd, buf, count);
 
 		if ((size_t)r == count) { /* overwhelmingly likely */
 			return;
@@ -993,7 +993,7 @@ static VALUE to_path(VALUE self)
 	if (sscanf(cpath, "/dev/fd/%u", &devfd) == 1)
 		rv = fstat((int)devfd, &sb);
 	else
-		rv = stat(cpath, &sb);
+		rv = nogvl_stat(cpath, &sb);
 
 	/*
 	 * calling this method implies the web server will bypass
-- 
EW


^ permalink raw reply	[flat|nested] 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 --
2016-07-28  0:06 [PATCH] ext: avoid clobbering existing system functions Eric Wong

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

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

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

 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