Unnamed Fossil Project

Check-in [0f4ad7934f]
Login

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

Overview
Comment:updated
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1:0f4ad7934f9b9fc3d11037dc8a3ec02f784108bf
User & Date: monster 2012-08-09 02:55:09
Context
2012-08-10
08:43
fixes check-in: 282111e83e user: monster tags: trunk
2012-08-09
02:55
updated check-in: 0f4ad7934f user: monster tags: trunk
01:06
mySQL backend for XDDB check-in: 64eb4d0d7d user: monster tags: trunk
Changes
Hide Diffs Unified Diffs Ignore Whitespace Patch

Changes to mysql.hc.







1
2
3
4
5
6
7







#include <mysql.h>
#include <mysqld_error.h>

#ifdef _LIBYOYO
#define _YO_MYSQL_BUILTIN
#endif
>
>
>
>
>
>







1
2
3
4
5
6
7
8
9
10
11
12
13

#include "yoyo.hc"

#ifdef __windoze
# include <winsock2.h>
#endif

#include <mysql.h>
#include <mysqld_error.h>

#ifdef _LIBYOYO
#define _YO_MYSQL_BUILTIN
#endif

Changes to tests/xddb.c.

1
2
3
4
5
6
7
8
9
10

11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
..
42
43
44
45
46
47
48


49
50


51
52
53
54
55
56
57

#include <crtdbg.h>

#define _LIBYOYO

#include "../tcpip.hc"
#include "../xddbfs.hc"
#include "../xddbmsql.hc"
#include "../prog.hc"
#include "../tesuite.hc"


