[cvslog] (2008-07-10 10:56:33 UTC) Module eggdrop1.6: Change committed!

cvslog cvs at tsss.org
Thu Jul 10 04:56:33 CST 2008


CVSROOT    : /usr/local/cvsroot
Module     : eggdrop1.6
Commit time: 2008-07-10 10:56:33 UTC
Commited by: Tothwolf <tothwolf at techmonkeys.org>

Modified files:
     aclocal.m4 config.h.in configure configure.ac doc/Changes1.6
     src/eggdrop.h src/main.c src/main.h src/tclmisc.c
     src/mod/irc.mod/chan.c

Log message:

Removed Solaris RANDMAX autoconf hack.

Added proper preprocessor checks for RANDOM_MAX and RAND_MAX.

Added autoconf tests and preprocessor checks for rand() and lrand48().

Simplified randint macro to make it faster.

Added argument sanity checking for tcl_rand() / Tcl [rand] command.

Added min:max value sanity checking in irc.mod set_delay(). This should match the aop-delay behavior documented in eggdrop.conf now.

---------------------- diff included ----------------------
Index: eggdrop1.6/aclocal.m4
diff -u eggdrop1.6/aclocal.m4:1.111 eggdrop1.6/aclocal.m4:1.112
--- eggdrop1.6/aclocal.m4:1.111	Thu Jul 10 05:06:53 2008
+++ eggdrop1.6/aclocal.m4	Thu Jul 10 05:56:22 2008
@@ -16,7 +16,7 @@
 dnl along with this program; if not, write to the Free Software
 dnl Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
 dnl
-dnl $Id: aclocal.m4,v 1.111 2008-07-10 10:06:53 tothwolf Exp $
+dnl $Id: aclocal.m4,v 1.112 2008-07-10 10:56:22 tothwolf Exp $
 dnl
 
 
@@ -654,7 +654,6 @@
   SUNOS="no"
   HPUX="no"
   EGG_CYGWIN="no"
-  RANDMAX="RAND_MAX"
 
   case "$egg_cv_var_system_type" in
     BSD/OS)
@@ -773,8 +772,6 @@
         SHLIB_LD="ld"
         SHLIB_CC="$CC -PIC"
       fi
-      # Solaris defines (2^31)-1 as the limit for random() rather than RAND_MAX.
-      RANDMAX="0x7FFFFFFF"
     ;;
     *BSD)
       # FreeBSD/OpenBSD/NetBSD
@@ -807,7 +804,6 @@
   AC_SUBST(SHLIB_LD)
   AC_SUBST(SHLIB_CC)
   AC_SUBST(SHLIB_STRIP)
-  AC_DEFINE_UNQUOTED(RANDOM_MAX, $RANDMAX, [Define limit of random() function.])
 ])
 
 
Index: eggdrop1.6/config.h.in
diff -u eggdrop1.6/config.h.in:1.50 eggdrop1.6/config.h.in:1.51
--- eggdrop1.6/config.h.in:1.50	Thu Jul  3 22:17:25 2008
+++ eggdrop1.6/config.h.in	Thu Jul 10 05:56:22 2008
@@ -126,6 +126,9 @@
 /* Define to 1 if you have the <locale.h> header file. */
 #undef HAVE_LOCALE_H
 
+/* Define to 1 if you have the `lrand48' function. */
+#undef HAVE_LRAND48
+
 /* Define to 1 if you have the <mach-o/dyld.h> header file. */
 #undef HAVE_MACH_O_DYLD_H
 
@@ -159,6 +162,9 @@
 /* Define to 1 if you have the `NSLinkModule' function. */
 #undef HAVE_NSLINKMODULE
 
+/* Define to 1 if you have the `rand' function. */
+#undef HAVE_RAND
+
 /* Define to 1 if you have the `random' function. */
 #undef HAVE_RANDOM
 
@@ -189,9 +195,6 @@
 /* Define to 1 if you have the `socklen_t' type. */
 #undef HAVE_SOCKLEN_T
 
-/* Define to 1 if you have the `srandom' function. */
-#undef HAVE_SRANDOM
-
 /* Define to 1 if you have the <stdarg.h> header file. */
 #undef HAVE_STDARG_H
 
@@ -323,9 +326,6 @@
 /* Define to the version of this package. */
 #undef PACKAGE_VERSION
 
