For whatever reason (compiler or header bugs), at least one commonly-used
authorGeoff Thorpe <geoff@openssl.org>
Wed, 29 Oct 2003 04:40:13 +0000 (04:40 +0000)
committerGeoff Thorpe <geoff@openssl.org>
Wed, 29 Oct 2003 04:40:13 +0000 (04:40 +0000)
linux system (namely mine) chokes on our definitions and uses of the "HZ"
symbol in crypto/tmdiff.[ch] and apps/speed.c as a "bad function cast"
(when in fact there is no function casting involved at all). In both cases,
it is easily worked around by not defining a cast into the macro and
jiggling the expressions slightly.

In addition - this highlights some cruft in openssl that needs sorting out.
The tmdiff.h header is exported as part of the openssl API despite the fact
that it is ugly as the driven sludge and not used anywhere in the library,
applications, or utilities. More weird still, almost identical code exists
in apps/speed.c though it looks to be slightly tweaked - so either tmdiff
should be updated and used by speed.c, or it should be dumped because it's
obviously not useful enough.

Rather than removing it for now, I've changed the API for tmdiff to at
least make sense. This involves taking the object type (MS_TM) from the
implementation and using it in the header rather than using "char *" in the
API and casting mercilessly in the code (ugh). If someone doesn't like
"MS_TM" and the "ms_time_***" naming, by all means change it. This should
be a harmless improvement, because the existing API is clearly not very
useful (eg. we reimplement it rather than using it in our own utils).

However, someone still needs to take a hack at consolidating speed.c and
tmdiff.[ch] somehow.

CHANGES
apps/speed.c
crypto/tmdiff.c
crypto/tmdiff.h

diff --git a/CHANGES b/CHANGES
index ea4793c2e75713a1305ed963ef2e76ebb5a0bb0a..a75374b3ff0a07e27ebf0ea98fbd99f2c795881b 100644 (file)
--- a/CHANGES
+++ b/CHANGES
@@ -4,6 +4,15 @@
 
  Changes between 0.9.7c and 0.9.8  [xx XXX xxxx]
 
+  *) The tmdiff.h API was so ugly and minimal that our own timing utility
+     (speed) prefers to use its own implementation. The two implementations
+     haven't been consolidated as yet (volunteers?) but the tmdiff API has had
+     its object type properly exposed (MS_TM) instead of casting to/from "char
+     *". This may still change yet if someone realises MS_TM and "ms_time_***"
+     aren't necessarily the greatest nomenclatures - but this is what was used
+     internally to the implementation so I've used that for now.
+     [Geoff Thorpe]
+
   *) Ensure that deprecated functions do not get compiled when
      OPENSSL_NO_DEPRECATED is defined. Some "openssl" subcommands and a few of
      the self-tests were still using deprecated key-generation functions so
index 558760732f4cd23be14278b2255db1f7d343f9d7..5576f23feed47de431969289cc5ce3e63db0db93 100644 (file)
 #include <openssl/ecdh.h>
 #endif
 
+/*
+ * The following "HZ" timing stuff should be sync'd up with the code in
+ * crypto/tmdiff.[ch]. That appears to try to do the same job, though I think
+ * this code is more up to date than libcrypto's so there may be features to
+ * migrate over first. This is used in two places further down AFAICS. 
+ * The point is that nothing in openssl actually *uses* that tmdiff stuff, so
+ * either speed.c should be using it or it should go because it's obviously not
+ * useful enough. Anyone want to do a janitorial job on this?
+ */
+
 /* The following if from times(3) man page.  It may need to be changed */
 #ifndef HZ
 # if defined(_SC_CLK_TCK) \
      && (!defined(OPENSSL_SYS_VMS) || __CTRL_VER >= 70000000)
-#  define HZ ((double)sysconf(_SC_CLK_TCK))
+#  define HZ sysconf(_SC_CLK_TCK)
 # else
 #  ifndef CLK_TCK
 #   ifndef _BSD_CLK_TCK_ /* FreeBSD hack */
@@ -294,7 +304,7 @@ static double Time_F(int s)
 
 #ifdef USE_TOD
        if(usertime)
