| ︙ | | | ︙ | |
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
|
* Results:
* Pointer to array of bytes, or NULL. representing the ByteArray object.
* Writes number of bytes in array to *lengthPtr.
*
*----------------------------------------------------------------------
*/
unsigned char *
TclGetBytesFromObj(
Tcl_Interp *interp, /* For error reporting */
Tcl_Obj *objPtr, /* Value to extract from */
size_t *lengthPtr) /* If non-NULL, filled with length of the
* array of bytes in the ByteArray object. */
{
ByteArray *baPtr;
const Tcl_ObjIntRep *irPtr = TclFetchIntRep(objPtr, &properByteArrayType);
|
>
|
|
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
|
* Results:
* Pointer to array of bytes, or NULL. representing the ByteArray object.
* Writes number of bytes in array to *lengthPtr.
*
*----------------------------------------------------------------------
*/
#undef Tcl_GetBytesFromObj
unsigned char *
Tcl_GetBytesFromObj(
Tcl_Interp *interp, /* For error reporting */
Tcl_Obj *objPtr, /* Value to extract from */
size_t *lengthPtr) /* If non-NULL, filled with length of the
* array of bytes in the ByteArray object. */
{
ByteArray *baPtr;
const Tcl_ObjIntRep *irPtr = TclFetchIntRep(objPtr, &properByteArrayType);
|
| ︙ | | | ︙ | |
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
|
if (lengthPtr != NULL) {
*lengthPtr = baPtr->used;
}
return baPtr->bytes;
}
unsigned char *
Tcl_GetBytesFromObj(
Tcl_Interp *interp, /* For error reporting */
Tcl_Obj *objPtr, /* Value to extract from */
int *lengthPtr) /* If non-NULL, filled with length of the
* array of bytes in the ByteArray object. */
{
size_t numBytes = 0;
unsigned char *bytes = TclGetBytesFromObj(interp, objPtr, &numBytes);
if (lengthPtr) {
if (numBytes > INT_MAX) {
/* Caller asked for an int length, but true length is outside
* the int range. This case will be developed out of existence
* in Tcl 9. As interim measure, fail. */
|
|
|
|
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
|
if (lengthPtr != NULL) {
*lengthPtr = baPtr->used;
}
return baPtr->bytes;
}
unsigned char *
TclGetBytesFromObj(
Tcl_Interp *interp, /* For error reporting */
Tcl_Obj *objPtr, /* Value to extract from */
int *lengthPtr) /* If non-NULL, filled with length of the
* array of bytes in the ByteArray object. */
{
size_t numBytes = 0;
unsigned char *bytes = Tcl_GetBytesFromObj(interp, objPtr, &numBytes);
if (lengthPtr) {
if (numBytes > INT_MAX) {
/* Caller asked for an int length, but true length is outside
* the int range. This case will be developed out of existence
* in Tcl 9. As interim measure, fail. */
|
| ︙ | | | ︙ | |
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
|
*
* Side effects:
* Frees old internal rep. Allocates memory for new internal rep.
*
*----------------------------------------------------------------------
*/
unsigned char *
Tcl_GetByteArrayFromObj(
Tcl_Obj *objPtr, /* The ByteArray object. */
int *lengthPtr) /* If non-NULL, filled with length of the
* array of bytes in the ByteArray object. */
{
size_t numBytes = 0;
unsigned char *bytes = TclGetBytesFromObj(NULL, objPtr, &numBytes);
/* Macro TclGetByteArrayFromObj passes NULL for lengthPtr as
* a trick to get around changing size. */
if (lengthPtr) {
if (numBytes > INT_MAX) {
/* Caller asked for an int length, but true length is outside
* the int range. This case will be developed out of existence
* in Tcl 9. As interim measure, fail. */
*lengthPtr = 0;
return NULL;
} else {
*lengthPtr = (int) numBytes;
}
}
return bytes;
}
/*
*----------------------------------------------------------------------
*
* Tcl_SetByteArrayLength --
*
* This procedure changes the length of the byte array for this object.
|
>
|
|
|
<
<
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
|
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
|
*
* Side effects:
* Frees old internal rep. Allocates memory for new internal rep.
*
*----------------------------------------------------------------------
*/
#undef Tcl_GetByteArrayFromObj
unsigned char *
TclGetByteArrayFromObj(
Tcl_Obj *objPtr, /* The ByteArray object. */
int *lengthPtr) /* If non-NULL, filled with length of the
* array of bytes in the ByteArray object. */
{
size_t numBytes = 0;
unsigned char *bytes = Tcl_GetBytesFromObj(NULL, objPtr, &numBytes);
/* Macro TclGetByteArrayFromObj passes NULL for lengthPtr as
* a trick to get around changing size. */
if (lengthPtr) {
if (numBytes > INT_MAX) {
/* Caller asked for an int length, but true length is outside
* the int range. */
*lengthPtr = 0;
return NULL;
} else {
*lengthPtr = (int) numBytes;
}
}
return bytes;
}
unsigned char *
Tcl_GetByteArrayFromObj(
Tcl_Obj *objPtr, /* The ByteArray object. */
size_t *lengthPtr) /* If non-NULL, filled with length of the
* array of bytes in the ByteArray object. */
{
size_t numBytes = 0;
unsigned char *bytes = Tcl_GetBytesFromObj(NULL, objPtr, &numBytes);
/* Macro TclGetByteArrayFromObj passes NULL for lengthPtr as
* a trick to get around changing size. */
if (lengthPtr) {
*lengthPtr = numBytes;
}
return bytes;
}
/*
*----------------------------------------------------------------------
*
* Tcl_SetByteArrayLength --
*
* This procedure changes the length of the byte array for this object.
|
| ︙ | | | ︙ | |
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
|
Tcl_Interp *interp,
Tcl_Obj *objPtr,
size_t limit,
int demandProper,
ByteArray **byteArrayPtrPtr)
{
size_t length;
const char *src = TclGetStringFromObj(objPtr, &length);
size_t numBytes
= (limit != TCL_INDEX_NONE && limit < length) ? limit : length;
ByteArray *byteArrayPtr = (ByteArray *)Tcl_Alloc(BYTEARRAY_SIZE(numBytes));
unsigned char *dst = byteArrayPtr->bytes;
unsigned char *dstEnd = dst + numBytes;
const char *srcEnd = src + length;
int proper = 1;
|
|
|
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
|
Tcl_Interp *interp,
Tcl_Obj *objPtr,
size_t limit,
int demandProper,
ByteArray **byteArrayPtrPtr)
{
size_t length;
const char *src = Tcl_GetStringFromObj(objPtr, &length);
size_t numBytes
= (limit != TCL_INDEX_NONE && limit < length) ? limit : length;
ByteArray *byteArrayPtr = (ByteArray *)Tcl_Alloc(BYTEARRAY_SIZE(numBytes));
unsigned char *dst = byteArrayPtr->bytes;
unsigned char *dstEnd = dst + numBytes;
const char *srcEnd = src + length;
int proper = 1;
|
| ︙ | | | ︙ | |
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
|
*/
if (arg >= objc) {
goto badIndex;
}
if (count == BINARY_ALL) {
Tcl_Obj *copy = TclNarrowToBytes(objv[arg]);
(void)TclGetByteArrayFromObj(copy, &count);
Tcl_DecrRefCount(copy);
} else if (count == BINARY_NOCOUNT) {
count = 1;
}
arg++;
if (cmd == 'a' || cmd == 'A') {
offset += count;
|
|
|
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
|
*/
if (arg >= objc) {
goto badIndex;
}
if (count == BINARY_ALL) {
Tcl_Obj *copy = TclNarrowToBytes(objv[arg]);
(void)Tcl_GetByteArrayFromObj(copy, &count);
Tcl_DecrRefCount(copy);
} else if (count == BINARY_NOCOUNT) {
count = 1;
}
arg++;
if (cmd == 'a' || cmd == 'A') {
offset += count;
|
| ︙ | | | ︙ | |
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
|
switch (cmd) {
case 'a':
case 'A': {
char pad = (char) (cmd == 'a' ? '\0' : ' ');
unsigned char *bytes;
Tcl_Obj *copy = TclNarrowToBytes(objv[arg++]);
bytes = TclGetByteArrayFromObj(copy, &length);
if (count == BINARY_ALL) {
count = length;
} else if (count == BINARY_NOCOUNT) {
count = 1;
}
if (length >= count) {
memcpy(cursor, bytes, count);
} else {
memcpy(cursor, bytes, length);
memset(cursor + length, pad, count - length);
}
cursor += count;
Tcl_DecrRefCount(copy);
break;
}
case 'b':
case 'B': {
unsigned char *last;
str = TclGetStringFromObj(objv[arg], &length);
arg++;
if (count == BINARY_ALL) {
count = length;
} else if (count == BINARY_NOCOUNT) {
count = 1;
}
last = cursor + ((count + 7) / 8);
|
|
|
|
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
|
switch (cmd) {
case 'a':
case 'A': {
char pad = (char) (cmd == 'a' ? '\0' : ' ');
unsigned char *bytes;
Tcl_Obj *copy = TclNarrowToBytes(objv[arg++]);
bytes = Tcl_GetByteArrayFromObj(copy, &length);
if (count == BINARY_ALL) {
count = length;
} else if (count == BINARY_NOCOUNT) {
count = 1;
}
if (length >= count) {
memcpy(cursor, bytes, count);
} else {
memcpy(cursor, bytes, length);
memset(cursor + length, pad, count - length);
}
cursor += count;
Tcl_DecrRefCount(copy);
break;
}
case 'b':
case 'B': {
unsigned char *last;
str = Tcl_GetStringFromObj(objv[arg], &length);
arg++;
if (count == BINARY_ALL) {
count = length;
} else if (count == BINARY_NOCOUNT) {
count = 1;
}
last = cursor + ((count + 7) / 8);
|
| ︙ | | | ︙ | |
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
|
break;
}
case 'h':
case 'H': {
unsigned char *last;
int c;
str = TclGetStringFromObj(objv[arg], &length);
arg++;
if (count == BINARY_ALL) {
count = length;
} else if (count == BINARY_NOCOUNT) {
count = 1;
}
last = cursor + ((count + 1) / 2);
|
|
|
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
|
break;
}
case 'h':
case 'H': {
unsigned char *last;
int c;
str = Tcl_GetStringFromObj(objv[arg], &length);
arg++;
if (count == BINARY_ALL) {
count = length;
} else if (count == BINARY_NOCOUNT) {
count = 1;
}
last = cursor + ((count + 1) / 2);
|
| ︙ | | | ︙ | |
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
|
Tcl_HashTable *numberCachePtr;
if (objc < 3) {
Tcl_WrongNumArgs(interp, 1, objv,
"value formatString ?varName ...?");
return TCL_ERROR;
}
buffer = TclGetBytesFromObj(interp, objv[1], &length);
if (buffer == NULL) {
return TCL_ERROR;
}
numberCachePtr = &numberCacheHash;
Tcl_InitHashTable(numberCachePtr, TCL_ONE_WORD_KEYS);
format = TclGetString(objv[2]);
arg = 3;
|
|
|
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
|
Tcl_HashTable *numberCachePtr;
if (objc < 3) {
Tcl_WrongNumArgs(interp, 1, objv,
"value formatString ?varName ...?");
return TCL_ERROR;
}
buffer = Tcl_GetBytesFromObj(interp, objv[1], &length);
if (buffer == NULL) {
return TCL_ERROR;
}
numberCachePtr = &numberCacheHash;
Tcl_InitHashTable(numberCachePtr, TCL_ONE_WORD_KEYS);
format = TclGetString(objv[2]);
arg = 3;
|
| ︙ | | | ︙ | |
2574
2575
2576
2577
2578
2579
2580
2581
2582
2583
2584
2585
2586
2587
2588
|
size_t offset = 0, count = 0;
if (objc != 2) {
Tcl_WrongNumArgs(interp, 1, objv, "data");
return TCL_ERROR;
}
data = TclGetBytesFromObj(interp, objv[1], &count);
if (data == NULL) {
return TCL_ERROR;
}
TclNewObj(resultObj);
cursor = Tcl_SetByteArrayLength(resultObj, count * 2);
for (offset = 0; offset < count; ++offset) {
|
|
|
2591
2592
2593
2594
2595
2596
2597
2598
2599
2600
2601
2602
2603
2604
2605
|
size_t offset = 0, count = 0;
if (objc != 2) {
Tcl_WrongNumArgs(interp, 1, objv, "data");
return TCL_ERROR;
}
data = Tcl_GetBytesFromObj(interp, objv[1], &count);
if (data == NULL) {
return TCL_ERROR;
}
TclNewObj(resultObj);
cursor = Tcl_SetByteArrayLength(resultObj, count * 2);
for (offset = 0; offset < count; ++offset) {
|
| ︙ | | | ︙ | |
2638
2639
2640
2641
2642
2643
2644
2645
2646
2647
2648
2649
2650
2651
2652
2653
2654
2655
|
case OPT_STRICT:
strict = 1;
break;
}
}
TclNewObj(resultObj);
data = TclGetBytesFromObj(NULL, objv[objc - 1], &count);
if (data == NULL) {
pure = 0;
data = (unsigned char *) TclGetStringFromObj(objv[objc - 1], &count);
}
datastart = data;
dataend = data + count;
size = (count + 1) / 2;
begin = cursor = Tcl_SetByteArrayLength(resultObj, size);
while (data < dataend) {
value = 0;
|
|
|
|
2655
2656
2657
2658
2659
2660
2661
2662
2663
2664
2665
2666
2667
2668
2669
2670
2671
2672
|
case OPT_STRICT:
strict = 1;
break;
}
}
TclNewObj(resultObj);
data = Tcl_GetBytesFromObj(NULL, objv[objc - 1], &count);
if (data == NULL) {
pure = 0;
data = (unsigned char *) Tcl_GetStringFromObj(objv[objc - 1], &count);
}
datastart = data;
dataend = data + count;
size = (count + 1) / 2;
begin = cursor = Tcl_SetByteArrayLength(resultObj, size);
while (data < dataend) {
value = 0;
|
| ︙ | | | ︙ | |
2771
2772
2773
2774
2775
2776
2777
2778
2779
2780
2781
2782
2783
2784
2785
2786
2787
2788
2789
2790
2791
2792
2793
2794
2795
2796
2797
2798
|
"line length out of range", -1));
Tcl_SetErrorCode(interp, "TCL", "BINARY", "ENCODE",
"LINE_LENGTH", NULL);
return TCL_ERROR;
}
break;
case OPT_WRAPCHAR:
wrapchar = (const char *)TclGetBytesFromObj(NULL,
objv[i + 1], &wrapcharlen);
if (wrapchar == NULL) {
purewrap = 0;
wrapchar = TclGetStringFromObj(objv[i + 1], &wrapcharlen);
}
break;
}
}
if (wrapcharlen == 0) {
maxlen = 0;
}
data = TclGetBytesFromObj(interp, objv[objc - 1], &count);
if (data == NULL) {
return TCL_ERROR;
}
TclNewObj(resultObj);
if (count > 0) {
unsigned char *cursor = NULL;
|
|
|
|
|
2788
2789
2790
2791
2792
2793
2794
2795
2796
2797
2798
2799
2800
2801
2802
2803
2804
2805
2806
2807
2808
2809
2810
2811
2812
2813
2814
2815
|
"line length out of range", -1));
Tcl_SetErrorCode(interp, "TCL", "BINARY", "ENCODE",
"LINE_LENGTH", NULL);
return TCL_ERROR;
}
break;
case OPT_WRAPCHAR:
wrapchar = (const char *)Tcl_GetBytesFromObj(NULL,
objv[i + 1], &wrapcharlen);
if (wrapchar == NULL) {
purewrap = 0;
wrapchar = Tcl_GetStringFromObj(objv[i + 1], &wrapcharlen);
}
break;
}
}
if (wrapcharlen == 0) {
maxlen = 0;
}
data = Tcl_GetBytesFromObj(interp, objv[objc - 1], &count);
if (data == NULL) {
return TCL_ERROR;
}
TclNewObj(resultObj);
if (count > 0) {
unsigned char *cursor = NULL;
|
| ︙ | | | ︙ | |
2899
2900
2901
2902
2903
2904
2905
2906
2907
2908
2909
2910
2911
2912
2913
|
Tcl_SetErrorCode(interp, "TCL", "BINARY", "ENCODE",
"LINE_LENGTH", NULL);
return TCL_ERROR;
}
lineLength = ((lineLength - 1) & -4) + 1; /* 5, 9, 13 ... */
break;
case OPT_WRAPCHAR:
wrapchar = (const unsigned char *) TclGetStringFromObj(
objv[i + 1], &wrapcharlen);
{
const unsigned char *p = wrapchar;
size_t numBytes = wrapcharlen;
while (numBytes) {
switch (*p) {
|
|
|
2916
2917
2918
2919
2920
2921
2922
2923
2924
2925
2926
2927
2928
2929
2930
|
Tcl_SetErrorCode(interp, "TCL", "BINARY", "ENCODE",
"LINE_LENGTH", NULL);
return TCL_ERROR;
}
lineLength = ((lineLength - 1) & -4) + 1; /* 5, 9, 13 ... */
break;
case OPT_WRAPCHAR:
wrapchar = (const unsigned char *) Tcl_GetStringFromObj(
objv[i + 1], &wrapcharlen);
{
const unsigned char *p = wrapchar;
size_t numBytes = wrapcharlen;
while (numBytes) {
switch (*p) {
|
| ︙ | | | ︙ | |
2940
2941
2942
2943
2944
2945
2946
2947
2948
2949
2950
2951
2952
2953
2954
|
/*
* Allocate the buffer. This is a little bit too long, but is "good
* enough".
*/
offset = 0;
data = TclGetBytesFromObj(interp, objv[objc - 1], &count);
if (data == NULL) {
return TCL_ERROR;
}
TclNewObj(resultObj);
rawLength = (lineLength - 1) * 3 / 4;
start = cursor = Tcl_SetByteArrayLength(resultObj,
(lineLength + wrapcharlen) *
|
|
|
2957
2958
2959
2960
2961
2962
2963
2964
2965
2966
2967
2968
2969
2970
2971
|
/*
* Allocate the buffer. This is a little bit too long, but is "good
* enough".
*/
offset = 0;
data = Tcl_GetBytesFromObj(interp, objv[objc - 1], &count);
if (data == NULL) {
return TCL_ERROR;
}
TclNewObj(resultObj);
rawLength = (lineLength - 1) * 3 / 4;
start = cursor = Tcl_SetByteArrayLength(resultObj,
(lineLength + wrapcharlen) *
|
| ︙ | | | ︙ | |
3041
3042
3043
3044
3045
3046
3047
3048
3049
3050
3051
3052
3053
3054
3055
3056
3057
3058
|
case OPT_STRICT:
strict = 1;
break;
}
}
TclNewObj(resultObj);
data = TclGetBytesFromObj(NULL, objv[objc - 1], &count);
if (data == NULL) {
pure = 0;
data = (unsigned char *) TclGetStringFromObj(objv[objc - 1], &count);
}
datastart = data;
dataend = data + count;
size = ((count + 3) & ~3) * 3 / 4;
begin = cursor = Tcl_SetByteArrayLength(resultObj, size);
lineLen = -1;
|
|
|
|
3058
3059
3060
3061
3062
3063
3064
3065
3066
3067
3068
3069
3070
3071
3072
3073
3074
3075
|
case OPT_STRICT:
strict = 1;
break;
}
}
TclNewObj(resultObj);
data = Tcl_GetBytesFromObj(NULL, objv[objc - 1], &count);
if (data == NULL) {
pure = 0;
data = (unsigned char *) Tcl_GetStringFromObj(objv[objc - 1], &count);
}
datastart = data;
dataend = data + count;
size = ((count + 3) & ~3) * 3 / 4;
begin = cursor = Tcl_SetByteArrayLength(resultObj, size);
lineLen = -1;
|
| ︙ | | | ︙ | |
3216
3217
3218
3219
3220
3221
3222
3223
3224
3225
3226
3227
3228
3229
3230
3231
3232
3233
|
case OPT_STRICT:
strict = 1;
break;
}
}
TclNewObj(resultObj);
data = TclGetBytesFromObj(NULL, objv[objc - 1], &count);
if (data == NULL) {
pure = 0;
data = (unsigned char *) TclGetStringFromObj(objv[objc - 1], &count);
}
datastart = data;
dataend = data + count;
size = ((count + 3) & ~3) * 3 / 4;
begin = cursor = Tcl_SetByteArrayLength(resultObj, size);
while (data < dataend) {
unsigned long value = 0;
|
|
|
|
3233
3234
3235
3236
3237
3238
3239
3240
3241
3242
3243
3244
3245
3246
3247
3248
3249
3250
|
case OPT_STRICT:
strict = 1;
break;
}
}
TclNewObj(resultObj);
data = Tcl_GetBytesFromObj(NULL, objv[objc - 1], &count);
if (data == NULL) {
pure = 0;
data = (unsigned char *) Tcl_GetStringFromObj(objv[objc - 1], &count);
}
datastart = data;
dataend = data + count;
size = ((count + 3) & ~3) * 3 / 4;
begin = cursor = Tcl_SetByteArrayLength(resultObj, size);
while (data < dataend) {
unsigned long value = 0;
|
| ︙ | | | ︙ | |