unicorn Ruby/Rack server user+dev discussion/patches/pulls/bugs/help
 help / color / mirror / code / Atom feed
From: Eric Wong <bofh@yhbt.net>
To: unicorn-public@yhbt.net
Subject: [PATCH 1/6] extconf.rb: get rid of unnecessary checks
Date: Fri,  1 Oct 2021 03:09:18 +0000	[thread overview]
Message-ID: <20211001030923.26705-2-bofh@yhbt.net> (raw)
In-Reply-To: <20211001030923.26705-1-bofh@yhbt.net>

SIZEOF_*, *2NUM and NUM2* should all be defined by ruby.h and
dependencies it pulls in since Ruby 2.0 and possibly earlier.

INT_MAX and LLONG_MAX are in limits.h which is POSIX.

HAVE_GMTIME_R is already defined by ruby/config.h, so we
shouldn't have to check for it, either.

Combined, these changes speed up extconf.rb by several seconds.
---
 ext/unicorn_http/c_util.h   | 18 +++++-------------
 ext/unicorn_http/ext_help.h | 24 ------------------------
 ext/unicorn_http/extconf.rb |  5 -----
 ext/unicorn_http/httpdate.c |  1 +
 4 files changed, 6 insertions(+), 42 deletions(-)

diff --git a/ext/unicorn_http/c_util.h b/ext/unicorn_http/c_util.h
index ab1fc0e..5774615 100644
--- a/ext/unicorn_http/c_util.h
+++ b/ext/unicorn_http/c_util.h
@@ -8,23 +8,15 @@
 
 #include <unistd.h>
 #include <assert.h>
+#include <limits.h>
 
 #define MIN(a,b) (a < b ? a : b)
 #define ARRAY_SIZE(x) (sizeof(x)/sizeof(x[0]))
 
-#ifndef SIZEOF_OFF_T
-#  define SIZEOF_OFF_T 4
-#  warning SIZEOF_OFF_T not defined, guessing 4.  Did you run extconf.rb?
-#endif
-
-#if SIZEOF_OFF_T == 4
-#  define UH_OFF_T_MAX 0x7fffffff
-#elif SIZEOF_OFF_T == 8
-#  if SIZEOF_LONG == 4
-#    define UH_OFF_T_MAX 0x7fffffffffffffffLL
-#  else
-#    define UH_OFF_T_MAX 0x7fffffffffffffff
-#  endif
+#if SIZEOF_OFF_T == SIZEOF_INT
+#  define UH_OFF_T_MAX INT_MAX
+#elif SIZEOF_OFF_T == SIZEOF_LONG_LONG
+#  define UH_OFF_T_MAX LLONG_MAX
 #else
 #  error off_t size unknown for this platform!
 #endif /* SIZEOF_OFF_T check */
diff --git a/ext/unicorn_http/ext_help.h b/ext/unicorn_http/ext_help.h
index 747c36c..86a187e 100644
--- a/ext/unicorn_http/ext_help.h
+++ b/ext/unicorn_http/ext_help.h
@@ -8,30 +8,6 @@
 #  define assert_frozen(f) do {} while (0)
 #endif /* !defined(OBJ_FROZEN) */
 
-#if !defined(OFFT2NUM)
-#  if SIZEOF_OFF_T == SIZEOF_LONG
-#    define OFFT2NUM(n) LONG2NUM(n)
-#  else
-#    define OFFT2NUM(n) LL2NUM(n)
-#  endif
-#endif /* ! defined(OFFT2NUM) */
-
-#if !defined(SIZET2NUM)
-#  if SIZEOF_SIZE_T == SIZEOF_LONG
-#    define SIZET2NUM(n) ULONG2NUM(n)
-#  else
-#    define SIZET2NUM(n) ULL2NUM(n)
-#  endif
-#endif /* ! defined(SIZET2NUM) */
-
-#if !defined(NUM2SIZET)
-#  if SIZEOF_SIZE_T == SIZEOF_LONG
-#    define NUM2SIZET(n) ((size_t)NUM2ULONG(n))
-#  else
-#    define NUM2SIZET(n) ((size_t)NUM2ULL(n))
-#  endif
-#endif /* ! defined(NUM2SIZET) */
-
 static inline int str_cstr_eq(VALUE val, const char *ptr, long len)
 {
   return (RSTRING_LEN(val) == len && !memcmp(ptr, RSTRING_PTR(val), len));
diff --git a/ext/unicorn_http/extconf.rb b/ext/unicorn_http/extconf.rb
index 8bdc1c9..46070a7 100644
--- a/ext/unicorn_http/extconf.rb
+++ b/ext/unicorn_http/extconf.rb
@@ -6,12 +6,7 @@
        "It might not properly work with #{RUBY_VERSION}"
 end
 
-have_macro("SIZEOF_OFF_T", "ruby.h") or check_sizeof("off_t", "sys/types.h")
-have_macro("SIZEOF_SIZE_T", "ruby.h") or check_sizeof("size_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") or abort 'Ruby 2.0+ required'
 have_func("rb_hash_clear", "ruby.h") or abort 'Ruby 2.0+ required'
-have_func("gmtime_r", "time.h")
 
 message('checking if String#-@ (str_uminus) dedupes... ')
 begin
diff --git a/ext/unicorn_http/httpdate.c b/ext/unicorn_http/httpdate.c
index b59d038..3f512dd 100644
--- a/ext/unicorn_http/httpdate.c
+++ b/ext/unicorn_http/httpdate.c
@@ -11,6 +11,7 @@ static const char months[] = "Jan\0Feb\0Mar\0Apr\0May\0Jun\0"
 
 /* for people on wonky systems only */
 #ifndef HAVE_GMTIME_R
+# warning using fake gmtime_r
 static struct tm * my_gmtime_r(time_t *now, struct tm *tm)
 {
 	struct tm *global = gmtime(now);

  reply	other threads:[~2021-10-01  3:09 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-10-01  3:09 [PATCH 0/6] reduce thundering herds on Linux 4.5+ Eric Wong
2021-10-01  3:09 ` Eric Wong [this message]
2021-10-01  3:09 ` [PATCH 2/6] makefile: reduce unnecessary rebuilds Eric Wong
2021-10-01  3:09 ` [PATCH 3/6] HACKING: drop outdated information about pandoc Eric Wong
2021-10-01  3:09 ` [PATCH 4/6] http_server: get rid of Process.ppid check Eric Wong
2021-10-01  3:09 ` [PATCH 5/6] worker_loop: get rid of select() avoidance hack Eric Wong
2021-10-01  3:09 ` [PATCH 6/6] use EPOLLEXCLUSIVE on Linux 4.5+ 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/unicorn/

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

  git send-email \
    --in-reply-to=20211001030923.26705-2-bofh@yhbt.net \
    --to=bofh@yhbt.net \
    --cc=unicorn-public@yhbt.net \
    --subject='Re: [PATCH 1/6] extconf.rb: get rid of unnecessary checks' \
    /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

Code repositories for project(s) associated with this inbox:

	../../unicorn.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).