~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to storage/myisam/mi_packrec.c

  • Committer: Brian Aker
  • Date: 2008-07-14 22:18:37 UTC
  • mfrom: (77.1.96 codestyle)
  • Revision ID: brian@tangent.org-20080714221837-oceoshx7fjkla9u3
Merge from Monty

Show diffs side-by-side

added added

removed removed

Lines of Context:
44
44
  { bits-=(bit+1); break; } \
45
45
  pos+= *pos
46
46
 
47
 
/* Size in uint16_t of a Huffman tree for byte compression of 256 byte values. */
 
47
/* Size in uint16 of a Huffman tree for byte compression of 256 byte values. */
48
48
#define OFFSET_TABLE_SIZE 512
49
49
 
50
50
static uint read_huff_table(MI_BIT_BUFF *bit_buff,MI_DECODE_TREE *decode_tree,
51
 
                            uint16_t **decode_table,uchar **intervall_buff,
52
 
                            uint16_t *tmp_buff);
53
 
static void make_quick_table(uint16_t *to_table,uint16_t *decode_table,
 
51
                            uint16 **decode_table,uchar **intervall_buff,
 
52
                            uint16 *tmp_buff);
 
53
static void make_quick_table(uint16 *to_table,uint16 *decode_table,
54
54
                             uint *next_free,uint value,uint bits,
55
55
                             uint max_bits);
56
 