-/* Define limit of random() function. */
-#undef RANDOM_MAX
-
 /* Define to the type of arg 1 for `select'. */
 #undef SELECT_TYPE_ARG1
 
Index: eggdrop1.6/configure
diff -u eggdrop1.6/configure:1.160 eggdrop1.6/configure:1.161
--- eggdrop1.6/configure:1.160	Thu Jul 10 05:06:53 2008
+++ eggdrop1.6/configure	Thu Jul 10 05:56:22 2008
@@ -1,5 +1,5 @@
 #! /bin/sh
-# From configure.ac Revision: 1.33 .
+# From configure.ac Revision: 1.34 .
 # Guess values for system-dependent variables and create Makefiles.
 # Generated by GNU Autoconf 2.61 for Eggdrop 1.6.20.
 #
@@ -5781,7 +5781,6 @@
   SUNOS="no"
   HPUX="no"
   EGG_CYGWIN="no"
-  RANDMAX="RAND_MAX"
 
   case "$egg_cv_var_system_type" in
     BSD/OS)
@@ -6028,8 +6027,6 @@
         SHLIB_LD="ld"
         SHLIB_CC="$CC -PIC"
       fi
-      # Solaris defines (2^31)-1 as the limit for random() rather than RAND_MAX.
-      RANDMAX="0x7FFFFFFF"
     ;;
     *BSD)
       # FreeBSD/OpenBSD/NetBSD
@@ -6071,11 +6068,6 @@
 
 
 
-cat >>confdefs.h <<_ACEOF
-#define RANDOM_MAX $RANDMAX
-_ACEOF
-
-
 
 
 # Checks for header files.
@@ -8787,7 +8779,8 @@
 
 
 
