From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.3.2 (2011-06-06) on dcvr.yhbt.net X-Spam-Level: X-Spam-ASN: AS6939 64.71.128.0/18 X-Spam-Status: No, score=-1.9 required=3.0 tests=AWL,BAYES_00, MSGID_FROM_MTA_HEADER shortcircuit=no autolearn=unavailable version=3.3.2 Path: news.gmane.org!not-for-mail From: Eric Wong Newsgroups: gmane.comp.lang.ruby.clogger.general Subject: [PATCH] attempt to support broken/crazy systems Date: Thu, 13 Jan 2011 00:37:08 +0000 Message-ID: <20110113003708.GA13256@dcvr.yhbt.net> References: <20110113003708.GA13256@dcvr.yhbt.net> NNTP-Posting-Host: lo.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit X-Trace: dough.gmane.org 1294879050 11371 80.91.229.12 (13 Jan 2011 00:37:30 GMT) X-Complaints-To: usenet@dough.gmane.org NNTP-Posting-Date: Thu, 13 Jan 2011 00:37:30 +0000 (UTC) To: clogger@librelist.org Original-X-From: clogger@librelist.org Thu Jan 13 01:37:20 2011 Return-path: Envelope-to: gcrcg-clogger@m.gmane.org In-Reply-To: <20110113003708.GA13256@dcvr.yhbt.net> List-Archive: List-Help: List-Id: List-Post: List-Subscribe: List-Unsubscribe: Precedence: list Original-Sender: clogger@librelist.org Xref: news.gmane.org gmane.comp.lang.ruby.clogger.general:42 Archived-At: Received: from zedshaw.xen.prgmr.com ([64.71.167.205]) by lo.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1PdBBl-0000BB-Sm for gcrcg-clogger@m.gmane.org; Thu, 13 Jan 2011 01:37:18 +0100 Received: from zedshaw.xen.prgmr.com (localhost [IPv6:::1]) by zedshaw.xen.prgmr.com (Postfix) with ESMTP id 59E9F21C62E for ; Thu, 13 Jan 2011 00:50:09 +0000 (UTC) I've just pushed this out to git://git.bogomips.org/clogger.git If you're using a crazy, non-Free OS[1] favored by many Rubyists, please tell me if it works or not with this patch. [1] - I don't and will never endorse non-Free Software nor any for-profit organizations in my Free Software works. >>From 6cc7e96f972d9a648bef9d49ca245282250a5502 Mon Sep 17 00:00:00 2001 From: Eric Wong Date: Wed, 12 Jan 2011 16:24:23 -0800 Subject: [PATCH] attempt to support broken/crazy systems clock_gettime() is not available on some systems and/or CLOCK_MONOTONIC. This is totally broken considering the POSIX standard was 10 years ago, now. Nothing in gnulib, either, wtf?! http://www.gnu.org/software/gnulib/manual/html_node/clock_005fgettime.html --- ext/clogger_ext/broken_system_compat.h | 27 +++++++++++++++++++++++++++ ext/clogger_ext/clogger.c | 1 + ext/clogger_ext/extconf.rb | 1 + 3 files changed, 29 insertions(+), 0 deletions(-) create mode 100644 ext/clogger_ext/broken_system_compat.h diff --git a/ext/clogger_ext/broken_system_compat.h b/ext/clogger_ext/broken_system_compat.h new file mode 100644 index 0000000..f58307e --- /dev/null +++ b/ext/clogger_ext/broken_system_compat.h @@ -0,0 +1,27 @@ +/* + * this header includes functions to support broken systems + * without clock_gettime() or CLOCK_MONOTONIC + */ + +#ifndef HAVE_CLOCK_GETTIME +# ifndef CLOCK_REALTIME +# define CLOCK_REALTIME 0 /* whatever */ +# endif +static int fake_clock_gettime(int clk_id, struct timespec *res) +{ + struct timeval tv; + int r = gettimeofday(&tv, NULL); + + assert(0 == r && "gettimeofday() broke!?"); + res->tv_sec = tv.tv_sec; + res->tv_nsec = tv.tv_usec * 1000; + + return r; +} +# define clock_gettime fake_clock_gettime +#endif /* broken systems w/o clock_gettime() */ + +/* UGH */ +#ifndef _POSIX_MONOTONIC_CLOCK +# define CLOCK_MONOTONIC CLOCK_REALTIME +#endif diff --git a/ext/clogger_ext/clogger.c b/ext/clogger_ext/clogger.c index 9703f69..7e01e6d 100644 --- a/ext/clogger_ext/clogger.c +++ b/ext/clogger_ext/clogger.c @@ -16,6 +16,7 @@ #define _POSIX_C_SOURCE 200112L #include #include "ruby_1_9_compat.h" +#include "broken_system_compat.h" static void clock_diff(struct timespec *a, const struct timespec *b) { diff --git a/ext/clogger_ext/extconf.rb b/ext/clogger_ext/extconf.rb index 60c46a7..d87d8c2 100644 --- a/ext/clogger_ext/extconf.rb +++ b/ext/clogger_ext/extconf.rb @@ -17,6 +17,7 @@ begin $CPPFLAGS += '-D_POSIX_SOURCE_200112L' have_func('CLOCK_MONOTONIC', 'time.h') end + have_func('clock_gettime', 'time.h') have_func('localtime_r', 'time.h') or raise "localtime_r needed" have_func('gmtime_r', 'time.h') or raise "gmtime_r needed" have_func('rb_str_set_len', 'ruby.h') -- Eric Wong