@@ -57,6 +57,7 @@ void TSI_init(ToplevelStreamInfo* info)
57
57
58
58
void TSI_destroy (ToplevelStreamInfo * info )
59
59
{
60
+ fprintf (stderr , "TSI_destroy: %p\n" , info );
60
61
if (info -> parent_object ){
61
62
Py_DECREF (info -> parent_object );
62
63
info -> parent_object = 0 ;
@@ -164,6 +165,12 @@ ull DC_rbound(const DeltaChunk* dc)
164
165
return dc -> to + dc -> ts ;
165
166
}
166
167
168
+ inline
169
+ void DC_print (const DeltaChunk * dc , const char * prefix )
170
+ {
171
+ fprintf (stderr , "%s-dc: to = %i, ts = %i, so = %i, data = %p\n" , prefix , (int )dc -> to , dc -> ts , dc -> so , dc -> data );
172
+ }
173
+
167
174
// Apply
168
175
inline
169
176
void DC_apply (const DeltaChunk * dc , const uchar * base , PyObject * writer , PyObject * tmpargs )
@@ -179,6 +186,8 @@ void DC_apply(const DeltaChunk* dc, const uchar* base, PyObject* writer, PyObjec
179
186
assert (0 );
180
187
}
181
188
189
+ DC_print (dc , "DC_apply" );
190
+
182
191
// tuple steals reference, and will take care about the deallocation
183
192
PyObject_Call (writer , tmpargs , NULL );
184
193
@@ -233,14 +242,14 @@ ushort DC_count_encode_bytes(const DeltaChunk* dc)
233
242
ull so = dc -> so ;
234
243
235
244
// offset
236
- c += so & 0x000000FF ;
237
- c += so & 0x0000FF00 ;
238
- c += so & 0x00FF0000 ;
239
- c += so & 0xFF000000 ;
245
+ c += ( so & 0x000000FF ) > 0 ;
246
+ c += ( so & 0x0000FF00 ) > 0 ;
247
+ c += ( so & 0x00FF0000 ) > 0 ;
248
+ c += ( so & 0xFF000000 ) > 0 ;
240
249
241
250
// size - max size is 0x10000, its encoded with 0 size bits
242
- c += ts & 0x000000FF ;
243
- c += ts & 0x0000FF00 ;
251
+ c += ( ts & 0x000000FF ) > 0 ;
252
+ c += ( ts & 0x0000FF00 ) > 0 ;
244
253
245
254
return c ;
246
255
}
@@ -413,7 +422,7 @@ void DIV_destroy(DeltaInfoVector* vec)
413
422
{
414
423
if (vec -> mem ){
415
424
#ifdef DEBUG
416
- fprintf (stderr , "Freeing %p\n" , (void * )vec -> mem );
425
+ fprintf (stderr , "DIV_destroy: %p\n" , (void * )vec -> mem );
417
426
#endif
418
427
PyMem_Free (vec -> mem );
419
428
vec -> size = 0 ;
@@ -494,22 +503,20 @@ uint DIV_count_slice_bytes(const DeltaInfoVector* src, uint ofs, uint size)
494
503
uint num_bytes = 0 ;
495
504
DeltaInfo * cdi = DIV_closest_chunk (src , ofs );
496
505
497
-
498
-
499
506
DeltaChunk dc ;
500
507
DC_init (& dc , 0 , 0 , 0 , NULL );
501
508
502
509
// partial overlap
503
510
if (cdi -> to != ofs ) {
504
511
const ull relofs = ofs - cdi -> to ;
505
512
const uint cdisize = DIV_info_size (src , cdi );
506
- const uint actual_size = cdisize - relofs < size ? cdisize - relofs : size ;
507
- size -= actual_size ;
513
+ const uint max_size = cdisize - relofs < size ? cdisize - relofs : size ;
514
+ size -= max_size ;
508
515
509
516
// get the size in bytes the info would have
510
517
next_delta_info (src -> dstream + cdi -> dso , & dc );
511
518
dc .so += relofs ;
512
- dc .ts = actual_size ;
519
+ dc .ts = max_size ;
513
520
num_bytes += DC_count_encode_bytes (& dc );
514
521
515
522
cdi += 1 ;
@@ -547,27 +554,32 @@ uint DIV_count_slice_bytes(const DeltaInfoVector* src, uint ofs, uint size)
547
554
inline
548
555
uint DIV_copy_slice_to (const DeltaInfoVector * src , uchar * dest , ull tofs , uint size )
549
556
{
557
+ fprintf (stderr , "copy slice: ofs = %i, size = %i\n" , (int )tofs , size );
550
558
assert (DIV_lbound (src ) <= tofs );
551
- assert ((tofs + size ) <= DIV_last (src ) -> to + src -> di_last_size );
559
+ assert ((tofs + size ) <= DIV_info_rbound (src , DIV_last ( src )) );
552
560
553
561
DeltaChunk dc ;
554
562
DC_init (& dc , 0 , 0 , 0 , NULL );
555
563
556
564
DeltaInfo * cdi = DIV_closest_chunk (src , tofs );
557
565
uint num_chunks = 0 ;
558
566
567
+ #ifdef DEBUG
568
+ const uchar * deststart = dest ;
569
+ #endif
570
+
559
571
// partial overlap
560
572
if (cdi -> to != tofs ) {
561
573
const uint relofs = tofs - cdi -> to ;
562
574
next_delta_info (src -> dstream + cdi -> dso , & dc );
563
575
const uint cdisize = dc .ts ;
564
- const uint actual_size = cdisize - relofs < size ? cdisize - relofs : size ;
576
+ const uint max_size = cdisize - relofs < size ? cdisize - relofs : size ;
565
577
566
- size -= actual_size ;
578
+ size -= max_size ;
567
579
568
580
// adjust dc proportions
569
581
570
- DC_encode_to (& dc , & dest , relofs , actual_size );
582
+ DC_encode_to (& dc , & dest , relofs , max_size );
571
583
572
584
num_chunks += 1 ;
573
585
cdi += 1 ;
@@ -580,6 +592,7 @@ uint DIV_copy_slice_to(const DeltaInfoVector* src, uchar* dest, ull tofs, uint s
580
592
const DeltaInfo * vecend = DIV_end (src );
581
593
for ( ;cdi < vecend ; ++ cdi )
582
594
{
595
+ fprintf (stderr , "copy slice: cdi: to = %i, dso = %i\n" , (int )cdi -> to , (int )cdi -> dso );
583
596
num_chunks += 1 ;
584
597
next_delta_info (src -> dstream + cdi -> dso , & dc );
585
598
if (dc .ts < size ) {
@@ -595,6 +608,10 @@ uint DIV_copy_slice_to(const DeltaInfoVector* src, uchar* dest, ull tofs, uint s
595
608
}
596
609
}
597
610
611
+ #ifdef DEBUG
612
+ fprintf (stderr , "copy slice: Wrote %i bytes\n" , (int )(dest - deststart ));
613
+ #endif
614
+
598
615
assert (size == 0 );
599
616
return num_chunks ;
600
617
}
@@ -619,6 +636,7 @@ bool DIV_connect_with_base(ToplevelStreamInfo* tsi, DeltaInfoVector* div)
619
636
620
637
OffsetInfo * pofs = offset_array ;
621
638
uint num_addbytes = 0 ;
639
+ uint dofs = 0 ;
622
640
623
641
const uchar * data = TSI_first (tsi );
624
642
const uchar * prev_data = data ;
@@ -627,16 +645,19 @@ bool DIV_connect_with_base(ToplevelStreamInfo* tsi, DeltaInfoVector* div)
627
645
DeltaChunk dc ;
628
646
DC_init (& dc , 0 , 0 , 0 , NULL );
629
647
648
+
630
649
// OFFSET RUN
631
650
for (;data < dend ; pofs ++ , prev_data = data )
632
651
{
633
-
634
652
pofs -> bofs = num_addbytes ;
635
- pofs -> dofs = (uint )(prev_data - data );
636
-
637
- // Data chunks don't need processing
638
653
data = next_delta_info (data , & dc );
654
+ pofs -> dofs = dofs ;
655
+ dofs += (uint )(data - prev_data );
656
+
657
+ fprintf (stderr , "pofs->bofs = %i, ->dofs = %i\n" , pofs -> bofs , pofs -> dofs );
658
+ DC_print (& dc , "count-run" );
639
659
660
+ // Data chunks don't need processing
640
661
if (dc .data ){
641
662
continue ;
642
663
}
@@ -646,6 +667,8 @@ bool DIV_connect_with_base(ToplevelStreamInfo* tsi, DeltaInfoVector* div)
646
667
num_addbytes += DIV_count_slice_bytes (div , dc .so , dc .ts ) - (data - prev_data );
647
668
}
648
669
670
+ fprintf (stderr , "num_addbytes = %i\n" , num_addbytes );
671
+ assert (DC_rbound (& dc ) == tsi -> target_size );
649
672
650
673
651
674
// reserve enough memory to hold all the new chunks
@@ -655,6 +678,7 @@ bool DIV_connect_with_base(ToplevelStreamInfo* tsi, DeltaInfoVector* div)
655
678
uchar * ds ; // pointer into the delta stream
656
679
const uchar * nds ; // next pointer, used for size retrieving the size
657
680
uint num_addchunks = 0 ; // total amount of chunks added
681
+ DC_init (& dc , 0 , 0 , 0 , NULL );
658
682
659
683
// Insert slices, from the end to the beginning, which allows memcpy
660
684
// to be used, with a little help of the offset array
@@ -682,6 +706,7 @@ bool DIV_connect_with_base(ToplevelStreamInfo* tsi, DeltaInfoVector* div)
682
706
num_addchunks -= 1 ;
683
707
}
684
708
709
+ fprintf (stderr , "num_addchunks = %i\n" , num_addchunks );
685
710
tsi -> num_chunks += num_addchunks ;
686
711
687
712
PyMem_Free (offset_array );
@@ -860,6 +885,8 @@ const uchar* next_delta_info(const uchar* data, DeltaChunk* dc)
860
885
dc -> data = data ;
861
886
dc -> ts = cmd ;
862
887
dc -> so = 0 ;
888
+
889
+ data += cmd ;
863
890
} else {
864
891
PyErr_SetString (PyExc_RuntimeError , "Encountered an unsupported delta cmd: 0" );
865
892
return NULL ;
@@ -993,8 +1020,8 @@ static PyObject* connect_deltas(PyObject *self, PyObject *dstreams)
993
1020
DIV_reserve_memory (& div , compute_chunk_count (data , dend , 0 ));
994
1021
995
1022
// parse command stream
996
- DeltaChunk dc ;
997
1023
DeltaInfo * di = 0 ; // temporary pointer
1024
+ DeltaChunk dc ;
998
1025
DC_init (& dc , 0 , 0 , 0 , NULL );
999
1026
1000
1027
assert (data < dend );
@@ -1019,7 +1046,9 @@ static PyObject* connect_deltas(PyObject *self, PyObject *dstreams)
1019
1046
}
1020
1047
1021
1048
#ifdef DEBUG
1049
+ fprintf (stderr , "------------ Stream %i --------\n " , (int )dsi );
1022
1050
fprintf (stderr , "Before Connect: tdsinfo->num_chunks = %i, tdsinfo->bytelen = %i\n" , (int )tdsinfo .num_chunks , (int )tdsinfo .tdslen );
1051
+ fprintf (stderr , "div->num_chunks = %i, div->reserved_size = %i, div->bytelen=%i\n" , (int )div .size , (int )div .reserved_size , (int )dlen );
1023
1052
#endif
1024
1053
1025
1054
if (!DIV_connect_with_base (& tdsinfo , & div )){
@@ -1028,7 +1057,6 @@ static PyObject* connect_deltas(PyObject *self, PyObject *dstreams)
1028
1057
1029
1058
#ifdef DEBUG
1030
1059
fprintf (stderr , "after connect: tdsinfo->num_chunks = %i, tdsinfo->bytelen = %i\n" , (int )tdsinfo .num_chunks , (int )tdsinfo .tdslen );
1031
- fprintf (stderr , "div->num_chunks = %i, div->reserved_size = %i, div->bytelen=%i\n" , (int )div .size , (int )div .reserved_size , (int )dlen );
1032
1060
#endif
1033
1061
1034
1062
// destroy members, but keep memory
0 commit comments