-           {
+               {
                static struct rusage tstart,tend;
 
                getrusage_used = 1;
@@ -349,7 +359,8 @@ static double Time_F(int s)
                else
                        {
                        times(&tend);
-                       ret=((double)(tend.tms_utime-tstart.tms_utime))/HZ;
+                       ret = HZ;
+                       ret=(double)(tend.tms_utime-tstart.tms_utime) / ret;
                        return((ret < 1e-3)?1e-3:ret);
                        }
                }
@@ -2191,7 +2202,10 @@ show_res:
 #endif
 #ifdef HZ
 #define as_string(s) (#s)
-               printf("HZ=%g", (double)HZ);
+               {
+               double dbl = HZ;
+               printf("HZ=%g", dbl);
+               }
 # ifdef _SC_CLK_TCK
                printf(" [sysconf value]");
 # endif
index 307523ebba3b96248383b7911178d9809df8ee1e..cbec38e178657b1df2eb27a1a42ebf2f83bc6ffd 100644 (file)
 #ifndef HZ
 # if defined(_SC_CLK_TCK) \
      && (!defined(OPENSSL_SYS_VMS) || __CTRL_VER >= 70000000)
-#  define HZ ((double)sysconf(_SC_CLK_TCK))
+/* #  define HZ ((double)sysconf(_SC_CLK_TCK)) */
+#  define HZ sysconf(_SC_CLK_TCK)
 # else
 #  ifndef CLK_TCK
 #   ifndef _BSD_CLK_TCK_ /* FreeBSD hack */
 # endif
 #endif
 
-typedef struct ms_tm
+struct ms_tm
        {
 #ifdef TIMES
        struct tms ms_tms;
@@ -136,9 +137,9 @@ typedef struct ms_tm
 #    endif
 #  endif
 #endif
-       } MS_TM;
+       };
 
-char *ms_time_new(void)
+MS_TM *ms_time_new(void)
        {
        MS_TM *ret;
 
@@ -149,18 +150,17 @@ char *ms_time_new(void)
 #ifdef OPENSSL_SYS_WIN32
        ret->thread_id=GetCurrentThread();
 #endif
-       return((char *)ret);
+       return ret;
        }
 
-void ms_time_free(char *a)
+void ms_time_free(MS_TM *a)
        {
        if (a != NULL)
                OPENSSL_free(a);
        }
 
-void ms_time_get(char *a)
+void ms_time_get(MS_TM *tm)
        {
-       MS_TM *tm=(MS_TM *)a;
 #ifdef OPENSSL_SYS_WIN32
        FILETIME tmpa,tmpb,tmpc;
 #endif
@@ -180,14 +180,13 @@ void ms_time_get(char *a)
 #endif
        }
 
-double ms_time_diff(char *ap, char *bp)
+double ms_time_diff(MS_TM *a, MS_TM *b)
        {
-       MS_TM *a=(MS_TM *)ap;
-       MS_TM *b=(MS_TM *)bp;
        double ret;
 
 #ifdef TIMES
-       ret=(b->ms_tms.tms_utime-a->ms_tms.tms_utime)/HZ;
+       ret = HZ;
+       ret = (b->ms_tms.tms_utime-a->ms_tms.tms_utime) / ret;
 #else
 # ifdef OPENSSL_SYS_WIN32
        {
@@ -217,14 +216,14 @@ double ms_time_diff(char *ap, char *bp)
        return((ret < 0.0000001)?0.0000001:ret);
        }
 
-int ms_time_cmp(char *ap, char *bp)
+int ms_time_cmp(const MS_TM *a, const MS_TM *b)
        {
-       MS_TM *a=(MS_TM *)ap,*b=(MS_TM *)bp;
        double d;
        int ret;
 
 #ifdef TIMES
-       d=(b->ms_tms.tms_utime-a->ms_tms.tms_utime)/HZ;
+       d = HZ;
+       d = (b->ms_tms.tms_utime-a->ms_tms.tms_utime) / d;
 #else
 # ifdef OPENSSL_SYS_WIN32
        d =(b->ms_win32.dwHighDateTime&0x000fffff)*10+b->ms_win32.dwLowDateTime/1e7;
index 41a8a1e0e0dab6b059e6184e62efef87da9555be..af5c41c649929ce0ae042aa244fc0cb58ade7661 100644 (file)
 /* Header for dynamic hash table routines
  * Author - Eric Young
  */
+/* ... erm yeah, "dynamic hash tables" you say?
+ * 
+ * And what would dynamic hash tables have to do with any of this code *now*?
+ * AFAICS, this code is only referenced by crypto/bn/exp.c which is an unused
+ * file that I doubt compiles any more. speed.c is the only thing that could
+ * use this (and it has nothing to do with hash tables), yet it instead has its
+ * own duplication of all this stuff and looks, if anything, more complete. See
+ * the corresponding note in apps/speed.c.
+ * The Bemused - Geoff
+ */
 
 #ifndef HEADER_TMDIFF_H
 #define HEADER_TMDIFF_H
 extern "C" {
 #endif
 
-char *ms_time_new(void );
-void ms_time_free(char *a);
-void ms_time_get(char *a);
-double ms_time_diff(char *start,char *end);
-int ms_time_cmp(char *ap,char *bp);
+typedef struct ms_tm MS_TM;
+
+MS_TM *ms_time_new(void );
+void ms_time_free(MS_TM *a);
+void ms_time_get(MS_TM *a);
+double ms_time_diff(MS_TM *start, MS_TM *end);
+int ms_time_cmp(const MS_TM *ap, const MS_TM *bp);
 
 #ifdef  __cplusplus
 }