static void fill_quick_table(uint16_t *table,uint bits, uint max_bits,
 
56
static void fill_quick_table(uint16 *table,uint bits, uint max_bits,
57
57
                             uint value);
58
 
static uint copy_decode_table(uint16_t *to_pos,uint offset,
59
 
                              uint16_t *decode_table);
60
 
static uint find_longest_bitstream(uint16_t *table, uint16_t *end);
 
58
static uint copy_decode_table(uint16 *to_pos,uint offset,
 
59
                              uint16 *decode_table);
 
60
static uint find_longest_bitstream(uint16 *table, uint16 *end);
61
61
static void (*get_unpack_function(MI_COLUMNDEF *rec))(MI_COLUMNDEF *field,
62
62
                                                    MI_BIT_BUFF *buff,
63
63
                                                    uchar *to,
134
134
  File file;
135
135
  int diff_length;
136
136
  uint i,trees,huff_tree_bits,rec_reflength,length;
137
 
  uint16_t *decode_table,*tmp_buff;
 
137
  uint16 *decode_table,*tmp_buff;
138
138
  ulong elements,intervall_length;
139
139
  uchar *disk_cache;
140
140
  uchar *intervall_buff;
141
141
  uchar header[HEAD_LENGTH];
142
142
  MYISAM_SHARE *share=info->s;
143
143
  MI_BIT_BUFF bit_buff;
 
144
  DBUG_ENTER("_mi_read_pack_info");
144
145
 
145
146
  if (myisam_quick_table_bits < 4)
146
147
    myisam_quick_table_bits=4;
176
177
  share->base.min_block_length=share->min_pack_length+1;
177
178
  if (share->min_pack_length > 254)
178
179
    share->base.min_block_length+=2;
 
180
  DBUG_PRINT("info", ("fixed header length:   %u", HEAD_LENGTH));
 
181
  DBUG_PRINT("info", ("total header length:   %lu", share->pack.header_length));
 
182
  DBUG_PRINT("info", ("pack file version:     %u", share->pack.version));
 
183
  DBUG_PRINT("info", ("min pack length:       %lu", share->min_pack_length));
 
184
  DBUG_PRINT("info", ("max pack length:       %lu", share->max_pack_length));
 
185
  DBUG_PRINT("info", ("elements of all trees: %lu", elements));
 
186
  DBUG_PRINT("info", ("distinct values bytes: %lu", intervall_length));
 
187
  DBUG_PRINT("info", ("number of code trees:  %u", trees));
 
188
  DBUG_PRINT("info", ("bytes for record lgt:  %u", share->pack.ref_length));
 
189
  DBUG_PRINT("info", ("record pointer length: %u", rec_reflength));
179
190
 
180
191
  /*
181
192
    Memory segment #1:
198
209
    This segment will be reallocated after construction of the tables.
199
210
  */
200
211
  length=(uint) (elements*2+trees*(1 << myisam_quick_table_bits));
201
 
  if (!(share->decode_tables=(uint16_t*)
202
 
        my_malloc((length + OFFSET_TABLE_SIZE) * sizeof(uint16_t) +
 
212
  if (!(share->decode_tables=(uint16*)
 
213
        my_malloc((length + OFFSET_TABLE_SIZE) * sizeof(uint16) +
203
214
                  (uint) (share->pack.header_length - sizeof(header)),
204
215
                  MYF(MY_WME | MY_ZEROFILL))))
205
216
    goto err1;
223
234
    share->rec[i].huff_tree=share->decode_trees+(uint) get_bits(&bit_buff,
224
235
                                                                huff_tree_bits);
225
236
    share->rec[i].unpack=get_unpack_function(share->rec+i);
 
237
    DBUG_PRINT("info", ("col: %2u  type: %2u  pack: %u  slbits: %2u",
 
238
                        i, share->rec[i].base_type, share->rec[i].pack_type,
 
239
                        share->rec[i].space_length_bits));
226
240
  }
227
241
  skip_to_next_byte(&bit_buff);
228
242
  /*
235
249
                        &intervall_buff,tmp_buff))
236
250
      goto err3;
237
251
  /* Reallocate the decoding tables to the used size. */
238
 
  decode_table=(uint16_t*)
 
252
  decode_table=(uint16*)
239
253
    my_realloc((uchar*) share->decode_tables,
240
254
               (uint) ((uchar*) decode_table - (uchar*) share->decode_tables),
241
255
               MYF(MY_HOLD_ON_ERROR));
245
259
    share->decode_tables=decode_table;
246
260
    for (i=0 ; i < trees ; i++)
247
261
      share->decode_trees[i].table=ADD_TO_PTR(share->decode_trees[i].table,
248
 
                                              diff, uint16_t*);
 
262
                                              diff, uint16*);
249
263
  }
250
264
 
251
265
  /* Fix record-ref-length for keys */
254
268
    for (i=0 ; i < share->base.keys ; i++)
255
269
    {
256
270
      MI_KEYDEF *keyinfo= &share->keyinfo[i];
257
 
      keyinfo->keylength+= (uint16_t) diff_length;
258
 
      keyinfo->minlength+= (uint16_t) diff_length;
259
 
      keyinfo->maxlength+= (uint16_t) diff_length;
260
 
      keyinfo->seg[keyinfo->keysegs].length= (uint16_t) rec_reflength;
 
271
      keyinfo->keylength+= (uint16) diff_length;
 
272
      keyinfo->minlength+= (uint16) diff_length;
 
273
      keyinfo->maxlength+= (uint16) diff_length;
 
274
      keyinfo->seg[keyinfo->keysegs].length= (uint16) rec_reflength;
261
275
    }
262
276
    if (share->ft2_keyinfo.seg)
263
277
    {
264
278
      MI_KEYDEF *ft2_keyinfo= &share->ft2_keyinfo;
265
 
      ft2_keyinfo->keylength+= (uint16_t) diff_length;
266
 
      ft2_keyinfo->minlength+= (uint16_t) diff_length;
267
 
      ft2_keyinfo->maxlength+= (uint16_t) diff_length;
 
279
      ft2_keyinfo->keylength+= (uint16) diff_length;
 
280
      ft2_keyinfo->minlength+= (uint16) diff_length;
 
281
      ft2_keyinfo->maxlength+= (uint16) diff_length;
268
282
    }
269
283
  }
270
284
 
271
285
  if (bit_buff.error || bit_buff.pos < bit_buff.end)
272
286
    goto err3;
273
287
 
274
 
  return(0);
 
288
  DBUG_RETURN(0);
275
289
 
276
290
err3:
277
291
  my_errno=HA_ERR_WRONG_IN_RECORD;
280
294
err1:
281
295
  my_free((uchar*) share->decode_trees,MYF(0));
282
296
err0:
283
 
  return(1);
 
297
  DBUG_RETURN(1);
284
298
}
285
299
 
286
300
 
303
317
*/
304
318
 
305
319
static uint read_huff_table(MI_BIT_BUFF *bit_buff, MI_DECODE_TREE *decode_tree,
306
 
                            uint16_t **decode_table, uchar **intervall_buff,
307
 
                            uint16_t *tmp_buff)
 
320
                            uint16 **decode_table, uchar **intervall_buff,
 
321
                            uint16 *tmp_buff)
