/ Check-in [28d1bc98]
Login

Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.

Overview
Comment:Modify the sqlite3_log() interface and implementation so that it never uses dynamic memory allocation - to avoid deadlocking when called while holding the memory allocator mutex.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1: 28d1bc98d60319b10af427072037a0121bc76259
User & Date: drh 2010-03-03 22:25:18
References
2010-03-03
22:40
Modify the sqlite3_log() interface and implementation so that it never uses dynamic memory allocation - to avoid deadlocking when called while holding the memory allocator mutex. Cherry-pick merge of [28d1bc98d6]. check-in: 6f368b54 user: drh tags: branch-3.6.22
Context
2010-03-03
22:43
Pull the latest Lemon updates from the lemon-update-2010 branch into the trunk. check-in: 84d760bf user: drh tags: trunk
22:25
Modify the sqlite3_log() interface and implementation so that it never uses dynamic memory allocation - to avoid deadlocking when called while holding the memory allocator mutex. check-in: 28d1bc98 user: drh tags: trunk
16:02
Fix some extra instances of the constants addressed by [83e47ca006]. check-in: 0354ab27 user: dan tags: trunk
Changes
Hide Diffs Unified Diffs Ignore Whitespace Patch

Changes to src/printf.c.

934
935
936
937
938
939
940
























941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
  acc.useMalloc = 0;
  va_start(ap,zFormat);
  sqlite3VXPrintf(&acc, 0, zFormat, ap);
  va_end(ap);
  z = sqlite3StrAccumFinish(&acc);
  return z;
}

























/*
** Format and write a message to the log if logging is enabled.
*/
void sqlite3_log(int iErrCode, const char *zFormat, ...){
  void (*xLog)(void*, int, const char*);  /* The global logger function */
  void *pLogArg;                          /* First argument to the logger */
  va_list ap;                             /* Vararg list */
  char *zMsg;                             /* Complete log message */
  
  xLog = sqlite3GlobalConfig.xLog;
  if( xLog ){
    va_start(ap, zFormat);
    sqlite3BeginBenignMalloc();
    zMsg = sqlite3_vmprintf(zFormat, ap);
    sqlite3EndBenignMalloc();
    va_end(ap);
    pLogArg = sqlite3GlobalConfig.pLogArg;
    xLog(pLogArg, iErrCode, zMsg ? zMsg : zFormat);
    sqlite3_free(zMsg);
  }
}

#if defined(SQLITE_DEBUG)
/*
** A version of printf() that understands %lld.  Used for debugging.
** The printf() built into some versions of windows does not understand %lld







>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>





<
<

<
<
|
<

<
|
<

<
<
<







934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969


970


971

972

973

974



975
976
977
978
979
980
981
  acc.useMalloc = 0;
  va_start(ap,zFormat);
  sqlite3VXPrintf(&acc, 0, zFormat, ap);
  va_end(ap);
  z = sqlite3StrAccumFinish(&acc);
  return z;
}

/*
** This is the routine that actually formats the sqlite3_log() message.
** We house it in a separate routine from sqlite3_log() to avoid using
** stack space on small-stack systems when logging is disabled.
**
** sqlite3_log() must render into a static buffer.  It cannot dynamically
** allocate memory because it might be called while the memory allocator
** mutex is held.
*/
static void renderLogMsg(int iErrCode, const char *zFormat, va_list ap){
  StrAccum acc;                           /* String accumulator */
#ifdef SQLITE_SMALL_STACK
  char zMsg[150];                         /* Complete log message */
#else
  char zMsg[400];                         /* Complete log message */
#endif

  sqlite3StrAccumInit(&acc, zMsg, sizeof(zMsg), 0);
  acc.useMalloc = 0;
  sqlite3VXPrintf(&acc, 0, zFormat, ap);
  sqlite3GlobalConfig.xLog(sqlite3GlobalConfig.pLogArg, iErrCode,
                           sqlite3StrAccumFinish(&acc));
}

/*
** Format and write a message to the log if logging is enabled.
*/
void sqlite3_log(int iErrCode, const char *zFormat, ...){


  va_list ap;                             /* Vararg list */


  if( sqlite3GlobalConfig.xLog ){

    va_start(ap, zFormat);

    renderLogMsg(iErrCode, zFormat, ap);

    va_end(ap);



  }
}

#if defined(SQLITE_DEBUG)
/*
** A version of printf() that understands %lld.  Used for debugging.
** The printf() built into some versions of windows does not understand %lld

Changes to src/sqlite.h.in.

5701
5702
5703
5704
5705
5706
5707






5708
5709
5710
5711
5712
5713
5714
**
** The sqlite3_log() interface is intended for use by extensions such as
** virtual tables, collating functions, and SQL functions.  While there is
** nothing to prevent an application from calling sqlite3_log(), doing so
** is considered bad form.
**
** The zFormat string must not be NULL.






*/
void sqlite3_log(int iErrCode, const char *zFormat, ...);

/*
** Undo the hack that converts floating point types to integer for
** builds on processors without floating point support.
*/







>
>
>
>
>
>







5701
5702
5703
5704
5705
5706
5707
5708
5709
5710
5711
5712
5713
5714
5715
5716
5717
5718
5719
5720
**
** The sqlite3_log() interface is intended for use by extensions such as
** virtual tables, collating functions, and SQL functions.  While there is
** nothing to prevent an application from calling sqlite3_log(), doing so
** is considered bad form.
**
** The zFormat string must not be NULL.
**
** To avoid deadlocks and other threading problems, the sqlite3_log() routine
** will not use dynamically allocated memory.  The log message is stored in
** a fixed-length buffer on the stack.  If the log message is longer than
** a few hundred characters, it will be truncated to the length of the
** buffer.
*/
void sqlite3_log(int iErrCode, const char *zFormat, ...);

/*
** Undo the hack that converts floating point types to integer for
** builds on processors without floating point support.
*/