YO_XDDB *Open_Xddb(int create_new)
  {
    char *db_source = Prog_Arguments_Count()?Prog_Argument(0):"xddb"; 
    YO_XDDB *xddb = 0;
    
    if ( 0 ) ;
    else if ( Str_Starts_With(db_source,"mysql://") )
      {
        xddb = XddbMsql_Connect(db_source,"123qwe",XDDB_FORMAT_ZIPPED_TEXT,create_new);
      }
    else
      {
        xddb = Xddbfs_Open(db_source,create_new,XDDB_FORMAT_TEXT,0);
      }
      
    return xddb;
................................................................................
        Tesuite_Info(__Format("xddb test, source: %s, format: %s",
                                    Xddb_Source_String(xddb),
                                    Xddb_Format_String(xddb)));
                                    
        unique = Xddb_Build_Unique_Key();
        doc = Xdata_Init();
        Xnode_Value_Set_Str(&doc->root,"unique",unique);


        key = Xddb_Unique(xddb,doc);
        doc = Xddb_Get(xddb,key,XDDB_RAISE_IF_DSNT_EXSIST);


        if ( strcmp(Xnode_Value_Get_Str(&doc->root,"unique",""),unique) )
          __Raise(YO_ERROR_TESUITE_FAIL,"document is not consistent");
        Xddb_Delete(xddb,key);
        if ( Xddb_Has(xddb,key) )
          __Raise(YO_ERROR_TESUITE_FAIL,"document still present in store");
        
        Tesuite_Case_Successed();





<




>









|







 







>
>


>
>







1
2
3
4
5

6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
..
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61

#include <crtdbg.h>

#define _LIBYOYO


#include "../xddbfs.hc"
#include "../xddbmsql.hc"
#include "../prog.hc"
#include "../tesuite.hc"
#include "../xdatasec.hc"

YO_XDDB *Open_Xddb(int create_new)
  {
    char *db_source = Prog_Arguments_Count()?Prog_Argument(0):"xddb"; 
    YO_XDDB *xddb = 0;
    
    if ( 0 ) ;
    else if ( Str_Starts_With(db_source,"mysql://") )
      {
        xddb = XddbMsql_Connect(db_source,"",XDDB_FORMAT_ZIPPED_TEXT,create_new);
      }
    else
      {
        xddb = Xddbfs_Open(db_source,create_new,XDDB_FORMAT_TEXT,0);
      }
      
    return xddb;
................................................................................
        Tesuite_Info(__Format("xddb test, source: %s, format: %s",
                                    Xddb_Source_String(xddb),
                                    Xddb_Format_String(xddb)));
                                    
        unique = Xddb_Build_Unique_Key();
        doc = Xdata_Init();
        Xnode_Value_Set_Str(&doc->root,"unique",unique);
        Xnode_Value_Set_Str(&doc->root,"u","_%\032\b\t\r\n\\\'\"");
        Xdata_Sha1_Update(doc);
        key = Xddb_Unique(xddb,doc);
        doc = Xddb_Get(xddb,key,XDDB_RAISE_IF_DSNT_EXSIST);
        if ( !Xdata_Sha1_Verify(doc) )
          __Raise(YO_ERROR_TESUITE_FAIL,"document is not consistent");
        if ( strcmp(Xnode_Value_Get_Str(&doc->root,"unique",""),unique) )
          __Raise(YO_ERROR_TESUITE_FAIL,"document is not consistent");
        Xddb_Delete(xddb,key);
        if ( Xddb_Has(xddb,key) )
          __Raise(YO_ERROR_TESUITE_FAIL,"document still present in store");
        
        Tesuite_Case_Successed();

Changes to xddb.hc.

167
168
169
170
171
172
173


174
175
176
177
178
179
180
...
210
211
212
213
214
215
216



217
218
219
220
221
222
223
    else if ( xddb->doc_format == XDDB_FORMAT_BINARY )
      ;//Xdata_Binary_Encode_Into(bf,doc,0);
    else if ( xddb->doc_format == XDDB_FORMAT_ZIPPED_BINARY )
      ;//Xdata_Binary_Encode_Into(bf,doc,1);
    else
      __Raise(YO_ERROR_INCONSISTENT,__yoTa("unsupported document format",0));



    if ( xddb->esc_put || xddb->encrypt )
      {
        if ( xddb->encrypt )
          {
          }
        if ( xddb->esc_put ) __Auto_Release
          {
................................................................................
                bf = Buffer_Reserve(0,count);
                //Buffer_Unesc_Append(bf,at,count);
                at = bf->bytes;
                count = bf->count;
              }
          }
        



        switch ( at[8] )
          {
            case XDDB_FORMAT_TEXT:
              doc = Def_Parse_Str(at+16);
              break;
            case XDDB_FORMAT_ZIPPED_TEXT:
              {







>
>







 







>
>
>







167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
...
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
    else if ( xddb->doc_format == XDDB_FORMAT_BINARY )
      ;//Xdata_Binary_Encode_Into(bf,doc,0);
    else if ( xddb->doc_format == XDDB_FORMAT_ZIPPED_BINARY )
      ;//Xdata_Binary_Encode_Into(bf,doc,1);
    else
      __Raise(YO_ERROR_INCONSISTENT,__yoTa("unsupported document format",0));

    Unsigned_To_Hex2(Crc_8(0,bf->at+16,bf->count-16),bf->at+13);

    if ( xddb->esc_put || xddb->encrypt )
      {
        if ( xddb->encrypt )
          {
          }
        if ( xddb->esc_put ) __Auto_Release
          {
................................................................................
                bf = Buffer_Reserve(0,count);
                //Buffer_Unesc_Append(bf,at,count);
                at = bf->bytes;
                count = bf->count;
              }
          }
        
        if ( Crc_8(0,at+16,count-16) != Hex2_To_Unsigned(at+13) )
          __Raise(YO_ERROR_CORRUPTED,__yoTa("document corrupted",0));

        switch ( at[8] )
          {
            case XDDB_FORMAT_TEXT:
              doc = Def_Parse_Str(at+16);
              break;
            case XDDB_FORMAT_ZIPPED_TEXT:
              {

Changes to xddbmsql.hc.

177
178
179
180
181
182
183
184
185

186
187
188
189
190
191
192
      {
        do 
          { 
            if ( *p == '\\' || *p == '"' 
              || *p == '\'' || *p == 0 
              || *p == '\b' || *p == '\n'
              || *p == '\r' || *p == '\t'
              || *p == 26   || *p == '%' 
              || *p == '_' ) 

              break; 
            ++p; 
          } 
        while ( p != E );
        
        if ( q != p )
          Buffer_Append(bf,q,p-q);







|
|
>







177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
      {
        do 
          { 
            if ( *p == '\\' || *p == '"' 
              || *p == '\'' || *p == 0 
              || *p == '\b' || *p == '\n'
              || *p == '\r' || *p == '\t'
              //|| *p == '%' 
              //|| *p == '_' 
              || *p == 26  ) 
              break; 
            ++p; 
          } 
        while ( p != E );
        
        if ( q != p )
          Buffer_Append(bf,q,p-q);

Changes to xdef.hc.

107
108
109
110
111
112
113






114
115
116
117
118
119
120
                  __Vector_Append(&out,&len,&capacity,st->text,1);
                else if ( *st->text == 'n' )
                  __Vector_Append(&out,&len,&capacity,"\n",1);
                else if ( *st->text == 'r' )
                  __Vector_Append(&out,&len,&capacity,"\r",1);
                else if ( *st->text == 't' )
                  __Vector_Append(&out,&len,&capacity,"\t",1);






                else 
                  __Raise(YO_ERROR_ILLFORMED,__Format("invalid esc sequence at line %d",st->lineno));
              }
            else
              __Vector_Append(&out,&len,&capacity,st->text,1);
          }
          







>
>
>
>
>
>







107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
                  __Vector_Append(&out,&len,&capacity,st->text,1);
                else if ( *st->text == 'n' )
                  __Vector_Append(&out,&len,&capacity,"\n",1);
                else if ( *st->text == 'r' )
                  __Vector_Append(&out,&len,&capacity,"\r",1);
                else if ( *st->text == 't' )
                  __Vector_Append(&out,&len,&capacity,"\t",1);
                else if ( *st->text == 'x' )
                  {
                    byte_t q = Str_Unhex_Byte(st->text+1,0,0);
                    st->text += 2;
                    __Vector_Append(&out,&len,&capacity,&q,1);
                  }
                else 
                  __Raise(YO_ERROR_ILLFORMED,__Format("invalid esc sequence at line %d",st->lineno));
              }
            else
              __Vector_Append(&out,&len,&capacity,st->text,1);
          }
          

Changes to yoyo.hc.

568
569
570
571
572
573
574


















575
576
577
578
579
580
581
....
1199
1200
1201
1202
1203
1204
1205







1206
1207
1208
1209
1210
1211
1212
....
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
....
1407
1408
1409
1410
1411
1412
1413




1414
1415
1416
1417
1418
1419
1420
# define STRICT_REQUIRE(Expr) REQUIRE(Expr)
# define STRICT_CHECK(Expr) (Expr)
#else
# define STRICT_REQUIRE(Expr) ((void)0)
# define STRICT_CHECK(Expr) (1)
#endif /* _STRICT */



















#define Slist_Remove_By(ListPtr,Next,Val) Yo_Slist_Remove((void**)ListPtr,(int)((size_t)(&(*ListPtr)->Next)-(size_t)(*ListPtr)),Val)
#define Slist_Remove(ListPtr,Val) Slist_Remove_By(ListPtr,next,Val)

void Yo_Slist_Remove(void **p, int offs_of_next, void *val)
#ifdef _YO_CORE_BUILTIN
  {
    if ( p ) 
................................................................................
  }
#endif
  ;

void Yo_Global_Cleanup()
#ifdef _YO_CORE_BUILTIN
  {







  }
#endif
  ;

void *Yo_Malloc(unsigned size)
  _YO_CORE_BUILTIN_CODE({return Yo_Pool(Yo_Malloc_Npl(size));});
void *Yo_Realloc(void *p,unsigned size)
................................................................................
    f->func = func;

    return o;
  }
#endif
  ;

enum 
  { 
    YO_OBJECT_SIGNATURE_PFX  =  0x00594f59, /*'YOY'*/  
    YO_OBJECT_SIGNATURE_HEAP =  0x4f594f59, /*'YOYO'*/  
    YO_MEMPOOL_PIECE_MAXSIZE = 1*KILOBYTE,
    YO_MEMPOOL_PIECE_ON_BLOCK= 16,
    YO_MEMPOOL_PIECE_STEP    = 64,
    YO_MEMPOOL_SLOTS_COUNT   = YO_MEMPOOL_PIECE_MAXSIZE/YO_MEMPOOL_PIECE_STEP,
  };

__Static_Assert(YO_MEMPOOL_SLOTS_COUNT <= 'O');

#ifdef _YO_CORE_BUILTIN
void *Yo_Mempool_Slots[YO_MEMPOOL_SLOTS_COUNT] = {0,};
int Yo_Mempool_Counts[YO_MEMPOOL_SLOTS_COUNT] = {0,};
#endif

void Yo_Mempool_Free(void *p,int plidx)
#ifdef _YO_CORE_BUILTIN
  {
    void **Q = p;
    STRICT_REQUIRE(plidx >= 0 && plidx <YO_MEMPOOL_SLOTS_COUNT); 
    for (;;)
      {
................................................................................
    __Xchg_Interlock
      {
        void * volatile *S = Yo_Mempool_Slots+plidx;
        if ( !*S )
          {
            int i,piece = (plidx+1)*YO_MEMPOOL_PIECE_STEP; 
            void **Q = Yo_Malloc_Npl(piece*YO_MEMPOOL_PIECE_ON_BLOCK);




            Yo_Mempool_Counts[plidx] += YO_MEMPOOL_PIECE_ON_BLOCK;
            for ( i=0; i < YO_MEMPOOL_PIECE_ON_BLOCK; ++i, Q = (void**)((byte_t*)Q + piece) )
              for (;;)
                {
                  *Q = *S;
                  if ( __Atomic_CmpXchg_Ptr(S,Q,*Q) ) break;
                }







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







 







>
>
>
>
>
>
>







 







<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<







 







>
>
>
>







568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
....
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
....
1390
1391
1392
1393
1394
1395
1396

















1397
1398
1399
1400
1401
1402
1403
....
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
# define STRICT_REQUIRE(Expr) REQUIRE(Expr)
# define STRICT_CHECK(Expr) (Expr)
#else
# define STRICT_REQUIRE(Expr) ((void)0)
# define STRICT_CHECK(Expr) (1)
#endif /* _STRICT */

enum 
  { 
    YO_OBJECT_SIGNATURE_PFX  =  0x00594f59, /*'YOY'*/  
    YO_OBJECT_SIGNATURE_HEAP =  0x4f594f59, /*'YOYO'*/  
    YO_MEMPOOL_PIECE_MAXSIZE = 1*KILOBYTE,
    YO_MEMPOOL_PIECE_ON_BLOCK= 16,
    YO_MEMPOOL_PIECE_STEP    = 64,
    YO_MEMPOOL_SLOTS_COUNT   = YO_MEMPOOL_PIECE_MAXSIZE/YO_MEMPOOL_PIECE_STEP,
  };

__Static_Assert(YO_MEMPOOL_SLOTS_COUNT <= 'O');

#ifdef _YO_CORE_BUILTIN
void **Yo_Mempool_Blocks = 0;
void *Yo_Mempool_Slots[YO_MEMPOOL_SLOTS_COUNT] = {0,};
int Yo_Mempool_Counts[YO_MEMPOOL_SLOTS_COUNT] = {0,};
#endif

#define Slist_Remove_By(ListPtr,Next,Val) Yo_Slist_Remove((void**)ListPtr,(int)((size_t)(&(*ListPtr)->Next)-(size_t)(*ListPtr)),Val)
#define Slist_Remove(ListPtr,Val) Slist_Remove_By(ListPtr,next,Val)

void Yo_Slist_Remove(void **p, int offs_of_next, void *val)
#ifdef _YO_CORE_BUILTIN
  {
    if ( p ) 
................................................................................
  }
#endif
  ;

void Yo_Global_Cleanup()
#ifdef _YO_CORE_BUILTIN
  {
    while ( Yo_Mempool_Blocks )
      {
        void **Q = Yo_Mempool_Blocks;
        Yo_Mempool_Blocks = *Q;
        free(Q[1]);
        free(Q);
      }
  }
#endif
  ;

void *Yo_Malloc(unsigned size)
  _YO_CORE_BUILTIN_CODE({return Yo_Pool(Yo_Malloc_Npl(size));});
void *Yo_Realloc(void *p,unsigned size)
................................................................................
    f->func = func;

    return o;
  }
#endif
  ;


















void Yo_Mempool_Free(void *p,int plidx)
#ifdef _YO_CORE_BUILTIN
  {
    void **Q = p;
    STRICT_REQUIRE(plidx >= 0 && plidx <YO_MEMPOOL_SLOTS_COUNT); 
    for (;;)
      {
................................................................................
    __Xchg_Interlock
      {
        void * volatile *S = Yo_Mempool_Slots+plidx;
        if ( !*S )
          {
            int i,piece = (plidx+1)*YO_MEMPOOL_PIECE_STEP; 
            void **Q = Yo_Malloc_Npl(piece*YO_MEMPOOL_PIECE_ON_BLOCK);
            void **R = Yo_Malloc_Npl(sizeof(void*)*2);
            R[1] = Q;
            R[0] = Yo_Mempool_Blocks;
            Yo_Mempool_Blocks = R;
            Yo_Mempool_Counts[plidx] += YO_MEMPOOL_PIECE_ON_BLOCK;
            for ( i=0; i < YO_MEMPOOL_PIECE_ON_BLOCK; ++i, Q = (void**)((byte_t*)Q + piece) )
              for (;;)
                {
                  *Q = *S;
                  if ( __Atomic_CmpXchg_Ptr(S,Q,*Q) ) break;
                }

Changes to zlib.hc.

87
88
89
90
91
92
93

94

95
96
97
98
99
100
101
102
        case ZLIB_VERSION_ERROR: return "Z_VERSION_ERROR";
      }
    return "unknown error";
  }
#endif
  ;
  

extern int compress(void *dst, long *dst_len, void *src, long src);

extern int uncompress(void *dst, long *dst_len, void *src, long src);

int Zlib_Compress(void *dst, long *dst_len, void *src, long src_len)
#ifdef _YO_ZLIB_BUILTIN
  {
    return compress(dst,dst_len,src,src_len);
  }
#endif







>
|
>
|







87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
        case ZLIB_VERSION_ERROR: return "Z_VERSION_ERROR";
      }
    return "unknown error";
  }
#endif
  ;
  
#undef compress
int compress(void *dst, long *dst_len, void *src, long src_len);
#undef uncompress
int uncompress(void *dst, long *dst_len, void *src, long src_len);

int Zlib_Compress(void *dst, long *dst_len, void *src, long src_len)
#ifdef _YO_ZLIB_BUILTIN
  {
    return compress(dst,dst_len,src,src_len);
  }
#endif