308
322
{
309
323
  uint min_chr,elements,char_bits,offset_bits,size,intervall_length,table_bits,
310
324
  next_free_offset;
311
 
  uint16_t *ptr,*end;
 
325
  uint16 *ptr,*end;
 
326
  DBUG_ENTER("read_huff_table");
312
327
 
313
328
  if (!get_bits(bit_buff,1))
314
329
  {
319
334
    offset_bits=get_bits(bit_buff,5);
320
335
    intervall_length=0;
321
336
    ptr=tmp_buff;
 
337
    DBUG_PRINT("info", ("byte value compression"));
 
338
    DBUG_PRINT("info", ("minimum byte value:    %u", min_chr));
 
339
    DBUG_PRINT("info", ("number of tree nodes:  %u", elements));
 
340
    DBUG_PRINT("info", ("bits for values:       %u", char_bits));
 
341
    DBUG_PRINT("info", ("bits for tree offsets: %u", offset_bits));
322
342
    if (elements > 256)
323
343
    {
324
 
      return(1);
 
344
      DBUG_PRINT("error", ("ERROR: illegal number of tree elements: %u",
 
345
                           elements));
 
346
      DBUG_RETURN(1);
325
347
    }
326
348
  }
327
349
  else
334
356
    offset_bits=get_bits(bit_buff,5);
335
357
    decode_tree->quick_table_bits=0;
336
358
    ptr= *decode_table;
 
359
    DBUG_PRINT("info", ("distinct column value compression"));
 
360
    DBUG_PRINT("info", ("number of tree nodes:  %u", elements));
 
361
    DBUG_PRINT("info", ("value buffer length:   %u", intervall_length));
 
362
    DBUG_PRINT("info", ("bits for value index:  %u", char_bits));
 
363
    DBUG_PRINT("info", ("bits for tree offsets: %u", offset_bits));
337
364
  }
338
365
  size=elements*2-2;
 
366
  DBUG_PRINT("info", ("tree size in uint16:   %u", size));
 
367
  DBUG_PRINT("info", ("tree size in bytes:    %u",
 
368
                      size * (uint) sizeof(uint16)));
339
369
 
340
370
  for (end=ptr+size ; ptr < end ; ptr++)
341
371
  {
342
372
    if (get_bit(bit_buff))
343
373
    {
344
 
      *ptr= (uint16_t) get_bits(bit_buff,offset_bits);
 
374
      *ptr= (uint16) get_bits(bit_buff,offset_bits);
345
375
      if ((ptr + *ptr >= end) || !*ptr)
346
376
      {
347
 
        return(1);
 
377
        DBUG_PRINT("error", ("ERROR: illegal pointer in decode tree"));
 
378
        DBUG_RETURN(1);
348
379
      }
349
380
    }
350
381
    else
351
 
      *ptr= (uint16_t) (IS_CHAR + (get_bits(bit_buff,char_bits) + min_chr));
 
382
      *ptr= (uint16) (IS_CHAR + (get_bits(bit_buff,char_bits) + min_chr));
352
383
  }
353
384
  skip_to_next_byte(bit_buff);
354
385
 
360
391
    /* Find longest Huffman code from begin to end of tree in bits. */
361
392
    table_bits= find_longest_bitstream(tmp_buff, ptr);
362
393
    if (table_bits >= OFFSET_TABLE_SIZE)
363
 
      return(1);
 
394
      DBUG_RETURN(1);
364
395
    if (table_bits > myisam_quick_table_bits)
365
396
      table_bits=myisam_quick_table_bits;
 
397
    DBUG_PRINT("info", ("table bits:            %u", table_bits));
366
398
 
367
399
    next_free_offset= (1 << table_bits);
368
400
    make_quick_table(*decode_table,tmp_buff,&next_free_offset,0,table_bits,
385
417
    bit_buff->pos+=intervall_length;
386
418
    bit_buff->bits=0;
387
419
  }
388
 
  return(0);
 
420
  DBUG_RETURN(0);
389
421
}
390
422
 
391
423
 
428
460
    void
429
461
*/
430
462
 
431
 
