tokyomessenger 0.5
Sign up to get free protection for your applications and to get access to all the features.
- data/COPYING +504 -0
- data/README.rdoc +224 -0
- data/Rakefile +72 -0
- data/benchmarks/balancer.rb +101 -0
- data/benchmarks/bulk_db.rb +92 -0
- data/benchmarks/bulk_table.rb +104 -0
- data/benchmarks/db.rb +131 -0
- data/benchmarks/table.rb +186 -0
- data/ext/a.h +496 -0
- data/ext/extconf.rb +27 -0
- data/ext/md5.c +381 -0
- data/ext/md5.h +101 -0
- data/ext/tc_myconf.c +493 -0
- data/ext/tc_myconf.h +543 -0
- data/ext/tcadb.c +4339 -0
- data/ext/tcadb.h +533 -0
- data/ext/tcbdb.c +4180 -0
- data/ext/tcbdb.h +1086 -0
- data/ext/tcfdb.c +2746 -0
- data/ext/tcfdb.h +842 -0
- data/ext/tchdb.c +5153 -0
- data/ext/tchdb.h +856 -0
- data/ext/tcrdb.c +2637 -0
- data/ext/tcrdb.h +785 -0
- data/ext/tctdb.c +6199 -0
- data/ext/tctdb.h +1070 -0
- data/ext/tcutil.c +10528 -0
- data/ext/tcutil.h +4166 -0
- data/ext/tokyo_messenger.c +147 -0
- data/ext/tokyo_messenger.h +49 -0
- data/ext/tokyo_messenger_db.c +227 -0
- data/ext/tokyo_messenger_db.h +8 -0
- data/ext/tokyo_messenger_module.c +453 -0
- data/ext/tokyo_messenger_module.h +10 -0
- data/ext/tokyo_messenger_query.c +226 -0
- data/ext/tokyo_messenger_query.h +9 -0
- data/ext/tokyo_messenger_table.c +319 -0
- data/ext/tokyo_messenger_table.h +8 -0
- data/ext/tt_myconf.c +169 -0
- data/ext/tt_myconf.h +408 -0
- data/ext/ttutil.c +1509 -0
- data/ext/ttutil.h +480 -0
- data/lib/tokyo_messenger/balancer.rb +188 -0
- data/spec/ext.lua +4 -0
- data/spec/plu_db.rb +538 -0
- data/spec/spec.rb +1 -0
- data/spec/spec_base.rb +17 -0
- data/spec/start_tyrants.sh +36 -0
- data/spec/stop_tyrants.sh +9 -0
- data/spec/tokyo_tyrant_balancer_db_spec.rb +160 -0
- data/spec/tokyo_tyrant_balancer_table_spec.rb +177 -0
- data/spec/tokyo_tyrant_query_spec.rb +159 -0
- data/spec/tokyo_tyrant_spec.rb +254 -0
- data/spec/tokyo_tyrant_table_spec.rb +301 -0
- metadata +117 -0
data/ext/tc_myconf.c
ADDED
@@ -0,0 +1,493 @@
|
|
1
|
+
/*************************************************************************************************
|
2
|
+
* System-dependent configurations of Tokyo Cabinet
|
3
|
+
* Copyright (C) 2006-2009 Mikio Hirabayashi
|
4
|
+
* This file is part of Tokyo Cabinet.
|
5
|
+
* Tokyo Cabinet is free software; you can redistribute it and/or modify it under the terms of
|
6
|
+
* the GNU Lesser General Public License as published by the Free Software Foundation; either
|
7
|
+
* version 2.1 of the License or any later version. Tokyo Cabinet is distributed in the hope
|
8
|
+
* that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
|
9
|
+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
|
10
|
+
* License for more details.
|
11
|
+
* You should have received a copy of the GNU Lesser General Public License along with Tokyo
|
12
|
+
* Cabinet; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330,
|
13
|
+
* Boston, MA 02111-1307 USA.
|
14
|
+
*************************************************************************************************/
|
15
|
+
|
16
|
+
|
17
|
+
#include "tc_myconf.h"
|
18
|
+
|
19
|
+
|
20
|
+
|
21
|
+
/*************************************************************************************************
|
22
|
+
* common settings
|
23
|
+
*************************************************************************************************/
|
24
|
+
|
25
|
+
|
26
|
+
int _tc_dummy_cnt = 0;
|
27
|
+
|
28
|
+
|
29
|
+
int _tc_dummyfunc(void){
|
30
|
+
return 0;
|
31
|
+
}
|
32
|
+
|
33
|
+
|
34
|
+
int _tc_dummyfuncv(int a, ...){
|
35
|
+
return 0;
|
36
|
+
}
|
37
|
+
|
38
|
+
|
39
|
+
|
40
|
+
/*************************************************************************************************
|
41
|
+
* for ZLIB
|
42
|
+
*************************************************************************************************/
|
43
|
+
|
44
|
+
|
45
|
+
#if TCUSEZLIB
|
46
|
+
|
47
|
+
|
48
|
+
#include <zlib.h>
|
49
|
+
|
50
|
+
#define ZLIBBUFSIZ 8192
|
51
|
+
|
52
|
+
|
53
|
+
static char *_tc_deflate_impl(const char *ptr, int size, int *sp, int mode);
|
54
|
+
static char *_tc_inflate_impl(const char *ptr, int size, int *sp, int mode);
|
55
|
+
static unsigned int _tc_getcrc_impl(const char *ptr, int size);
|
56
|
+
|
57
|
+
|
58
|
+
char *(*_tc_deflate)(const char *, int, int *, int) = _tc_deflate_impl;
|
59
|
+
char *(*_tc_inflate)(const char *, int, int *, int) = _tc_inflate_impl;
|
60
|
+
unsigned int (*_tc_getcrc)(const char *, int) = _tc_getcrc_impl;
|
61
|
+
|
62
|
+
|
63
|
+
static char *_tc_deflate_impl(const char *ptr, int size, int *sp, int mode){
|
64
|
+
assert(ptr && size >= 0 && sp);
|
65
|
+
z_stream zs;
|
66
|
+
zs.zalloc = Z_NULL;
|
67
|
+
zs.zfree = Z_NULL;
|
68
|
+
zs.opaque = Z_NULL;
|
69
|
+
switch(mode){
|
70
|
+
case _TCZMRAW:
|
71
|
+
if(deflateInit2(&zs, 5, Z_DEFLATED, -15, 7, Z_DEFAULT_STRATEGY) != Z_OK)
|
72
|
+
return NULL;
|
73
|
+
break;
|
74
|
+
case _TCZMGZIP:
|
75
|
+
if(deflateInit2(&zs, 6, Z_DEFLATED, 15 + 16, 9, Z_DEFAULT_STRATEGY) != Z_OK)
|
76
|
+
return NULL;
|
77
|
+
break;
|
78
|
+
default:
|
79
|
+
if(deflateInit2(&zs, 6, Z_DEFLATED, 15, 8, Z_DEFAULT_STRATEGY) != Z_OK)
|
80
|
+
return NULL;
|
81
|
+
break;
|
82
|
+
}
|
83
|
+
int asiz = size + 16;
|
84
|
+
if(asiz < ZLIBBUFSIZ) asiz = ZLIBBUFSIZ;
|
85
|
+
char *buf;
|
86
|
+
if(!(buf = MYMALLOC(asiz))){
|
87
|
+
deflateEnd(&zs);
|
88
|
+
return NULL;
|
89
|
+
}
|
90
|
+
unsigned char obuf[ZLIBBUFSIZ];
|
91
|
+
int bsiz = 0;
|
92
|
+
zs.next_in = (unsigned char *)ptr;
|
93
|
+
zs.avail_in = size;
|
94
|
+
zs.next_out = obuf;
|
95
|
+
zs.avail_out = ZLIBBUFSIZ;
|
96
|
+
int rv;
|
97
|
+
while((rv = deflate(&zs, Z_FINISH)) == Z_OK){
|
98
|
+
int osiz = ZLIBBUFSIZ - zs.avail_out;
|
99
|
+
if(bsiz + osiz > asiz){
|
100
|
+
asiz = asiz * 2 + osiz;
|
101
|
+
char *swap;
|
102
|
+
if(!(swap = MYREALLOC(buf, asiz))){
|
103
|
+
MYFREE(buf);
|
104
|
+
deflateEnd(&zs);
|
105
|
+
return NULL;
|
106
|
+
}
|
107
|
+
buf = swap;
|
108
|
+
}
|
109
|
+
memcpy(buf + bsiz, obuf, osiz);
|
110
|
+
bsiz += osiz;
|
111
|
+
zs.next_out = obuf;
|
112
|
+
zs.avail_out = ZLIBBUFSIZ;
|
113
|
+
}
|
114
|
+
if(rv != Z_STREAM_END){
|
115
|
+
MYFREE(buf);
|
116
|
+
deflateEnd(&zs);
|
117
|
+
return NULL;
|
118
|
+
}
|
119
|
+
int osiz = ZLIBBUFSIZ - zs.avail_out;
|
120
|
+
if(bsiz + osiz + 1 > asiz){
|
121
|
+
asiz = asiz * 2 + osiz;
|
122
|
+
char *swap;
|
123
|
+
if(!(swap = MYREALLOC(buf, asiz))){
|
124
|
+
MYFREE(buf);
|
125
|
+
deflateEnd(&zs);
|
126
|
+
return NULL;
|
127
|
+
}
|
128
|
+
buf = swap;
|
129
|
+
}
|
130
|
+
memcpy(buf + bsiz, obuf, osiz);
|
131
|
+
bsiz += osiz;
|
132
|
+
buf[bsiz] = '\0';
|
133
|
+
if(mode == _TCZMRAW) bsiz++;
|
134
|
+
*sp = bsiz;
|
135
|
+
deflateEnd(&zs);
|
136
|
+
return buf;
|
137
|
+
}
|
138
|
+
|
139
|
+
|
140
|
+
static char *_tc_inflate_impl(const char *ptr, int size, int *sp, int mode){
|
141
|
+
assert(ptr && size >= 0 && sp);
|
142
|
+
z_stream zs;
|
143
|
+
zs.zalloc = Z_NULL;
|
144
|
+
zs.zfree = Z_NULL;
|
145
|
+
zs.opaque = Z_NULL;
|
146
|
+
switch(mode){
|
147
|
+
case _TCZMRAW:
|
148
|
+
if(inflateInit2(&zs, -15) != Z_OK) return NULL;
|
149
|
+
break;
|
150
|
+
case _TCZMGZIP:
|
151
|
+
if(inflateInit2(&zs, 15 + 16) != Z_OK) return NULL;
|
152
|
+
break;
|
153
|
+
default:
|
154
|
+
if(inflateInit2(&zs, 15) != Z_OK) return NULL;
|
155
|
+
break;
|
156
|
+
}
|
157
|
+
int asiz = size * 2 + 16;
|
158
|
+
if(asiz < ZLIBBUFSIZ) asiz = ZLIBBUFSIZ;
|
159
|
+
char *buf;
|
160
|
+
if(!(buf = MYMALLOC(asiz))){
|
161
|
+
inflateEnd(&zs);
|
162
|
+
return NULL;
|
163
|
+
}
|
164
|
+
unsigned char obuf[ZLIBBUFSIZ];
|
165
|
+
int bsiz = 0;
|
166
|
+
zs.next_in = (unsigned char *)ptr;
|
167
|
+
zs.avail_in = size;
|
168
|
+
zs.next_out = obuf;
|
169
|
+
zs.avail_out = ZLIBBUFSIZ;
|
170
|
+
int rv;
|
171
|
+
while((rv = inflate(&zs, Z_NO_FLUSH)) == Z_OK){
|
172
|
+
int osiz = ZLIBBUFSIZ - zs.avail_out;
|
173
|
+
if(bsiz + osiz >= asiz){
|
174
|
+
asiz = asiz * 2 + osiz;
|
175
|
+
char *swap;
|
176
|
+
if(!(swap = MYREALLOC(buf, asiz))){
|
177
|
+
MYFREE(buf);
|
178
|
+
inflateEnd(&zs);
|
179
|
+
return NULL;
|
180
|
+
}
|
181
|
+
buf = swap;
|
182
|
+
}
|
183
|
+
memcpy(buf + bsiz, obuf, osiz);
|
184
|
+
bsiz += osiz;
|
185
|
+
zs.next_out = obuf;
|
186
|
+
zs.avail_out = ZLIBBUFSIZ;
|
187
|
+
}
|
188
|
+
if(rv != Z_STREAM_END){
|
189
|
+
MYFREE(buf);
|
190
|
+
inflateEnd(&zs);
|
191
|
+
return NULL;
|
192
|
+
}
|
193
|
+
int osiz = ZLIBBUFSIZ - zs.avail_out;
|
194
|
+
if(bsiz + osiz >= asiz){
|
195
|
+
asiz = asiz * 2 + osiz;
|
196
|
+
char *swap;
|
197
|
+
if(!(swap = MYREALLOC(buf, asiz))){
|
198
|
+
MYFREE(buf);
|
199
|
+
inflateEnd(&zs);
|
200
|
+
return NULL;
|
201
|
+
}
|
202
|
+
buf = swap;
|
203
|
+
}
|
204
|
+
memcpy(buf + bsiz, obuf, osiz);
|
205
|
+
bsiz += osiz;
|
206
|
+
buf[bsiz] = '\0';
|
207
|
+
*sp = bsiz;
|
208
|
+
inflateEnd(&zs);
|
209
|
+
return buf;
|
210
|
+
}
|
211
|
+
|
212
|
+
|
213
|
+
static unsigned int _tc_getcrc_impl(const char *ptr, int size){
|
214
|
+
assert(ptr && size >= 0);
|
215
|
+
int crc = crc32(0, Z_NULL, 0);
|
216
|
+
return crc32(crc, (unsigned char *)ptr, size);
|
217
|
+
}
|
218
|
+
|
219
|
+
|
220
|
+
#else
|
221
|
+
|
222
|
+
|
223
|
+
char *(*_tc_deflate)(const char *, int, int *, int) = NULL;
|
224
|
+
char *(*_tc_inflate)(const char *, int, int *, int) = NULL;
|
225
|
+
unsigned int (*_tc_getcrc)(const char *, int) = NULL;
|
226
|
+
|
227
|
+
|
228
|
+
#endif
|
229
|
+
|
230
|
+
|
231
|
+
|
232
|
+
/*************************************************************************************************
|
233
|
+
* for BZIP2
|
234
|
+
*************************************************************************************************/
|
235
|
+
|
236
|
+
|
237
|
+
#if TCUSEBZIP
|
238
|
+
|
239
|
+
|
240
|
+
#include <bzlib.h>
|
241
|
+
|
242
|
+
#define BZIPBUFSIZ 8192
|
243
|
+
|
244
|
+
|
245
|
+
static char *_tc_bzcompress_impl(const char *ptr, int size, int *sp);
|
246
|
+
static char *_tc_bzdecompress_impl(const char *ptr, int size, int *sp);
|
247
|
+
|
248
|
+
|
249
|
+
char *(*_tc_bzcompress)(const char *, int, int *) = _tc_bzcompress_impl;
|
250
|
+
char *(*_tc_bzdecompress)(const char *, int, int *) = _tc_bzdecompress_impl;
|
251
|
+
|
252
|
+
|
253
|
+
static char *_tc_bzcompress_impl(const char *ptr, int size, int *sp){
|
254
|
+
assert(ptr && size >= 0 && sp);
|
255
|
+
bz_stream zs;
|
256
|
+
zs.bzalloc = NULL;
|
257
|
+
zs.bzfree = NULL;
|
258
|
+
zs.opaque = NULL;
|
259
|
+
if(BZ2_bzCompressInit(&zs, 9, 0, 0) != BZ_OK) return NULL;
|
260
|
+
int asiz = size + 16;
|
261
|
+
if(asiz < BZIPBUFSIZ) asiz = BZIPBUFSIZ;
|
262
|
+
char *buf;
|
263
|
+
if(!(buf = MYMALLOC(asiz))){
|
264
|
+
BZ2_bzCompressEnd(&zs);
|
265
|
+
return NULL;
|
266
|
+
}
|
267
|
+
char obuf[BZIPBUFSIZ];
|
268
|
+
int bsiz = 0;
|
269
|
+
zs.next_in = (char *)ptr;
|
270
|
+
zs.avail_in = size;
|
271
|
+
zs.next_out = obuf;
|
272
|
+
zs.avail_out = BZIPBUFSIZ;
|
273
|
+
int rv;
|
274
|
+
while((rv = BZ2_bzCompress(&zs, BZ_FINISH)) == BZ_FINISH_OK){
|
275
|
+
int osiz = BZIPBUFSIZ - zs.avail_out;
|
276
|
+
if(bsiz + osiz > asiz){
|
277
|
+
asiz = asiz * 2 + osiz;
|
278
|
+
char *swap;
|
279
|
+
if(!(swap = MYREALLOC(buf, asiz))){
|
280
|
+
MYFREE(buf);
|
281
|
+
BZ2_bzCompressEnd(&zs);
|
282
|
+
return NULL;
|
283
|
+
}
|
284
|
+
buf = swap;
|
285
|
+
}
|
286
|
+
memcpy(buf + bsiz, obuf, osiz);
|
287
|
+
bsiz += osiz;
|
288
|
+
zs.next_out = obuf;
|
289
|
+
zs.avail_out = BZIPBUFSIZ;
|
290
|
+
}
|
291
|
+
if(rv != BZ_STREAM_END){
|
292
|
+
MYFREE(buf);
|
293
|
+
BZ2_bzCompressEnd(&zs);
|
294
|
+
return NULL;
|
295
|
+
}
|
296
|
+
int osiz = BZIPBUFSIZ - zs.avail_out;
|
297
|
+
if(bsiz + osiz + 1 > asiz){
|
298
|
+
asiz = asiz * 2 + osiz;
|
299
|
+
char *swap;
|
300
|
+
if(!(swap = MYREALLOC(buf, asiz))){
|
301
|
+
MYFREE(buf);
|
302
|
+
BZ2_bzCompressEnd(&zs);
|
303
|
+
return NULL;
|
304
|
+
}
|
305
|
+
buf = swap;
|
306
|
+
}
|
307
|
+
memcpy(buf + bsiz, obuf, osiz);
|
308
|
+
bsiz += osiz;
|
309
|
+
buf[bsiz] = '\0';
|
310
|
+
*sp = bsiz;
|
311
|
+
BZ2_bzCompressEnd(&zs);
|
312
|
+
return buf;
|
313
|
+
}
|
314
|
+
|
315
|
+
|
316
|
+
static char *_tc_bzdecompress_impl(const char *ptr, int size, int *sp){
|
317
|
+
assert(ptr && size >= 0 && sp);
|
318
|
+
bz_stream zs;
|
319
|
+
zs.bzalloc = NULL;
|
320
|
+
zs.bzfree = NULL;
|
321
|
+
zs.opaque = NULL;
|
322
|
+
if(BZ2_bzDecompressInit(&zs, 0, 0) != BZ_OK) return NULL;
|
323
|
+
int asiz = size * 2 + 16;
|
324
|
+
if(asiz < BZIPBUFSIZ) asiz = BZIPBUFSIZ;
|
325
|
+
char *buf;
|
326
|
+
if(!(buf = MYMALLOC(asiz))){
|
327
|
+
BZ2_bzDecompressEnd(&zs);
|
328
|
+
return NULL;
|
329
|
+
}
|
330
|
+
char obuf[BZIPBUFSIZ];
|
331
|
+
int bsiz = 0;
|
332
|
+
zs.next_in = (char *)ptr;
|
333
|
+
zs.avail_in = size;
|
334
|
+
zs.next_out = obuf;
|
335
|
+
zs.avail_out = BZIPBUFSIZ;
|
336
|
+
int rv;
|
337
|
+
while((rv = BZ2_bzDecompress(&zs)) == BZ_OK){
|
338
|
+
int osiz = BZIPBUFSIZ - zs.avail_out;
|
339
|
+
if(bsiz + osiz >= asiz){
|
340
|
+
asiz = asiz * 2 + osiz;
|
341
|
+
char *swap;
|
342
|
+
if(!(swap = MYREALLOC(buf, asiz))){
|
343
|
+
MYFREE(buf);
|
344
|
+
BZ2_bzDecompressEnd(&zs);
|
345
|
+
return NULL;
|
346
|
+
}
|
347
|
+
buf = swap;
|
348
|
+
}
|
349
|
+
memcpy(buf + bsiz, obuf, osiz);
|
350
|
+
bsiz += osiz;
|
351
|
+
zs.next_out = obuf;
|
352
|
+
zs.avail_out = BZIPBUFSIZ;
|
353
|
+
}
|
354
|
+
if(rv != BZ_STREAM_END){
|
355
|
+
MYFREE(buf);
|
356
|
+
BZ2_bzDecompressEnd(&zs);
|
357
|
+
return NULL;
|
358
|
+
}
|
359
|
+
int osiz = BZIPBUFSIZ - zs.avail_out;
|
360
|
+
if(bsiz + osiz >= asiz){
|
361
|
+
asiz = asiz * 2 + osiz;
|
362
|
+
char *swap;
|
363
|
+
if(!(swap = MYREALLOC(buf, asiz))){
|
364
|
+
MYFREE(buf);
|
365
|
+
BZ2_bzDecompressEnd(&zs);
|
366
|
+
return NULL;
|
367
|
+
}
|
368
|
+
buf = swap;
|
369
|
+
}
|
370
|
+
memcpy(buf + bsiz, obuf, osiz);
|
371
|
+
bsiz += osiz;
|
372
|
+
buf[bsiz] = '\0';
|
373
|
+
*sp = bsiz;
|
374
|
+
BZ2_bzDecompressEnd(&zs);
|
375
|
+
return buf;
|
376
|
+
}
|
377
|
+
|
378
|
+
|
379
|
+
#else
|
380
|
+
|
381
|
+
|
382
|
+
char *(*_tc_bzcompress)(const char *, int, int *) = NULL;
|
383
|
+
char *(*_tc_bzdecompress)(const char *, int, int *) = NULL;
|
384
|
+
|
385
|
+
|
386
|
+
#endif
|
387
|
+
|
388
|
+
|
389
|
+
|
390
|
+
/*************************************************************************************************
|
391
|
+
* for test of custom codec functions
|
392
|
+
*************************************************************************************************/
|
393
|
+
|
394
|
+
|
395
|
+
#if TCUSEEXLZMA
|
396
|
+
|
397
|
+
|
398
|
+
#include <lzmalib.h>
|
399
|
+
|
400
|
+
|
401
|
+
void *_tc_recencode(const void *ptr, int size, int *sp, void *op){
|
402
|
+
return lzma_compress(ptr, size, sp);
|
403
|
+
}
|
404
|
+
|
405
|
+
|
406
|
+
void *_tc_recdecode(const void *ptr, int size, int *sp, void *op){
|
407
|
+
return lzma_decompress(ptr, size, sp);
|
408
|
+
}
|
409
|
+
|
410
|
+
|
411
|
+
#elif TCUSEEXLZO
|
412
|
+
|
413
|
+
|
414
|
+
#include <lzo/lzo1x.h>
|
415
|
+
|
416
|
+
|
417
|
+
bool _tc_lzo_init = false;
|
418
|
+
|
419
|
+
|
420
|
+
void *_tc_recencode(const void *ptr, int size, int *sp, void *op){
|
421
|
+
if(!_tc_lzo_init){
|
422
|
+
if(lzo_init() != LZO_E_OK) return NULL;
|
423
|
+
_tc_lzo_init = false;
|
424
|
+
}
|
425
|
+
lzo_bytep buf = MYMALLOC(size + (size >> 4) + 80);
|
426
|
+
if(!buf) return NULL;
|
427
|
+
lzo_uint bsiz;
|
428
|
+
char wrkmem[LZO1X_1_MEM_COMPRESS];
|
429
|
+
if(lzo1x_1_compress((lzo_bytep)ptr, size, buf, &bsiz, wrkmem) != LZO_E_OK){
|
430
|
+
MYFREE(buf);
|
431
|
+
return NULL;
|
432
|
+
}
|
433
|
+
buf[bsiz] = '\0';
|
434
|
+
*sp = bsiz;
|
435
|
+
return (char *)buf;
|
436
|
+
}
|
437
|
+
|
438
|
+
|
439
|
+
void *_tc_recdecode(const void *ptr, int size, int *sp, void *op){
|
440
|
+
if(!_tc_lzo_init){
|
441
|
+
if(lzo_init() != LZO_E_OK) return NULL;
|
442
|
+
_tc_lzo_init = false;
|
443
|
+
}
|
444
|
+
lzo_bytep buf;
|
445
|
+
lzo_uint bsiz;
|
446
|
+
int rat = 6;
|
447
|
+
while(true){
|
448
|
+
bsiz = (size + 256) * rat + 3;
|
449
|
+
buf = MYMALLOC(bsiz + 1);
|
450
|
+
if(!buf) return NULL;
|
451
|
+
int rv = lzo1x_decompress_safe((lzo_bytep)ptr, size, buf, &bsiz, NULL);
|
452
|
+
if(rv == LZO_E_OK){
|
453
|
+
break;
|
454
|
+
} else if(rv == LZO_E_OUTPUT_OVERRUN){
|
455
|
+
MYFREE(buf);
|
456
|
+
rat *= 2;
|
457
|
+
} else {
|
458
|
+
MYFREE(buf);
|
459
|
+
return NULL;
|
460
|
+
}
|
461
|
+
}
|
462
|
+
buf[bsiz] = '\0';
|
463
|
+
if(sp) *sp = bsiz;
|
464
|
+
return (char *)buf;
|
465
|
+
}
|
466
|
+
|
467
|
+
|
468
|
+
#else
|
469
|
+
|
470
|
+
|
471
|
+
void *_tc_recencode(const void *ptr, int size, int *sp, void *op){
|
472
|
+
char *res = MYMALLOC(size + 1);
|
473
|
+
if(!res) return NULL;
|
474
|
+
memcpy(res, ptr, size);
|
475
|
+
*sp = size;
|
476
|
+
return res;
|
477
|
+
}
|
478
|
+
|
479
|
+
|
480
|
+
void *_tc_recdecode(const void *ptr, int size, int *sp, void *op){
|
481
|
+
char *res = MYMALLOC(size + 1);
|
482
|
+
if(!res) return NULL;
|
483
|
+
memcpy(res, ptr, size);
|
484
|
+
*sp = size;
|
485
|
+
return res;
|
486
|
+
}
|
487
|
+
|
488
|
+
|
489
|
+
#endif
|
490
|
+
|
491
|
+
|
492
|
+
|
493
|
+
// END OF FILE
|