List:Commits« Previous MessageNext Message »
From:vvaintroub Date:February 5 2008 3:24pm
Subject: bk commit into 6.0 tree (vvaintroub:1.2782)
View as plain text  
Below is the list of changes that have just been committed into a local
6.0 repository of vvaintroub.  When vvaintroub does a push these changes
will be propagated to the main repository and, within 24 hours after the
push, to the public repository.
For information on how to access the public repository
see http://dev.mysql.com/doc/mysql/en/installing-source-tree.html

ChangeSet@stripped, 2008-02-05 16:23:57+01:00, vvaintroub@wva. +5 -0
  Preparation for DBUG_PRINT cleanup
  - implement formatted output for pointer, size_t and longlong in 
    my_vsnprint
  - use my_vsnprint in DBUG_PRINT (_db_doprnt)
  - change fopen() not to use "a+c" or "w+c" on Windows, but "a+" or "w" 
  as on other platforms. Syncing to disk after each write is not really
  needed and slows down tracing considerably.
   

  dbug/dbug.c@stripped, 2008-02-05 16:23:54+01:00, vvaintroub@wva. +4 -9
    -Use my_vsnprintf for formatted output in _db_doprnt , 
    as my_vsnprintf now has possibility to output pointers, longlongs and 
    size_t's in uniform C99-compatible fashion on every platform
    
    - Windows : fopen() trace file with "a+" or "w", 
    instead of "a+c" or "w+c".  The later caused FlushFileBuffer() after each
    write, which significantly slowed down  the trace. 

  include/m_string.h@stripped, 2008-02-05 16:23:54+01:00, vvaintroub@wva. +3 -1
    New function ll2str - convert longlong to string and optionally specify 
    case used for by conversion routine (i.e whether hexadecimal letters 
    should be uppercase or lowercase)

  mysys/my_fopen.c@stripped, 2008-02-05 16:23:55+01:00, vvaintroub@wva. +1 -1
    Replace 0x%lx with %p and remove (long) cast in DBUG_PRINT 

  strings/longlong2str.c@stripped, 2008-02-05 16:23:55+01:00, vvaintroub@wva. +5 -4
    New function ll2str - convert longlong to string and optionally specify 
    case used for by conversion routine (i.e whether hexadecimal letters 
    should be uppercase or lowercase)

  strings/my_vsnprintf.c@stripped, 2008-02-05 16:23:55+01:00, vvaintroub@wva. +68 -13
    Additional format specifier support in my_vsnprintf
    %lld,%llx,%p,%zd,%zx - to output longlongs, pointers and size_t's
    %f,%e,%g %F,%E,%G - to output doubles (relies on standard C library)