static void make_quick_table(uint16_t *to_table, uint16_t *decode_table,
 
463
static void make_quick_table(uint16 *to_table, uint16 *decode_table,
432
464
                             uint *next_free_offset, uint value, uint bits,
433
465
                             uint max_bits)
434
466
{
 
467
  DBUG_ENTER("make_quick_table");
 
468
 
435
469
  /*
436
470
    When down the table to the requested maximum, copy the rest of the
437
471
    Huffman table.
442
476
      Remaining left  Huffman tree segment starts behind quick table.
443
477
      Remaining right Huffman tree segment starts behind left segment.
444
478
    */
445
 
    to_table[value]= (uint16_t) *next_free_offset;
 
479
    to_table[value]= (uint16) *next_free_offset;
446
480
    /*
447
481
      Re-construct the remaining Huffman tree segment at
448
482
      next_free_offset in to_table.
449
483
    */
450
484
    *next_free_offset= copy_decode_table(to_table, *next_free_offset,
451
485
                                         decode_table);
452
 
    return;
 
486
    DBUG_VOID_RETURN;
453
487
  }
454
488
 
455
489
  /* Descent on the left side. Left side bits are clear (0). */
488
522
    fill_quick_table(to_table + value, bits, max_bits, (uint) *decode_table);
489
523
  }
490
524
 
491
 
  return;
 
525
  DBUG_VOID_RETURN;
492
526
}
493
527
 
494
528
 
516
550
    void
517
551
*/
518
552
 
519
 
