mirror of
https://github.com/sqlite/sqlite.git
synced 2025-08-07 02:42:48 +03:00
Refactor the interface to the randomness generator. (CVS 1224)
FossilOrigin-Name: f2bdccf4bb2f796aafb64c33e55f62a1794d750c
This commit is contained in:
26
manifest
26
manifest
@@ -1,5 +1,5 @@
|
|||||||
C Pass\sall\s(relevant)\sregression\stests\swhen\susing\sthe\scodec.\s(CVS\s1223)
|
C Refactor\sthe\sinterface\sto\sthe\srandomness\sgenerator.\s(CVS\s1224)
|
||||||
D 2004-02-11T02:18:06
|
D 2004-02-11T09:46:31
|
||||||
F Makefile.in cfd75c46b335881999333a9e4b982fa8491f200b
|
F Makefile.in cfd75c46b335881999333a9e4b982fa8491f200b
|
||||||
F Makefile.linux-gcc b86a99c493a5bfb402d1d9178dcdc4bd4b32f906
|
F Makefile.linux-gcc b86a99c493a5bfb402d1d9178dcdc4bd4b32f906
|
||||||
F README f1de682fbbd94899d50aca13d387d1b3fd3be2dd
|
F README f1de682fbbd94899d50aca13d387d1b3fd3be2dd
|
||||||
@@ -26,30 +26,30 @@ F src/auth.c c59ad0dab501888f8b1fccc25e2f5965d2265116
|
|||||||
F src/btree.c c325d46f0aa815d73358bf2e044dab23f645c214
|
F src/btree.c c325d46f0aa815d73358bf2e044dab23f645c214
|
||||||
F src/btree.h 41cb3ff6ebc3f6da2d0a074e39ff8c7a2287469f
|
F src/btree.h 41cb3ff6ebc3f6da2d0a074e39ff8c7a2287469f
|
||||||
F src/btree_rb.c ed844f9181d08efa4eaca2c157accc27434e345f
|
F src/btree_rb.c ed844f9181d08efa4eaca2c157accc27434e345f
|
||||||
F src/build.c 0fdb0ce4bd87419b3930d0279e8277c4f9f69c1f
|
F src/build.c 05ee0d69c7379ef3e20121b2197bfb8865003371
|
||||||
F src/copy.c 9e47975ea96751c658bcf1a0c4f0bb7c6ee61e73
|
F src/copy.c 9e47975ea96751c658bcf1a0c4f0bb7c6ee61e73
|
||||||
F src/date.c c9d2bfd40b1c95f8f97d53a5eba981d7167c7b61
|
F src/date.c c9d2bfd40b1c95f8f97d53a5eba981d7167c7b61
|
||||||
F src/delete.c 0778fe05df0a1d62ac27fd1a3dba237c186ff4d1
|
F src/delete.c 0778fe05df0a1d62ac27fd1a3dba237c186ff4d1
|
||||||
F src/encode.c 9e70ea1e4e746f23f18180949e94f1bb1c2220d3
|
F src/encode.c 9e70ea1e4e746f23f18180949e94f1bb1c2220d3
|
||||||
F src/expr.c 3928893e8a7576484cd2ed5548468ba978d8005a
|
F src/expr.c 3928893e8a7576484cd2ed5548468ba978d8005a
|
||||||
F src/func.c 5a0face8c3a948c62677243987a18ba2f9ef9c9b
|
F src/func.c cbc5edd10c82a5193b9ca0726873328be445e6c1
|
||||||
F src/hash.c 9b56ef3b291e25168f630d5643a4264ec011c70e
|
F src/hash.c 9b56ef3b291e25168f630d5643a4264ec011c70e
|
||||||
F src/hash.h 3247573ab95b9dd90bcca0307a75d9a16da1ccc7
|
F src/hash.h 3247573ab95b9dd90bcca0307a75d9a16da1ccc7
|
||||||
F src/insert.c 01f66866f35c986eab4a57373ca689a3255ef2df
|
F src/insert.c 01f66866f35c986eab4a57373ca689a3255ef2df
|
||||||
F src/main.c 6ec57b0f146572033c70493417d251365a7b4fbe
|
F src/main.c 6ec57b0f146572033c70493417d251365a7b4fbe
|
||||||
F src/md5.c fe4f9c9c6f71dfc26af8da63e4d04489b1430565
|
F src/md5.c fe4f9c9c6f71dfc26af8da63e4d04489b1430565
|
||||||
F src/os.c 681ec36217bc7c795d55d9a63ff79a8614ddee8c
|
F src/os.c f5fc4954725b2fcd852979f2746085fe8ca27710
|
||||||
F src/os.h 8d02b622153d2df442da1ec37cdd6b1bd9804a25
|
F src/os.h 8d02b622153d2df442da1ec37cdd6b1bd9804a25
|
||||||
F src/pager.c 8b4803d3225dfa15b15cfe6d0f48d8e690238a54
|
F src/pager.c 29ddad4dd454f0aaa98e2bcd327710ab9f02f833
|
||||||
F src/pager.h 82332878799280145639a48d88cdb4058925e3f6
|
F src/pager.h 82332878799280145639a48d88cdb4058925e3f6
|
||||||
F src/parse.y 7a121554c0c0c0150a77ab05417b01fa44813ac4
|
F src/parse.y 7a121554c0c0c0150a77ab05417b01fa44813ac4
|
||||||
F src/pragma.c 89d62c31c6f0a43376fe8d20549b87a6d30c467a
|
F src/pragma.c 89d62c31c6f0a43376fe8d20549b87a6d30c467a
|
||||||
F src/printf.c 84e4ea4ba49cbbf930e95e82295127ad5843ae1f
|
F src/printf.c 84e4ea4ba49cbbf930e95e82295127ad5843ae1f
|
||||||
F src/random.c 19e8e00fe0df32a742f115773f57651be327cabe
|
F src/random.c 775913e0b7fbd6295d21f12a7bd35b46387c44b2
|
||||||
F src/select.c a0211d1a6a94f6c3e611096e77f2d689a641495e
|
F src/select.c a0211d1a6a94f6c3e611096e77f2d689a641495e
|
||||||
F src/shell.c 514056d54893e58995ab27237e54c7f057e47597
|
F src/shell.c 514056d54893e58995ab27237e54c7f057e47597
|
||||||
F src/sqlite.h.in 1798588cab21ebf9fac3aad7fc1539b396c1f91d
|
F src/sqlite.h.in 1798588cab21ebf9fac3aad7fc1539b396c1f91d
|
||||||
F src/sqliteInt.h c5b727d5d07b88654c204c0fc1ae79c9f635a008
|
F src/sqliteInt.h f03de87717569619884830b1833eca2b257fc675
|
||||||
F src/table.c d845cb101b5afc1f7fea083c99e3d2fa7998d895
|
F src/table.c d845cb101b5afc1f7fea083c99e3d2fa7998d895
|
||||||
F src/tclsqlite.c 735da4580554cd38fc9360fe7d36ceff9574a84e
|
F src/tclsqlite.c 735da4580554cd38fc9360fe7d36ceff9574a84e
|
||||||
F src/test1.c 56e9a156df3ad5e4e98df776776e963effc727f7
|
F src/test1.c 56e9a156df3ad5e4e98df776776e963effc727f7
|
||||||
@@ -60,8 +60,8 @@ F src/tokenize.c 8c95dcd2620b18dc0db1cdc97f9e111d11e55fe0
|
|||||||
F src/trigger.c ce83e017b407d046e909d05373d7f8ee70f9f7f9
|
F src/trigger.c ce83e017b407d046e909d05373d7f8ee70f9f7f9
|
||||||
F src/update.c 24260b4fda00c9726d27699a0561d53c0dccc397
|
F src/update.c 24260b4fda00c9726d27699a0561d53c0dccc397
|
||||||
F src/util.c 64995b5949a5d377629ffd2598747bc771cade1e
|
F src/util.c 64995b5949a5d377629ffd2598747bc771cade1e
|
||||||
F src/vacuum.c 77485a64a6e4e358170f150fff681c1624a092b0
|
F src/vacuum.c 717aa6da40105f0597edc9b81114c65860b60e69
|
||||||
F src/vdbe.c 546bb0a81686016380bab34db458c6e255a6dd23
|
F src/vdbe.c dfd8b36fc51615f98eaa1d4e48e0c08a74ed4190
|
||||||
F src/vdbe.h 3957844e46fea71fd030e78f6a3bd2f7e320fb43
|
F src/vdbe.h 3957844e46fea71fd030e78f6a3bd2f7e320fb43
|
||||||
F src/vdbeInt.h 8a3baf749115cba81a810b7a52208aef055eda7b
|
F src/vdbeInt.h 8a3baf749115cba81a810b7a52208aef055eda7b
|
||||||
F src/vdbeaux.c c55d87d6658487e87ef09ca80c1aa2f314024fed
|
F src/vdbeaux.c c55d87d6658487e87ef09ca80c1aa2f314024fed
|
||||||
@@ -183,7 +183,7 @@ F www/sqlite.tcl 3c83b08cf9f18aa2d69453ff441a36c40e431604
|
|||||||
F www/tclsqlite.tcl b9271d44dcf147a93c98f8ecf28c927307abd6da
|
F www/tclsqlite.tcl b9271d44dcf147a93c98f8ecf28c927307abd6da
|
||||||
F www/vdbe.tcl 9b9095d4495f37697fd1935d10e14c6015e80aa1
|
F www/vdbe.tcl 9b9095d4495f37697fd1935d10e14c6015e80aa1
|
||||||
F www/whentouse.tcl a8335bce47cc2fddb07f19052cb0cb4d9129a8e4
|
F www/whentouse.tcl a8335bce47cc2fddb07f19052cb0cb4d9129a8e4
|
||||||
P be5122e99caacbeb5e568a2782fe2faf634ad355
|
P 5200e9edc5fdba0285a3cb1cd808cbf66d7a349e
|
||||||
R 68916ef0731924b53922877bb802191f
|
R c5684db8f7677f57705b421717c383e1
|
||||||
U drh
|
U drh
|
||||||
Z 51a413c8556d4e6f634af0189fc8243d
|
Z df9e7656fc2be67ad6e1201f87c6b61c
|
||||||
|
@@ -1 +1 @@
|
|||||||
5200e9edc5fdba0285a3cb1cd808cbf66d7a349e
|
f2bdccf4bb2f796aafb64c33e55f62a1794d750c
|
@@ -23,7 +23,7 @@
|
|||||||
** ROLLBACK
|
** ROLLBACK
|
||||||
** PRAGMA
|
** PRAGMA
|
||||||
**
|
**
|
||||||
** $Id: build.c,v 1.164 2004/01/19 04:55:56 jplyon Exp $
|
** $Id: build.c,v 1.165 2004/02/11 09:46:31 drh Exp $
|
||||||
*/
|
*/
|
||||||
#include "sqliteInt.h"
|
#include "sqliteInt.h"
|
||||||
#include <ctype.h>
|
#include <ctype.h>
|
||||||
@@ -819,7 +819,9 @@ void sqliteAddCollateType(Parse *pParse, int collType){
|
|||||||
*/
|
*/
|
||||||
void sqliteChangeCookie(sqlite *db, Vdbe *v){
|
void sqliteChangeCookie(sqlite *db, Vdbe *v){
|
||||||
if( db->next_cookie==db->aDb[0].schema_cookie ){
|
if( db->next_cookie==db->aDb[0].schema_cookie ){
|
||||||
db->next_cookie = db->aDb[0].schema_cookie + sqliteRandomByte() + 1;
|
unsigned char r;
|
||||||
|
sqliteRandomness(1, &r);
|
||||||
|
db->next_cookie = db->aDb[0].schema_cookie + r + 1;
|
||||||
db->flags |= SQLITE_InternChanges;
|
db->flags |= SQLITE_InternChanges;
|
||||||
sqliteVdbeAddOp(v, OP_Integer, db->next_cookie, 0);
|
sqliteVdbeAddOp(v, OP_Integer, db->next_cookie, 0);
|
||||||
sqliteVdbeAddOp(v, OP_SetCookie, 0, 0);
|
sqliteVdbeAddOp(v, OP_SetCookie, 0, 0);
|
||||||
|
18
src/func.c
18
src/func.c
@@ -16,7 +16,7 @@
|
|||||||
** sqliteRegisterBuildinFunctions() found at the bottom of the file.
|
** sqliteRegisterBuildinFunctions() found at the bottom of the file.
|
||||||
** All other code has file scope.
|
** All other code has file scope.
|
||||||
**
|
**
|
||||||
** $Id: func.c,v 1.38 2004/01/30 14:49:17 drh Exp $
|
** $Id: func.c,v 1.39 2004/02/11 09:46:32 drh Exp $
|
||||||
*/
|
*/
|
||||||
#include <ctype.h>
|
#include <ctype.h>
|
||||||
#include <math.h>
|
#include <math.h>
|
||||||
@@ -195,7 +195,9 @@ static void ifnullFunc(sqlite_func *context, int argc, const char **argv){
|
|||||||
** Implementation of random(). Return a random integer.
|
** Implementation of random(). Return a random integer.
|
||||||
*/
|
*/
|
||||||
static void randomFunc(sqlite_func *context, int argc, const char **argv){
|
static void randomFunc(sqlite_func *context, int argc, const char **argv){
|
||||||
sqlite_set_result_int(context, sqliteRandomInteger());
|
int r;
|
||||||
|
sqliteRandomness(sizeof(r), &r);
|
||||||
|
sqlite_set_result_int(context, r);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@@ -341,13 +343,13 @@ static void soundexFunc(sqlite_func *context, int argc, const char **argv){
|
|||||||
** generating test data.
|
** generating test data.
|
||||||
*/
|
*/
|
||||||
static void randStr(sqlite_func *context, int argc, const char **argv){
|
static void randStr(sqlite_func *context, int argc, const char **argv){
|
||||||
static const char zSrc[] =
|
static const unsigned char zSrc[] =
|
||||||
"abcdefghijklmnopqrstuvwxyz"
|
"abcdefghijklmnopqrstuvwxyz"
|
||||||
"ABCDEFGHIJKLMNOPQRSTUVWXYZ"
|
"ABCDEFGHIJKLMNOPQRSTUVWXYZ"
|
||||||
"0123456789"
|
"0123456789"
|
||||||
".-!,:*^+=_|?/<> ";
|
".-!,:*^+=_|?/<> ";
|
||||||
int iMin, iMax, n, r, i;
|
int iMin, iMax, n, r, i;
|
||||||
char zBuf[1000];
|
unsigned char zBuf[1000];
|
||||||
if( argc>=1 ){
|
if( argc>=1 ){
|
||||||
iMin = atoi(argv[0]);
|
iMin = atoi(argv[0]);
|
||||||
if( iMin<0 ) iMin = 0;
|
if( iMin<0 ) iMin = 0;
|
||||||
@@ -364,14 +366,14 @@ static void randStr(sqlite_func *context, int argc, const char **argv){
|
|||||||
}
|
}
|
||||||
n = iMin;
|
n = iMin;
|
||||||
if( iMax>iMin ){
|
if( iMax>iMin ){
|
||||||
r = sqliteRandomInteger() & 0x7fffffff;
|
sqliteRandomness(sizeof(r), &r);
|
||||||
|
r &= 0x7fffffff;
|
||||||
n += r%(iMax + 1 - iMin);
|
n += r%(iMax + 1 - iMin);
|
||||||
}
|
}
|
||||||
assert( n<sizeof(zBuf) );
|
assert( n<sizeof(zBuf) );
|
||||||
r = 0;
|
sqliteRandomness(n, zBuf);
|
||||||
for(i=0; i<n; i++){
|
for(i=0; i<n; i++){
|
||||||
r = (r + sqliteRandomByte())% (sizeof(zSrc)-1);
|
zBuf[i] = zSrc[zBuf[i]%(sizeof(zSrc)-1)];
|
||||||
zBuf[i] = zSrc[r];
|
|
||||||
}
|
}
|
||||||
zBuf[n] = 0;
|
zBuf[n] = 0;
|
||||||
sqlite_set_result_string(context, zBuf, n);
|
sqlite_set_result_string(context, zBuf, n);
|
||||||
|
28
src/os.c
28
src/os.c
@@ -785,7 +785,7 @@ int sqliteOsTempFileName(char *zBuf){
|
|||||||
"/tmp",
|
"/tmp",
|
||||||
".",
|
".",
|
||||||
};
|
};
|
||||||
static char zChars[] =
|
static unsigned char zChars[] =
|
||||||
"abcdefghijklmnopqrstuvwxyz"
|
"abcdefghijklmnopqrstuvwxyz"
|
||||||
"ABCDEFGHIJKLMNOPQRSTUVWXYZ"
|
"ABCDEFGHIJKLMNOPQRSTUVWXYZ"
|
||||||
"0123456789";
|
"0123456789";
|
||||||
@@ -802,9 +802,9 @@ int sqliteOsTempFileName(char *zBuf){
|
|||||||
do{
|
do{
|
||||||
sprintf(zBuf, "%s/"TEMP_FILE_PREFIX, zDir);
|
sprintf(zBuf, "%s/"TEMP_FILE_PREFIX, zDir);
|
||||||
j = strlen(zBuf);
|
j = strlen(zBuf);
|
||||||
for(i=0; i<15; i++){
|
sqliteRandomness(15, &zBuf[j]);
|
||||||
int n = sqliteRandomByte() % (sizeof(zChars)-1);
|
for(i=0; i<15; i++, j++){
|
||||||
zBuf[j++] = zChars[n];
|
zBuf[j] = (char)zChars[ ((unsigned char)zBuf[j])%(sizeof(zChars)-1) ];
|
||||||
}
|
}
|
||||||
zBuf[j] = 0;
|
zBuf[j] = 0;
|
||||||
}while( access(zBuf,0)==0 );
|
}while( access(zBuf,0)==0 );
|
||||||
@@ -822,9 +822,9 @@ int sqliteOsTempFileName(char *zBuf){
|
|||||||
for(;;){
|
for(;;){
|
||||||
sprintf(zBuf, "%s\\"TEMP_FILE_PREFIX, zTempPath);
|
sprintf(zBuf, "%s\\"TEMP_FILE_PREFIX, zTempPath);
|
||||||
j = strlen(zBuf);
|
j = strlen(zBuf);
|
||||||
for(i=0; i<15; i++){
|
sqliteRandomness(15, &zBuf[j]);
|
||||||
int n = sqliteRandomByte() % (sizeof(zChars) - 1);
|
for(i=0; i<15; i++, j++){
|
||||||
zBuf[j++] = zChars[n];
|
zBuf[j] = (char)zChars[ ((unsigned char)zBuf[j])%(sizeof(zChars)-1) ];
|
||||||
}
|
}
|
||||||
zBuf[j] = 0;
|
zBuf[j] = 0;
|
||||||
if( !sqliteOsFileExists(zBuf) ) break;
|
if( !sqliteOsFileExists(zBuf) ) break;
|
||||||
@@ -865,9 +865,9 @@ int sqliteOsTempFileName(char *zBuf){
|
|||||||
for(;;){
|
for(;;){
|
||||||
sprintf(zBuf, "%s"TEMP_FILE_PREFIX, zTempPath);
|
sprintf(zBuf, "%s"TEMP_FILE_PREFIX, zTempPath);
|
||||||
j = strlen(zBuf);
|
j = strlen(zBuf);
|
||||||
for(i=0; i<15; i++){
|
sqliteRandomness(15, &zBuf[j]);
|
||||||
int n = sqliteRandomByte() % sizeof(zChars);
|
for(i=0; i<15; i++, j++){
|
||||||
zBuf[j++] = zChars[n];
|
zBuf[j] = (char)zChars[ ((unsigned char)zBuf[j])%(sizeof(zChars)-1) ];
|
||||||
}
|
}
|
||||||
zBuf[j] = 0;
|
zBuf[j] = 0;
|
||||||
if( !sqliteOsFileExists(zBuf) ) break;
|
if( !sqliteOsFileExists(zBuf) ) break;
|
||||||
@@ -1325,9 +1325,11 @@ int sqliteOsReadLock(OsFile *id){
|
|||||||
if( id->locked>0 ){
|
if( id->locked>0 ){
|
||||||
rc = SQLITE_OK;
|
rc = SQLITE_OK;
|
||||||
}else{
|
}else{
|
||||||
int lk = (sqliteRandomInteger() & 0x7ffffff)%N_LOCKBYTE+1;
|
int lk;
|
||||||
int res;
|
int res;
|
||||||
int cnt = 100;
|
int cnt = 100;
|
||||||
|
sqliteRandomness(sizeof(lk), &lk);
|
||||||
|
lk = (lk & 0x7fffffff)%N_LOCKBYTE + 1;
|
||||||
while( cnt-->0 && (res = LockFile(id->h, FIRST_LOCKBYTE, 0, 1, 0))==0 ){
|
while( cnt-->0 && (res = LockFile(id->h, FIRST_LOCKBYTE, 0, 1, 0))==0 ){
|
||||||
Sleep(1);
|
Sleep(1);
|
||||||
}
|
}
|
||||||
@@ -1359,10 +1361,12 @@ int sqliteOsReadLock(OsFile *id){
|
|||||||
if( id->locked>0 || id->refNumRF == -1 ){
|
if( id->locked>0 || id->refNumRF == -1 ){
|
||||||
rc = SQLITE_OK;
|
rc = SQLITE_OK;
|
||||||
}else{
|
}else{
|
||||||
int lk = (sqliteRandomInteger() & 0x7ffffff)%N_LOCKBYTE+1;
|
int lk;
|
||||||
OSErr res;
|
OSErr res;
|
||||||
int cnt = 5;
|
int cnt = 5;
|
||||||
ParamBlockRec params;
|
ParamBlockRec params;
|
||||||
|
sqliteRandomness(sizeof(lk), &lk);
|
||||||
|
lk = (lk & 0x7fffffff)%N_LOCKBYTE + 1;
|
||||||
memset(¶ms, 0, sizeof(params));
|
memset(¶ms, 0, sizeof(params));
|
||||||
params.ioParam.ioRefNum = id->refNumRF;
|
params.ioParam.ioRefNum = id->refNumRF;
|
||||||
params.ioParam.ioPosMode = fsFromStart;
|
params.ioParam.ioPosMode = fsFromStart;
|
||||||
|
@@ -18,7 +18,7 @@
|
|||||||
** file simultaneously, or one process from reading the database while
|
** file simultaneously, or one process from reading the database while
|
||||||
** another is writing.
|
** another is writing.
|
||||||
**
|
**
|
||||||
** @(#) $Id: pager.c,v 1.99 2004/02/11 02:18:07 drh Exp $
|
** @(#) $Id: pager.c,v 1.100 2004/02/11 09:46:32 drh Exp $
|
||||||
*/
|
*/
|
||||||
#include "os.h" /* Must be first to enable large file support */
|
#include "os.h" /* Must be first to enable large file support */
|
||||||
#include "sqliteInt.h"
|
#include "sqliteInt.h"
|
||||||
@@ -1664,7 +1664,7 @@ static int pager_open_journal(Pager *pPager){
|
|||||||
rc = write32bits(&pPager->jfd, pPager->noSync ? 0xffffffff : 0);
|
rc = write32bits(&pPager->jfd, pPager->noSync ? 0xffffffff : 0);
|
||||||
}
|
}
|
||||||
if( rc==SQLITE_OK ){
|
if( rc==SQLITE_OK ){
|
||||||
pPager->cksumInit = (u32)sqliteRandomInteger();
|
sqliteRandomness(sizeof(pPager->cksumInit), &pPager->cksumInit);
|
||||||
rc = write32bits(&pPager->jfd, pPager->cksumInit);
|
rc = write32bits(&pPager->jfd, pPager->cksumInit);
|
||||||
}
|
}
|
||||||
}else if( journal_format==JOURNAL_FORMAT_2 ){
|
}else if( journal_format==JOURNAL_FORMAT_2 ){
|
||||||
|
46
src/random.c
46
src/random.c
@@ -15,7 +15,7 @@
|
|||||||
** Random numbers are used by some of the database backends in order
|
** Random numbers are used by some of the database backends in order
|
||||||
** to generate random integer keys for tables or random filenames.
|
** to generate random integer keys for tables or random filenames.
|
||||||
**
|
**
|
||||||
** $Id: random.c,v 1.10 2002/02/19 13:39:23 drh Exp $
|
** $Id: random.c,v 1.11 2004/02/11 09:46:33 drh Exp $
|
||||||
*/
|
*/
|
||||||
#include "sqliteInt.h"
|
#include "sqliteInt.h"
|
||||||
#include "os.h"
|
#include "os.h"
|
||||||
@@ -35,15 +35,15 @@
|
|||||||
** on RC4, which we know works very well.
|
** on RC4, which we know works very well.
|
||||||
*/
|
*/
|
||||||
static int randomByte(){
|
static int randomByte(){
|
||||||
int t;
|
unsigned char t;
|
||||||
|
|
||||||
/* All threads share a single random number generator.
|
/* All threads share a single random number generator.
|
||||||
** This structure is the current state of the generator.
|
** This structure is the current state of the generator.
|
||||||
*/
|
*/
|
||||||
static struct {
|
static struct {
|
||||||
int isInit; /* True if initialized */
|
unsigned char isInit; /* True if initialized */
|
||||||
int i, j; /* State variables */
|
unsigned char i, j; /* State variables */
|
||||||
int s[256]; /* State variables */
|
unsigned char s[256]; /* State variables */
|
||||||
} prng;
|
} prng;
|
||||||
|
|
||||||
/* Initialize the state of the random number generator once,
|
/* Initialize the state of the random number generator once,
|
||||||
@@ -65,8 +65,7 @@ static int randomByte(){
|
|||||||
prng.s[i] = i;
|
prng.s[i] = i;
|
||||||
}
|
}
|
||||||
for(i=0; i<256; i++){
|
for(i=0; i<256; i++){
|
||||||
int t;
|
prng.j += prng.s[i] + k[i];
|
||||||
prng.j = (prng.j + prng.s[i] + k[i]) & 0xff;
|
|
||||||
t = prng.s[prng.j];
|
t = prng.s[prng.j];
|
||||||
prng.s[prng.j] = prng.s[i];
|
prng.s[prng.j] = prng.s[i];
|
||||||
prng.s[i] = t;
|
prng.s[i] = t;
|
||||||
@@ -76,38 +75,23 @@ static int randomByte(){
|
|||||||
|
|
||||||
/* Generate and return single random byte
|
/* Generate and return single random byte
|
||||||
*/
|
*/
|
||||||
prng.i = (prng.i + 1) & 0xff;
|
prng.i++;
|
||||||
prng.j = (prng.j + prng.s[prng.i]) & 0xff;
|
|
||||||
t = prng.s[prng.i];
|
t = prng.s[prng.i];
|
||||||
|
prng.j += t;
|
||||||
prng.s[prng.i] = prng.s[prng.j];
|
prng.s[prng.i] = prng.s[prng.j];
|
||||||
prng.s[prng.j] = t;
|
prng.s[prng.j] = t;
|
||||||
t = prng.s[prng.i] + prng.s[prng.j];
|
t += prng.s[prng.i];
|
||||||
return prng.s[t & 0xff];
|
return prng.s[t];
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
** Return an random 8-bit integer.
|
** Return N random bytes.
|
||||||
*/
|
*/
|
||||||
int sqliteRandomByte(){
|
void sqliteRandomness(int N, void *pBuf){
|
||||||
int r;
|
unsigned char *zBuf = pBuf;
|
||||||
sqliteOsEnterMutex();
|
sqliteOsEnterMutex();
|
||||||
r = randomByte();
|
while( N-- ){
|
||||||
sqliteOsLeaveMutex();
|
*(zBuf++) = randomByte();
|
||||||
return r;
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
|
||||||
** Return a random 32-bit integer. The integer is generated by making
|
|
||||||
** 4 calls to sqliteRandomByte().
|
|
||||||
*/
|
|
||||||
int sqliteRandomInteger(){
|
|
||||||
int r;
|
|
||||||
int i;
|
|
||||||
sqliteOsEnterMutex();
|
|
||||||
r = randomByte();
|
|
||||||
for(i=1; i<4; i++){
|
|
||||||
r = (r<<8) + randomByte();
|
|
||||||
}
|
}
|
||||||
sqliteOsLeaveMutex();
|
sqliteOsLeaveMutex();
|
||||||
return r;
|
|
||||||
}
|
}
|
||||||
|
@@ -11,7 +11,7 @@
|
|||||||
*************************************************************************
|
*************************************************************************
|
||||||
** Internal interface definitions for SQLite.
|
** Internal interface definitions for SQLite.
|
||||||
**
|
**
|
||||||
** @(#) $Id: sqliteInt.h,v 1.209 2004/01/16 15:55:38 drh Exp $
|
** @(#) $Id: sqliteInt.h,v 1.210 2004/02/11 09:46:33 drh Exp $
|
||||||
*/
|
*/
|
||||||
#include "config.h"
|
#include "config.h"
|
||||||
#include "sqlite.h"
|
#include "sqlite.h"
|
||||||
@@ -1151,8 +1151,7 @@ int sqliteFuncId(Token*);
|
|||||||
int sqliteExprResolveIds(Parse*, SrcList*, ExprList*, Expr*);
|
int sqliteExprResolveIds(Parse*, SrcList*, ExprList*, Expr*);
|
||||||
int sqliteExprAnalyzeAggregates(Parse*, Expr*);
|
int sqliteExprAnalyzeAggregates(Parse*, Expr*);
|
||||||
Vdbe *sqliteGetVdbe(Parse*);
|
Vdbe *sqliteGetVdbe(Parse*);
|
||||||
int sqliteRandomByte(void);
|
void sqliteRandomness(int, void*);
|
||||||
int sqliteRandomInteger(void);
|
|
||||||
void sqliteRollbackAll(sqlite*);
|
void sqliteRollbackAll(sqlite*);
|
||||||
void sqliteCodeVerifySchema(Parse*, int);
|
void sqliteCodeVerifySchema(Parse*, int);
|
||||||
void sqliteBeginTransaction(Parse*, int);
|
void sqliteBeginTransaction(Parse*, int);
|
||||||
|
10
src/vacuum.c
10
src/vacuum.c
@@ -14,7 +14,7 @@
|
|||||||
** Most of the code in this file may be omitted by defining the
|
** Most of the code in this file may be omitted by defining the
|
||||||
** SQLITE_OMIT_VACUUM macro.
|
** SQLITE_OMIT_VACUUM macro.
|
||||||
**
|
**
|
||||||
** $Id: vacuum.c,v 1.9 2003/12/07 00:24:35 drh Exp $
|
** $Id: vacuum.c,v 1.10 2004/02/11 09:46:33 drh Exp $
|
||||||
*/
|
*/
|
||||||
#include "sqliteInt.h"
|
#include "sqliteInt.h"
|
||||||
#include "os.h"
|
#include "os.h"
|
||||||
@@ -185,14 +185,14 @@ static int vacuumCallback3(void *pArg, int argc, char **argv, char **NotUsed){
|
|||||||
/*
|
/*
|
||||||
** Generate a random name of 20 character in length.
|
** Generate a random name of 20 character in length.
|
||||||
*/
|
*/
|
||||||
static void randomName(char *zBuf){
|
static void randomName(unsigned char *zBuf){
|
||||||
static const char zChars[] =
|
static const unsigned char zChars[] =
|
||||||
"abcdefghijklmnopqrstuvwxyz"
|
"abcdefghijklmnopqrstuvwxyz"
|
||||||
"0123456789";
|
"0123456789";
|
||||||
int i;
|
int i;
|
||||||
|
sqliteRandomness(20, zBuf);
|
||||||
for(i=0; i<20; i++){
|
for(i=0; i<20; i++){
|
||||||
int n = sqliteRandomByte() % (sizeof(zChars)-1);
|
zBuf[i] = zChars[ zBuf[i]%(sizeof(zChars)-1) ];
|
||||||
zBuf[i] = zChars[n];
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
@@ -43,7 +43,7 @@
|
|||||||
** in this file for details. If in doubt, do not deviate from existing
|
** in this file for details. If in doubt, do not deviate from existing
|
||||||
** commenting and indentation practices when changing or adding code.
|
** commenting and indentation practices when changing or adding code.
|
||||||
**
|
**
|
||||||
** $Id: vdbe.c,v 1.258 2004/02/10 13:41:52 drh Exp $
|
** $Id: vdbe.c,v 1.259 2004/02/11 09:46:33 drh Exp $
|
||||||
*/
|
*/
|
||||||
#include "sqliteInt.h"
|
#include "sqliteInt.h"
|
||||||
#include "os.h"
|
#include "os.h"
|
||||||
@@ -2893,10 +2893,12 @@ case OP_NewRecno: {
|
|||||||
cnt = 0;
|
cnt = 0;
|
||||||
do{
|
do{
|
||||||
if( v==0 || cnt>2 ){
|
if( v==0 || cnt>2 ){
|
||||||
v = sqliteRandomInteger();
|
sqliteRandomness(sizeof(v), &v);
|
||||||
if( cnt<5 ) v &= 0xffffff;
|
if( cnt<5 ) v &= 0xffffff;
|
||||||
}else{
|
}else{
|
||||||
v += sqliteRandomByte() + 1;
|
unsigned char r;
|
||||||
|
sqliteRandomness(1, &r);
|
||||||
|
v += r + 1;
|
||||||
}
|
}
|
||||||
if( v==0 ) continue;
|
if( v==0 ) continue;
|
||||||
x = intToKey(v);
|
x = intToKey(v);
|
||||||
|
Reference in New Issue
Block a user