diff -Nrup a/dbug/dbug.c b/dbug/dbug.c
--- a/dbug/dbug.c	2007-10-15 18:56:22 +02:00
+++ b/dbug/dbug.c	2008-02-05 16:23:54 +01:00
@@ -238,6 +238,7 @@ typedef struct _db_code_state_ {
   uint u_line;                  /* User source code line number */
   int  locked;                  /* If locked with _db_lock_file_ */
   const char *u_keyword;        /* Keyword for current macro */
+  char cvtbuf[1024];            /* Conversion buffer */
 } CODE_STATE;
 
 /*
@@ -1133,8 +1134,8 @@ void _db_doprnt_(const char *format,...)
     else
       (void) fprintf(cs->stack->out_file, "%s: ", cs->func);
     (void) fprintf(cs->stack->out_file, "%s: ", cs->u_keyword);
-    (void) vfprintf(cs->stack->out_file, format, args);
-    (void) fputc('\n',cs->stack->out_file);
+    (void) my_vsnprintf(cs->cvtbuf, sizeof(cs->cvtbuf), format, args);
+    (void) fprintf(cs->stack->out_file,"%s\n",cs->cvtbuf);
     dbug_flush(cs);
     errno=save_errno;
   }
@@ -1826,13 +1827,7 @@ static void DBUGOpenFile(CODE_STATE *cs,
       else
       {
         newfile= !EXISTS(name);
-        if (!(fp= fopen(name,
-#if defined(MSDOS) || defined(__WIN__)
-		append ? "a+c" : "wc"
-#else
-                append ? "a+" : "w"
-#endif
-		)))
+        if (!(fp= fopen(name, append ? "a+" : "w")))
         {
           (void) fprintf(stderr, ERR_OPEN, cs->process, name);
           perror("");
diff -Nrup a/include/m_string.h b/include/m_string.h
--- a/include/m_string.h	2007-11-30 14:52:49 +01:00
+++ b/include/m_string.h	2008-02-05 16:23:54 +01:00
@@ -212,6 +212,7 @@ extern char *str2int(const char *src,int
 			 long *val);
 longlong my_strtoll10(const char *nptr, char **endptr, int *error);
 #if SIZEOF_LONG == SIZEOF_LONG_LONG
+#define ll2str(A,B,C,D) int2str((A),(B),(C),(D))
 #define longlong2str(A,B,C) int2str((A),(B),(C),1)
 #define longlong10_to_str(A,B,C) int10_to_str((A),(B),(C))
 #undef strtoll
@@ -225,7 +226,8 @@ longlong my_strtoll10(const char *nptr, 
 #endif
 #else
 #ifdef HAVE_LONG_LONG
-extern char *longlong2str(longlong val,char *dst,int radix);
+extern char *ll2str(longlong val,char *dst,int radix, int upcase);
+#define longlong2str(A,B,C) ll2str((A),(B),(C),1)
 extern char *longlong10_to_str(longlong val,char *dst,int radix);
 #if (!defined(HAVE_STRTOULL) || defined(NO_STRTOLL_PROTO))
 extern longlong strtoll(const char *str, char **ptr, int base);
diff -Nrup a/mysys/my_fopen.c b/mysys/my_fopen.c
--- a/mysys/my_fopen.c	2007-08-13 15:11:09 +02:00
+++ b/mysys/my_fopen.c	2008-02-05 16:23:55 +01:00
@@ -79,7 +79,7 @@ FILE *my_fopen(const char *filename, int
       my_file_total_opened++;
       my_file_info[fileno(fd)].type = STREAM_BY_FOPEN;
       pthread_mutex_unlock(&THR_LOCK_open);
-      DBUG_PRINT("exit",("stream: 0x%lx", (long) fd));
+      DBUG_PRINT("exit",("stream: %p", fd));
       DBUG_RETURN(fd);
     }
     pthread_mutex_unlock(&THR_LOCK_open);
diff -Nrup a/strings/longlong2str.c b/strings/longlong2str.c
--- a/strings/longlong2str.c	2007-10-31 10:34:25 +01:00
+++ b/strings/longlong2str.c	2008-02-05 16:23:55 +01:00
@@ -40,17 +40,18 @@
 #include <my_global.h>
 #include "m_string.h"
 
-#if defined(HAVE_LONG_LONG) && !defined(longlong2str) &&
!defined(HAVE_LONGLONG2STR)
+#if defined(HAVE_LONG_LONG) && (SIZEOF_LONG != SIZEOF_LONG_LONG) &&
!defined(HAVE_LONGLONG2STR)
 
 /*
   This assumes that longlong multiplication is faster than longlong division.
 */
 