static void fill_quick_table(uint16_t *table, uint bits, uint max_bits,
 
553
static void fill_quick_table(uint16 *table, uint bits, uint max_bits,
520
554
                             uint value)
521
555
{
522
 
  uint16_t *end;
 
556
  uint16 *end;
 
557
  DBUG_ENTER("fill_quick_table");
523
558
 
524
559
  /*
525
560
    Bits 1..8 of value represent the decoded byte value.
530
565
 
531
566
  for (end= table + ((my_ptrdiff_t) 1 << bits); table < end; table++)
532
567
  {
533
 
    *table= (uint16_t) value;
 
568
    *table= (uint16) value;
534
569
  }
535
 
  return;
 
570
  DBUG_VOID_RETURN;
536
571
}
537
572
 
538
573
 
552
587
    next free offset from to_pos.
553
588
*/
554
589
 
555
 
static uint copy_decode_table(uint16_t *to_pos, uint offset,
556
 
                              uint16_t *decode_table)
 
590
static uint copy_decode_table(uint16 *to_pos, uint offset,
 
591
                              uint16 *decode_table)
557
592
{
558
593
  uint prev_offset= offset;
 
594
  DBUG_ENTER("copy_decode_table");
559
595
 
560
596
  /* Descent on the left side. */
561
597
  if (!(*decode_table & IS_CHAR))
578
614
  if (!(*decode_table & IS_CHAR))
579
615
  {
580
616
    /* Set a pointer to the next free target node. */
581
 
    to_pos[prev_offset+1]=(uint16_t) (offset-prev_offset-1);
 
617
    to_pos[prev_offset+1]=(uint16) (offset-prev_offset-1);
582
618
    /* Copy the right hand subtree to the entry of that node. */
583
619
    offset=copy_decode_table(to_pos,offset,decode_table+ *decode_table);
584
620
  }
587
623
    /* Copy the byte value. */
588
624
    to_pos[prev_offset+1]= *decode_table;
589
625
  }
590
 
  return(offset);
 
626
  DBUG_RETURN(offset);
591
627
}
592
628
 
593
629
 
615
651
    >= OFFSET_TABLE_SIZE    Error, broken tree. It does not end before 'end'.
616
652
*/
617
653
 
618
 
static uint find_longest_bitstream(uint16_t *table, uint16_t *end)
 
654
static uint find_longest_bitstream(uint16 *table, uint16 *end)
619
655
{
620
656
  uint length= 1;
621
657
  uint length2;
622
658
 
623
659
  if (!(*table & IS_CHAR))
624
660
  {
625
 
    uint16_t *next= table + *table;
 
661
    uint16 *next= table + *table;
626
662
    if (next > end || next == table)
627
663
    {
 
664
      DBUG_PRINT("error", ("ERROR: illegal pointer in decode tree"));
628
665
      return OFFSET_TABLE_SIZE;
629
666
    }
630
667
    length= find_longest_bitstream(next, end) + 1;
632
669
  table++;
633
670
  if (!(*table & IS_CHAR))
634
671
  {
635
 
    uint16_t *next= table + *table;
 
672
    uint16 *next= table + *table;
636
673
    if (next > end || next == table)
637
674
    {
 
675
      DBUG_PRINT("error", ("ERROR: illegal pointer in decode tree"));
638
676
      return OFFSET_TABLE_SIZE;
639
677
    }
640
678
    length2= find_longest_bitstream(next, end) + 1;
662
700
{
663
701
  MI_BLOCK_INFO block_info;
664
702
  File file;
 
703
  DBUG_ENTER("mi_read_pack_record");
665
704
 
666
705
  if (filepos == HA_OFFSET_ERROR)
667
 
    return(-1);                 /* _search() didn't find record */
 
706
    DBUG_RETURN(-1);                    /* _search() didn't find record */
668
707
 
669
708
  file=info->dfile;
670
709
  if (_mi_pack_get_block_info(info, &info->bit_buff, &block_info,
674
713
              block_info.rec_len - block_info.offset, MYF(MY_NABP)))
675
714
    goto panic;
676
715
  info->update|= HA_STATE_AKTIV;
677
 
  return(_mi_pack_rec_unpack(info, &info->bit_buff, buf,
 
716
  DBUG_RETURN(_mi_pack_rec_unpack(info, &info->bit_buff, buf,
678
717
                                  info->rec_buff, block_info.rec_len));
679
718
panic:
680
719
  my_errno=HA_ERR_WRONG_IN_RECORD;
681
720
err:
682
 
  return(-1);
 
721
  DBUG_RETURN(-1);
683
722
}
684
723
 
685
724
 
691
730
  register MI_COLUMNDEF *end;
692
731
  MI_COLUMNDEF *current_field;
693
732
  MYISAM_SHARE *share=info->s;
 
733
  DBUG_ENTER("_mi_pack_rec_unpack");
694
734
 
695
735
  init_bit_buffer(bit_buff, (uchar*) from, reclength);
696
736
 
704
744
  }
705
745
  if (!bit_buff->error &&
706
746
      bit_buff->pos - bit_buff->bits / 8 == bit_buff->end)
707
 
    return(0);
 
747
    DBUG_RETURN(0);
708
748
  info->update&= ~HA_STATE_AKTIV;
709
 
  return(my_errno=HA_ERR_WRONG_IN_RECORD);
 
749
  DBUG_RETURN(my_errno=HA_ERR_WRONG_IN_RECORD);
710
750
} /* _mi_pack_rec_unpack */
711
751
 
712
752
 
771
811
                                   uchar *to, uchar *end)
772
812
{
773
813
  if (get_bit(bit_buff))
774
 
    memset((char*) to, 0, (uint) (end-to));
 
814
    bzero((char*) to,(uint) (end-to));
775
815
  else
776
816
  {
777
817
    end-=rec->space_length_bits;
778
818
    decode_bytes(rec,bit_buff,to,end);
779
 
    memset((char*) end, 0, rec->space_length_bits);
 
819
    bzero((char*) end,rec->space_length_bits);
780
820
  }
781
821
}
782
822
 
784
824
                          uchar *end)
785
825
{
786
826
  if (get_bit(bit_buff))
787
 
    memset((char*) to, 0, (uint) (end-to));
 
827
    bzero((char*) to,(uint) (end-to));
788
828
  else
789
829
    decode_bytes(rec,bit_buff,to,end);
790
830
}
793
833
                            uchar *end)
794
834
{
795
835
  if (get_bit(bit_buff))
796
 
    memset((uchar*) to, ' ', (end-to));
 
836
    bfill((uchar*) to,(end-to),' ');
797
837
  else
798
838
    decode_bytes(rec,bit_buff,to,end);
799
839
}
803
843
{
804
844
  uint spaces;
805
845
  if (get_bit(bit_buff))
806
 
    memset((uchar*) to, ' ', (end-to));
 
846
    bfill((uchar*) to,(end-to),' ');
807
847
  else
808
848
  {
809
849
    if (get_bit(bit_buff))
815
855
      }
816
856
      if (to+spaces != end)
817
857
        decode_bytes(rec,bit_buff,to,end-spaces);
818
 
      memset((uchar*) end-spaces, ' ', spaces);
 
858
      bfill((uchar*) end-spaces,spaces,' ');
819
859
    }
820
860
    else
821
861
      decode_bytes(rec,bit_buff,to,end);
835
875
    }
