clogger RubyGem user+dev discussion/patches/pulls/bugs/help
 help / color / mirror / code / Atom feed
From: Eric Wong <e@80x24.org>
To: clogger-public@bogomips.org
Subject: [PATCH] ext: avoid clobbering existing system functions
Date: Thu, 28 Jul 2016 00:06:46 +0000	[thread overview]
Message-ID: <20160728000646.24527-1-e@80x24.org> (raw)

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


                 reply	other threads:[~2016-07-28  0:06 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/clogger/

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

  git send-email \
    --in-reply-to=20160728000646.24527-1-e@80x24.org \
    --to=e@80x24.org \
    --cc=clogger-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/clogger.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).