-char *longlong2str(longlong val,char *dst,int radix)
+char *ll2str(longlong val,char *dst,int radix, int upcase)
 {
   char buffer[65];
   register char *p;
   long long_val;
+  char *dig_vec= upcase ? _dig_vec_upper : _dig_vec_lower;
   ulonglong uval= (ulonglong) val;
 
   if (radix < 0)
@@ -80,14 +81,14 @@ char *longlong2str(longlong val,char *ds
   {
     ulonglong quo= uval/(uint) radix;
     uint rem= (uint) (uval- quo* (uint) radix);
-    *--p = _dig_vec_upper[rem];
+    *--p = dig_vec[rem];
     uval= quo;
   }
   long_val= (long) uval;
   while (long_val != 0)
   {
     long quo= long_val/radix;
-    *--p = _dig_vec_upper[(uchar) (long_val - quo*radix)];
+    *--p = dig_vec[(uchar) (long_val - quo*radix)];
     long_val= quo;
   }
   while ((*dst++ = *p++) != 0) ;
diff -Nrup a/strings/my_vsnprintf.c b/strings/my_vsnprintf.c
--- a/strings/my_vsnprintf.c	2007-06-01 10:12:02 +02:00
+++ b/strings/my_vsnprintf.c	2008-02-05 16:23:55 +01:00
@@ -30,9 +30,15 @@
 
   IMPLEMENTION:
     Supports following formats:
-    %#[l]d
-    %#[l]u
-    %#[l]x
+    %#[l][l]d
+    %#[l][l]u
+    %#[l][l]x
+    %p
+    %zd
+    %zx
+    %f
+    %g
+    %e
     %#.#b 	Local format; note first # is ignored and second is REQUIRED
     %#.#s	Note first # is ignored
     
@@ -43,8 +49,9 @@
 size_t my_vsnprintf(char *to, size_t n, const char* fmt, va_list ap)
 {
   char *start=to, *end=to+n-1;
+  const char *percent_pos;
   size_t length, width;
-  uint pre_zero, have_long;
+  uint pre_zero, have_long, have_longlong;
 
   for (; *fmt ; fmt++)
   {
@@ -55,12 +62,13 @@ size_t my_vsnprintf(char *to, size_t n, 
       *to++= *fmt;			/* Copy ordinary char */
       continue;
     }
+    percent_pos = fmt;
     fmt++;					/* skip '%' */
     /* Read max fill size (only used with %d and %u) */
     if (*fmt == '-')
       fmt++;
     length= width= 0;
-    pre_zero= have_long= 0;
+    pre_zero= have_long= have_longlong = 0;
     if (*fmt == '*')
     {
       fmt++;
@@ -90,7 +98,20 @@ size_t my_vsnprintf(char *to, size_t n, 
     if (*fmt == 'l')
     {
       fmt++;
-      have_long= 1;
+      if (fmt[1] != 'l')
+        have_long= 1;
+      else
+      {
+        fmt++;
+        have_longlong= 1;
+      }
+    }
+    else if(*fmt == 'z')
+    {
+      fmt++;
+      have_longlong = (sizeof(size_t) == sizeof(longlong));
+      if(!have_longlong)
+        have_long = 1;
     }
     if (*fmt == 's')				/* String parameter */
     {
@@ -113,29 +134,63 @@ size_t my_vsnprintf(char *to, size_t n, 
       to+= width;
       continue;
     }
-    else if (*fmt == 'd' || *fmt == 'u'|| *fmt== 'x')	/* Integer parameter */
+    else if (*fmt == 'f' || *fmt =='g' || *fmt=='e' ||
+             *fmt == 'F' || *fmt =='G' || *fmt=='E' )
     {
-      register long larg;
+      /* Use standard C library for double to string conversions */
+      char fmtbuf[32];
+      double d= va_arg(ap, double);
+      if(fmt-percent_pos+1 < sizeof(fmtbuf)-1)
+        continue;
+      memmove(fmtbuf, percent_pos, (fmt - percent_pos)+1);
+      fmtbuf[fmt-percent_pos+1]= 0;
+#if (_MSC_VER)
+      /* Microsoft compiler needs _snprintf with underscore*/
+      to+= _snprintf(to, end-to, fmtbuf, d);
+#else
+      to+= snprintf(to, end-to, fmtbuf, d);
+#endif
+      continue;
+    }
+    else if (*fmt == 'd' || *fmt == 'u'|| *fmt== 'x' || *fmt =='p')
+    /* Integer parameter */
+    {
+      register longlong larg;
       size_t res_length, to_length;
       char *store_start= to, *store_end;
       char buff[32];
+      if (*fmt == 'p')
+      {
+       have_longlong= (sizeof(void *) == sizeof(longlong));
+       if(!have_longlong)
+         have_long = 1;
+      }
 
       if ((to_length= (size_t) (end-to)) < 16 || length)
 	store_start= buff;
-      if (have_long)
+      if (have_longlong)
+        larg = va_arg(ap,longlong);
+      else if (have_long)
         larg = va_arg(ap, long);
       else
         if (*fmt == 'd')
           larg = va_arg(ap, int);
         else
-          larg= (long) (uint) va_arg(ap, int);
+          larg= (longlong) (uint) va_arg(ap, int);
       if (*fmt == 'd')
-	store_end= int10_to_str(larg, store_start, -10);
+	store_end= longlong10_to_str(larg, store_start, -10);
       else
         if (*fmt== 'u')
-          store_end= int10_to_str(larg, store_start, 10);
+          store_end= longlong10_to_str(larg, store_start, 10);
+        else if(*fmt == 'p')
+        {
+          store_start[0] = '0';
+          store_start[1] = 'x';
+          store_end= ll2str(larg, store_start + 2, 16, 0);
+        }
         else
-          store_end= int2str(larg, store_start, 16, 0);
+          store_end= ll2str(larg, store_start, 16, 0);
+
       if ((res_length= (size_t) (store_end - store_start)) > to_length)
 	break;					/* num doesn't fit in output */
       /* If %#d syntax was used, we have to pre-zero/pre-space the string */


Thread
bk commit into 6.0 tree (vvaintroub:1.2782)vvaintroub5 Feb
  • Re: bk commit into 6.0 tree (vvaintroub:1.2782)Sergei Golubchik5 Feb