836
876
    if (to+spaces != end)
837
877
      decode_bytes(rec,bit_buff,to,end-spaces);
838
 
    memset((uchar*) end-spaces, ' ', spaces);
 
878
    bfill((uchar*) end-spaces,spaces,' ');
839
879
  }
840
880
  else
841
881
    decode_bytes(rec,bit_buff,to,end);
846
886
{
847
887
  uint spaces;
848
888
  if (get_bit(bit_buff))
849
 
    memset((uchar*) to, ' ', (end-to));
 
889
    bfill((uchar*) to,(end-to),' ');
850
890
  else
851
891
  {
852
892
    if ((spaces=get_bits(bit_buff,rec->space_length_bits))+to > end)
856
896
    }
857
897
    if (to+spaces != end)
858
898
      decode_bytes(rec,bit_buff,to,end-spaces);
859
 
    memset((uchar*) end-spaces, ' ', spaces);
 
899
    bfill((uchar*) end-spaces,spaces,' ');
860
900
  }
861
901
}
862
902
 
871
911
  }
872
912
  if (to+spaces != end)
873
913
    decode_bytes(rec,bit_buff,to,end-spaces);
874
 
  memset((uchar*) end-spaces, ' ', spaces);
 
914
  bfill((uchar*) end-spaces,spaces,' ');
875
915
}
876
916
 
877
917
static void uf_space_prespace_selected(MI_COLUMNDEF *rec, MI_BIT_BUFF *bit_buff,
879
919
{
880
920
  uint spaces;
881
921
  if (get_bit(bit_buff))
882
 
    memset((uchar*) to, ' ', (end-to));
 
922
    bfill((uchar*) to,(end-to),' ');
883
923
  else
884
924
  {
885
925
    if (get_bit(bit_buff))
889
929
        bit_buff->error=1;
890
930
        return;
891
931
      }
892
 
      memset((uchar*) to, ' ', spaces);
 
932
      bfill((uchar*) to,spaces,' ');
893
933
      if (to+spaces != end)
894
934
        decode_bytes(rec,bit_buff,to+spaces,end);
895
935
    }
910
950
      bit_buff->error=1;
911
951
      return;
912
952
    }
913
 
    memset((uchar*) to, ' ', spaces);
 
953
    bfill((uchar*) to,spaces,' ');
914
954
    if (to+spaces != end)
915
955
      decode_bytes(rec,bit_buff,to+spaces,end);
916
956
  }
924
964
{
925
965
  uint spaces;
926
966
  if (get_bit(bit_buff))
927
 
    memset((uchar*) to, ' ', (end-to));
 
967
    bfill((uchar*) to,(end-to),' ');
928
968
  else
929
969
  {
930
970
    if ((spaces=get_bits(bit_buff,rec->space_length_bits))+to > end)
932
972
      bit_buff->error=1;
933
973
      return;
934
974
    }
935
 
    memset((uchar*) to, ' ', spaces);
 
975
    bfill((uchar*) to,spaces,' ');
936
976
    if (to+spaces != end)
937
977
      decode_bytes(rec,bit_buff,to+spaces,end);
938
978
  }
947
987
    bit_buff->error=1;
948
988
    return;
949
989
  }
950
 
  memset((uchar*) to, ' ', spaces);
 
990
  bfill((uchar*) to,spaces,' ');
951
991
  if (to+spaces != end)
952
992
    decode_bytes(rec,bit_buff,to+spaces,end);
953
993
}
957
997
{
958
998
  end-=rec->space_length_bits;
959
999
  decode_bytes(rec,bit_buff,(uchar*) to,end);
960
 
  memset((char*) end, 0, rec->space_length_bits);
 
1000
  bzero((char*) end,rec->space_length_bits);
961
1001
}
962
1002
 
963
1003
static void uf_constant(MI_COLUMNDEF *rec,
983
1023
                    MI_BIT_BUFF *bit_buff __attribute__((unused)),
984
1024
                    uchar *to, uchar *end)
985
1025
{
986
 
  memset((char*) to, 0, (uint) (end-to));
 
1026
  bzero((char*) to,(uint) (end-to));
987
1027
}
988
1028
 
989
1029
static void uf_blob(MI_COLUMNDEF *rec, MI_BIT_BUFF *bit_buff,
990
1030
                    uchar *to, uchar *end)