-for ac_func in clock dprintf fsync getdtablesize getrusage inet_aton isascii mbrlen memcpy memset random rename setpgid sigaction sigemptyset snprintf srandom strcasecmp strncasecmp uname vsnprintf
+
+for ac_func in clock dprintf fsync getdtablesize getrusage inet_aton isascii mbrlen memcpy memset random rand lrand48 rename setpgid sigaction sigemptyset snprintf strcasecmp strncasecmp uname vsnprintf
 do
 as_ac_var=`echo "ac_cv_func_$ac_func" | $as_tr_sh`
 { echo "$as_me:$LINENO: checking for $ac_func" >&5
Index: eggdrop1.6/configure.ac
diff -u eggdrop1.6/configure.ac:1.34 eggdrop1.6/configure.ac:1.35
--- eggdrop1.6/configure.ac:1.34	Thu Jul 10 05:06:53 2008
+++ eggdrop1.6/configure.ac	Thu Jul 10 05:56:22 2008
@@ -1,11 +1,11 @@
 dnl configure.ac: this file is processed by autoconf to produce ./configure.
 dnl
-dnl $Id: configure.ac,v 1.34 2008-07-10 10:06:53 tothwolf Exp $
+dnl $Id: configure.ac,v 1.35 2008-07-10 10:56:22 tothwolf Exp $
 
 AC_PREREQ(2.60)
 AC_INIT([Eggdrop],[1.6.20],[bugs at eggheads.org])
 AC_COPYRIGHT([Copyright (C) 1999 - 2008 Eggheads Development Team])
-AC_REVISION($Revision: 1.34 $)
+AC_REVISION($Revision: 1.35 $)
 AC_CONFIG_SRCDIR(src/eggdrop.h)
 AC_CONFIG_AUX_DIR(misc)
 AC_CONFIG_HEADER(config.h)
@@ -112,7 +112,7 @@
 
 
 # Checks for functions and their arguments.
-AC_CHECK_FUNCS([clock dprintf fsync getdtablesize getrusage inet_aton isascii mbrlen memcpy memset random rename setpgid sigaction sigemptyset snprintf srandom strcasecmp strncasecmp uname vsnprintf])
+AC_CHECK_FUNCS([clock dprintf fsync getdtablesize getrusage inet_aton isascii mbrlen memcpy memset random rand lrand48 rename setpgid sigaction sigemptyset snprintf strcasecmp strncasecmp uname vsnprintf])
 AC_FUNC_SELECT_ARGTYPES
 EGG_FUNC_VPRINTF
 AC_FUNC_STRFTIME
Index: eggdrop1.6/doc/Changes1.6
diff -u eggdrop1.6/doc/Changes1.6:1.4 eggdrop1.6/doc/Changes1.6:1.5
--- eggdrop1.6/doc/Changes1.6:1.4	Thu Jul 10 05:06:53 2008
+++ eggdrop1.6/doc/Changes1.6	Thu Jul 10 05:56:23 2008
@@ -1,4 +1,4 @@
-$Id: Changes1.6,v 1.4 2008-07-10 10:06:53 tothwolf Exp $
+$Id: Changes1.6,v 1.5 2008-07-10 10:56:23 tothwolf Exp $
 
 Eggdrop Changes (since version 1.6.0)
 
@@ -6,6 +6,15 @@
 
 1.6.20 (CVS):
 
+  - Removed Solaris RANDMAX autoconf hack.
+  - Added proper preprocessor checks for RANDOM_MAX and RAND_MAX.
+  - Added autoconf tests and preprocessor checks for rand() and lrand48().
+  - Simplified randint macro to make it faster.
+  - Added argument sanity checking for tcl_rand() / Tcl [rand] command.
+  - Added min:max value sanity checking in irc.mod set_delay(). This should
+    match the aop-delay behavior documented in eggdrop.conf now.
+    Patch by: Tothwolf
+
   - More minor autoconf changes.
   - Context and ContextNote should use 'do {} while (0)' instead of '{}'.
   - Put Context init code into an #ifdef DEBUG_CONTEXT block.
Index: eggdrop1.6/src/eggdrop.h
diff -u eggdrop1.6/src/eggdrop.h:1.69 eggdrop1.6/src/eggdrop.h:1.70
--- eggdrop1.6/src/eggdrop.h:1.69	Thu Jul 10 05:06:53 2008
+++ eggdrop1.6/src/eggdrop.h	Thu Jul 10 05:56:23 2008
@@ -4,7 +4,7 @@
  *
  *   IF YOU ALTER THIS FILE, YOU NEED TO RECOMPILE THE BOT.
  *
- * $Id: eggdrop.h,v 1.69 2008-07-10 10:06:53 tothwolf Exp $
+ * $Id: eggdrop.h,v 1.70 2008-07-10 10:56:23 tothwolf Exp $
  */
 /*
  * Copyright (C) 1997 Robey Pointer
@@ -193,13 +193,63 @@
 #  endif
 #endif
 
-#ifndef HAVE_SRANDOM
-#  define srandom(x) srand(x)
-#endif
 
-#ifndef HAVE_RANDOM
-#  define random() (rand()/16)
-#endif
+/* Yikes...who would have thought finding a usable random() would be so much
+ * trouble?
+ * Note: random(), rand(), and lrand48() are *not* thread safe.
+ */
+#ifdef HAVE_RANDOM  
+  /* On systems with random(), RANDOM_MAX may or may not be defined.
+   *
+   * If RANDOM_MAX isn't defined, we use 0x7FFFFFFF (2^31-1), or 2147483647
+   * since this follows the 4.3BSD and POSIX.1-2001 standards. This of course
+   * assumes random() uses a 32 bit long int type per the standards.
+   */
+#  ifndef RANDOM_MAX
+#    define RANDOM_MAX 0x7FFFFFFF  /* random() -- 2^31-1 */
+#  endif 
+#else                              /* !HAVE_RANDOM */
+   /* This shouldn't exist in this case, but just to be safe... */
+#  ifdef RANDOM_MAX
+#    undef RANDOM_MAX
+#  endif
+  /* If we don't have random() it's safe to assume we also don't have
+   * srandom(), and we need both.
+   */
+#  ifdef HAVE_RAND
+#    define random() rand()   
+#    define srandom(x) srand(x)
+    /* Depending on the system int size, RAND_MAX can be either 0x7FFFFFFF
+     * (2^31-1), or 2147483647 for a 32 bit int, or 0x7FFF (2^15-1), or
+     * 32767 for a 16 bit int. The standards only state that RAND_MAX must
+     * be _at least_ 32767 but some systems with 16 bit int define it as
+     * 32767. See: SVr4, 4.3BSD, C89, C99, POSIX.1-2001.
+     */
+#    define RANDOM_MAX RAND_MAX    /* rand() -- 2^31-1 or 2^15-1 */
+#  else                            /* !HAVE_RAND */
+#    ifdef  HAVE_LRAND48
+#      define random() lrand48()
+#      define srandom(x) srand48(x)
+      /* For lrand48() we define RANDOM_MAX as 0x7FFFFFFF (2^31-1), or
+       * 2147483647 since this is what the SVr4 and POSIX.1-2001 standards
+       * call for. Note: SVID 3 declares these functions as obsolete and
+       * states rand() should be used instead.
+       */
+#      define RANDOM_MAX 0x7FFFFFFF /* lrand48() -- 2^31-1 */
+#    else                          /* !HAVE_LRAND48 */
+#      include "Error: Must define one of HAVE_RANDOM, HAVE_RAND, or HAVE_LRAND48"
+#    endif                         /* HAVE_LRAND48 */
+#  endif                           /* HAVE_RAND */
+#endif                             /* HAVE_RANDOM */
+
+
+/* Use high-order bits for getting the random integer. With a modern
+ * random() implmentation, modulo would probably be sufficient, but on
+ * systems lacking random(), it may just be a macro for an older rand()
+ * fucntion.
+ */
+#define randint(n) (unsigned long) (random() / (RANDOM_MAX + 1.0) * n)
+
 
 #ifndef HAVE_SIGACTION /* old "weird signals" */
 #  define sigaction sigvec
Index: eggdrop1.6/src/main.c
diff -u eggdrop1.6/src/main.c:1.125 eggdrop1.6/src/main.c:1.126
--- eggdrop1.6/src/main.c:1.125	Thu Jul 10 05:06:53 2008
+++ eggdrop1.6/src/main.c	Thu Jul 10 05:56:23 2008
@@ -5,7 +5,7 @@
  *   command line arguments
  *   context and assert debugging
  *
- * $Id: main.c,v 1.125 2008-07-10 10:06:53 tothwolf Exp $
+ * $Id: main.c,v 1.126 2008-07-10 10:56:23 tothwolf Exp $
  */
 /*
  * Copyright (C) 1997 Robey Pointer
@@ -948,8 +948,19 @@
      * calls to periodic_timers
      */
     now = time(NULL);
-    random();                   /* Woop, lets really jumble things */
-    if (now != then) {          /* Once a second */
+
+    /*
+     * FIXME: Get rid of this, it's ugly and wastes lots of cpu.
+     *
+     * pre-1.3.0 Eggdrop had random() in the once a second block below.
+     *
+     * This attempts to keep random() more random by constantly
+     * calling random() and updating the state information.
+     */
+    random();                /* Woop, lets really jumble things */
+
+    /* Once a second */
+    if (now != then) {
       call_hook(HOOK_SECONDLY);
       then = now;
     }
Index: eggdrop1.6/src/main.h
diff -u eggdrop1.6/src/main.h:1.37 eggdrop1.6/src/main.h:1.38
--- eggdrop1.6/src/main.h:1.37	Thu Jul  3 21:41:43 2008
+++ eggdrop1.6/src/main.h	Thu Jul 10 05:56:23 2008
@@ -2,7 +2,7 @@
  * main.h
  *   include file to include most other include files
  *
- * $Id: main.h,v 1.37 2008-07-04 02:41:43 tothwolf Exp $
+ * $Id: main.h,v 1.38 2008-07-10 10:56:23 tothwolf Exp $
  */
 /*
  * Copyright (C) 1997 Robey Pointer
@@ -138,10 +138,4 @@
 #  define O_NONBLOCK 00000004 /* POSIX non-blocking I/O */
 #endif /* BORGCUBES */
 
-/* Use high-order bits for getting the random integer. With random()
- * modulo would probably be sufficient but on systems lacking random(),
- * the function will be just renamed rand().
- */
-#define randint(n) (unsigned long) (random() / (RANDOM_MAX + 1.0) * ((n) < 0 ? (-(n)) : (n)))
-
 #endif /* _EGG_MAIN_H */
Index: eggdrop1.6/src/mod/irc.mod/chan.c
diff -u eggdrop1.6/src/mod/irc.mod/chan.c:1.127 eggdrop1.6/src/mod/irc.mod/chan.c:1.128
--- eggdrop1.6/src/mod/irc.mod/chan.c:1.127	Mon Jun 30 19:20:03 2008
+++ eggdrop1.6/src/mod/irc.mod/chan.c	Thu Jul 10 05:56:23 2008
@@ -6,7 +6,7 @@
  *   user kickban, kick, op, deop
  *   idle kicking
  *
- * $Id: chan.c,v 1.127 2008-07-01 00:20:03 tothwolf Exp $
+ * $Id: chan.c,v 1.128 2008-07-10 10:56:23 tothwolf Exp $
  */
 /*
  * Copyright (C) 1997 Robey Pointer
@@ -1584,31 +1584,57 @@
   return 0;
 }
 
+/* Set delay for +o, +h, or +v channel modes
+ */
 static void set_delay(struct chanset_t *chan, char *nick)
 {
   time_t a_delay;
-  int aop_min = chan->aop_min, aop_max = chan->aop_max, count = 0;
+  int aop_min, aop_max, aop_diff, count = 0;
   memberlist *m, *m2;
 
   m = ismember(chan, nick);
   if (!m)
     return;
-  if (aop_min >= aop_max)
+
+  /* aop-delay 5:30 -- aop_min:aop_max */
+  aop_min = chan->aop_min;
+  aop_max = chan->aop_max;
+  aop_diff = aop_max - aop_min;
+
+  /* If either min or max is less than or equal to 0 we don't delay. */
+  if ((aop_min <= 0) || (aop_max <= 0)) {
+    a_delay = now + 1;
+
+  /* Use min value for delay if min greater then or equal to max or if the
+   * difference of max and min is greater than RANDOM_MAX (sanity check).
+   */
+  } else if ((aop_min >= aop_max) || (aop_diff > RANDOM_MAX)) {
     a_delay = now + aop_min;
-  else
-    a_delay = now + randint(aop_max - aop_min) + aop_min + 1;
+
+  /* Set a random delay based on the difference of max and min */
+  } else {
+    a_delay = now + randint(aop_diff) + aop_min + 1;
+  }
+
   for (m2 = chan->channel.member; m2 && m2->nick[0]; m2 = m2->next)
     if (m2->delay && !(m2->flags & FULL_DELAY))
       count++;
-  if (count)
-    for (m2 = chan->channel.member; m2 && m2->nick[0]; m2 = m2->next)
+
+  if (count) {
+    for (m2 = chan->channel.member; m2 && m2->nick[0]; m2 = m2->next) {
       if (m2->delay && !(m2->flags & FULL_DELAY)) {
         m2->delay = a_delay;
+
         if (count + 1 >= modesperline)
           m2->flags |= FULL_DELAY;
+
       }
+    }
+  }
+
   if (count + 1 >= modesperline)
     m->flags |= FULL_DELAY;
+
   m->delay = a_delay;
 }
 
Index: eggdrop1.6/src/tclmisc.c
diff -u eggdrop1.6/src/tclmisc.c:1.59 eggdrop1.6/src/tclmisc.c:1.60
--- eggdrop1.6/src/tclmisc.c:1.59	Sat Feb 16 15:41:04 2008
+++ eggdrop1.6/src/tclmisc.c	Thu Jul 10 05:56:23 2008
@@ -2,7 +2,7 @@
  * tclmisc.c -- handles:
  *   Tcl stubs for everything else
  *
- * $Id: tclmisc.c,v 1.59 2008-02-16 21:41:04 guppy Exp $
+ * $Id: tclmisc.c,v 1.60 2008-07-10 10:56:23 tothwolf Exp $
  */
 /*
  * Copyright (C) 1997 Robey Pointer
@@ -430,19 +430,25 @@
 
 static int tcl_rand STDVAR
 {
-  unsigned long x;
+  unsigned long i, x;
   char s[11];
 
   BADARGS(2, 2, " limit");
 
-  if (atol(argv[1]) <= 0) {
+  i = atol(argv[1]);
+
+  if (i <= 0) {
     Tcl_AppendResult(irp, "random limit must be greater than zero", NULL);
     return TCL_ERROR;
+  } else if (i > RANDOM_MAX) {
+    Tcl_AppendResult(irp, "random limit must be less than ", RANDOM_MAX, NULL);
+    return TCL_ERROR;
   }
 
-  x = randint((unsigned long) (atol(argv[1])));
+  x = randint(i);
 
   egg_snprintf(s, sizeof s, "%lu", x);
+
   Tcl_AppendResult(irp, s, NULL);
   return TCL_OK;
 }
----------------------- End of diff -----------------------



More information about the Changes mailing list