991
1031
{
992
1032
  if (get_bit(bit_buff))
993
 
    memset((uchar*) to, 0, (end-to));
 
1033
    bzero((uchar*) to,(end-to));
994
1034
  else
995
1035
  {
996
1036
    ulong length=get_bits(bit_buff,rec->space_length_bits);
998
1038
    if (bit_buff->blob_pos+length > bit_buff->blob_end)
999
1039
    {
1000
1040
      bit_buff->error=1;
1001
 
      memset((uchar*) to, 0, (end-to));
 
1041
      bzero((uchar*) to,(end-to));
1002
1042
      return;
1003
1043
    }
1004
1044
    decode_bytes(rec,bit_buff,bit_buff->blob_pos,bit_buff->blob_pos+length);
1005
1045
    _my_store_blob_length((uchar*) to,pack_length,length);
1006
 
    memcpy((char*) to+pack_length,(char*) &bit_buff->blob_pos,
1007
 
           sizeof(char*));
 
1046
    memcpy_fixed((char*) to+pack_length,(char*) &bit_buff->blob_pos,
 
1047
                 sizeof(char*));
1008
1048
    bit_buff->blob_pos+=length;
1009
1049
  }
1010
1050
}
1045
1085
                         uchar *end)
1046
1086
{
1047
1087
  register uint bits,low_byte;
1048
 
  register uint16_t *pos;
 
1088
  register uint16 *pos;
1049
1089
  register uint table_bits,table_and;
1050
1090
  MI_DECODE_TREE *decode_tree;
1051
1091
 
1138
1178
                         uchar *end)
1139
1179
{
1140
1180
  register uint bits,low_byte;
1141
 
  register uint16_t *pos;
 
1181
  register uint16 *pos;
1142
1182
  register uint table_bits,table_and;
1143
1183
  MI_DECODE_TREE *decode_tree;
1144
1184
 
1233
1273
 
1234
1274
static uint decode_pos(MI_BIT_BUFF *bit_buff, MI_DECODE_TREE *decode_tree)
1235
1275
{
1236
 
  uint16_t *pos=decode_tree->table;
 
1276
  uint16 *pos=decode_tree->table;
1237
1277
  for (;;)
1238
1278
  {
1239
1279
    if (get_bit(bit_buff))
1252
1292
  uint b_type;
1253
1293
  MI_BLOCK_INFO block_info;
1254
1294
  MYISAM_SHARE *share=info->s;
 
1295
  DBUG_ENTER("_mi_read_rnd_pack_record");
1255
1296
 
1256
1297
  if (filepos >= info->state->data_file_length)
1257
1298
  {
1273
1314
                                   &info->rec_buff, info->dfile, filepos);
1274
1315
  if (b_type)
1275
1316
    goto err;                                   /* Error code is already set */
 
1317
#ifndef DBUG_OFF
 
1318
  if (block_info.rec_len > share->max_pack_length)
 
1319
  {
 
1320
    my_errno=HA_ERR_WRONG_IN_RECORD;
 
1321
    goto err;
 
1322
  }
 
1323
#endif
1276
1324
 
1277
1325
  if (info->opt_flag & READ_CACHE_USED)
1278
1326
  {
1293
1341
  info->nextpos=block_info.filepos+block_info.rec_len;
1294
1342
  info->update|= HA_STATE_AKTIV | HA_STATE_KEY_CHANGED;
1295
1343
 
1296
 
  return (_mi_pack_rec_unpack(info, &info->bit_buff, buf,
 
1344
  DBUG_RETURN (_mi_pack_rec_unpack(info, &info->bit_buff, buf,
1297
1345
                                   info->rec_buff, block_info.rec_len));
1298
1346
 err:
1299
 
  return(my_errno);
 
1347
  DBUG_RETURN(my_errno);
1300
1348
}
1301
1349
 
1302
1350
 
1319
1367
    VOID(my_seek(file,filepos,MY_SEEK_SET,MYF(0)));
1320
1368
    if (my_read(file, header,ref_length,MYF(MY_NABP)))
1321
1369
      return BLOCK_FATAL_ERROR;
 
1370
    DBUG_DUMP("header",(uchar*) header,ref_length);
1322
1371
  }
1323
1372
  head_length= read_pack_length((uint) myisam->s->pack.version, header,
1324
1373
                                &info->rec_len);
1433
1482
my_bool _mi_memmap_file(MI_INFO *info)
1434
1483
{
1435
1484
  MYISAM_SHARE *share=info->s;
 
1485
  DBUG_ENTER("mi_memmap_file");
1436
1486
 
1437
1487
  if (!info->s->file_map)
1438
1488
  {
1439
1489
    if (my_seek(info->dfile,0L,MY_SEEK_END,MYF(0)) <
1440
1490
        share->state.state.data_file_length+MEMMAP_EXTRA_MARGIN)
1441
1491
    {
1442
 
      return(0);
 
1492
      DBUG_PRINT("warning",("File isn't extended for memmap"));
 
1493
      DBUG_RETURN(0);
1443
1494
    }
1444
1495
    if (mi_dynmap_file(info, share->state.state.data_file_length))
1445
 
      return(0);
 
1496
      DBUG_RETURN(0);
1446
1497
  }
1447
1498
  info->opt_flag|= MEMMAP_USED;
1448
1499
  info->read_record= share->read_record= _mi_read_mempack_record;
1449
1500
  share->read_rnd= _mi_read_rnd_mempack_record;
1450
 
  return(1);
 
1501
  DBUG_RETURN(1);
1451
1502
}
1452
1503
 
1453
1504
 
1484
1535
  MI_BLOCK_INFO block_info;
1485
1536
  MYISAM_SHARE *share=info->s;
1486
1537
  uchar *pos;
 
1538
  DBUG_ENTER("mi_read_mempack_record");
1487
1539
 
1488
1540
  if (filepos == HA_OFFSET_ERROR)
1489
 
    return(-1);                 /* _search() didn't find record */
 
1541
    DBUG_RETURN(-1);                    /* _search() didn't find record */
1490
1542
 
1491
1543
  if (!(pos= (uchar*) _mi_mempack_get_block_info(info, &info->bit_buff,
1492
1544
                                                &block_info, &info->rec_buff,
1493
1545
                                                (uchar*) share->file_map+
1494
1546
                                                filepos)))
1495
 
    return(-1);
1496
 
  return(_mi_pack_rec_unpack(info, &info->bit_buff, buf,
 
1547
    DBUG_RETURN(-1);
 
1548
  DBUG_RETURN(_mi_pack_rec_unpack(info, &info->bit_buff, buf,
1497
1549
                                  pos, block_info.rec_len));
1498
1550
}
1499
1551
 
1507
1559
  MI_BLOCK_INFO block_info;
1508
1560
  MYISAM_SHARE *share=info->s;
1509
1561
  uchar *pos,*start;
 
1562
  DBUG_ENTER("_mi_read_rnd_mempack_record");
1510
1563
 
1511
1564
  if (filepos >= share->state.state.data_file_length)
1512
1565
  {
1519
1572
                                                (start=share->file_map+
1520
1573
                                                 filepos))))
1521
1574
    goto err;
 
1575
#ifndef DBUG_OFF
 
1576
  if (block_info.rec_len > info->s->max_pack_length)
 
1577
  {
 
1578
    my_errno=HA_ERR_WRONG_IN_RECORD;
 
1579
    goto err;
 
1580
  }
 
1581
#endif
1522
1582
  info->packed_length=block_info.rec_len;
1523
1583
  info->lastpos=filepos;
1524
1584
  info->nextpos=filepos+(uint) (pos-start)+block_info.rec_len;
1525
1585
  info->update|= HA_STATE_AKTIV | HA_STATE_KEY_CHANGED;
1526
1586
 
1527
 
  return (_mi_pack_rec_unpack(info, &info->bit_buff, buf,
 
1587
  DBUG_RETURN (_mi_pack_rec_unpack(info, &info->bit_buff, buf,
1528
1588
                                   pos, block_info.rec_len));
1529
1589
 err:
1530
 
  return(my_errno);
 
1590
  DBUG_RETURN(my_errno);
1531
1591
}
1532
1592
 
1533
1593
#endif /* HAVE_MMAP */
1550
1610
  *(uchar*) block_buff=255;
1551
1611
  if (version == 1) /* old format */
1552
1612
  {
1553
 
    assert(length <= 0xFFFFFF);
 
1613
    DBUG_ASSERT(length <= 0xFFFFFF);
1554
1614
    int3store(block_buff + 1, (ulong) length);
1555
1615
    return 4;
1556
1616
  }