Many hyperlinks are disabled.
Use anonymous login
to enable hyperlinks.
Overview
Comment: | WIP trial of proper bytearrays in Tcl 9. |
---|---|
Downloads: | Tarball | ZIP archive | SQL archive |
Timelines: | family | ancestors | descendants | both | dgp-properbytearray |
Files: | files | file ages | folders |
SHA1: |
d7c68a46af9d10a4c90e78f911f0d57d |
User & Date: | dgp 2016-12-05 19:17:52 |
Context
2016-12-06
| ||
12:47 | merge novem check-in: fd1d2bbcbe user: dgp tags: dgp-properbytearray | |
2016-12-05
| ||
19:17 | WIP trial of proper bytearrays in Tcl 9. check-in: d7c68a46af user: dgp tags: dgp-properbytearray | |
2016-12-02
| ||
19:02 | merge trunk check-in: 237dd7902f user: dgp tags: novem | |
Changes
Changes to generic/tclBinary.c.
︙ | ︙ | |||
448 449 450 451 452 453 454 | int *lengthPtr) /* If non-NULL, filled with length of the * array of bytes in the ByteArray object. */ { ByteArray *baPtr; if ((objPtr->typePtr != &properByteArrayType) && (objPtr->typePtr != &tclByteArrayType)) { | | > > | 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 | int *lengthPtr) /* If non-NULL, filled with length of the * array of bytes in the ByteArray object. */ { ByteArray *baPtr; if ((objPtr->typePtr != &properByteArrayType) && (objPtr->typePtr != &tclByteArrayType)) { if (TCL_ERROR == SetByteArrayFromAny(NULL, objPtr)) { return NULL; } } baPtr = GET_BYTEARRAY(objPtr); if (lengthPtr != NULL) { *lengthPtr = baPtr->used; } return (unsigned char *) baPtr->bytes; |
︙ | ︙ | |||
492 493 494 495 496 497 498 | ByteArray *byteArrayPtr; if (Tcl_IsShared(objPtr)) { Tcl_Panic("%s called with shared object", "Tcl_SetByteArrayLength"); } if ((objPtr->typePtr != &properByteArrayType) && (objPtr->typePtr != &tclByteArrayType)) { | | > > | 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 | ByteArray *byteArrayPtr; if (Tcl_IsShared(objPtr)) { Tcl_Panic("%s called with shared object", "Tcl_SetByteArrayLength"); } if ((objPtr->typePtr != &properByteArrayType) && (objPtr->typePtr != &tclByteArrayType)) { if (TCL_ERROR == SetByteArrayFromAny(NULL, objPtr)) { return NULL; } } byteArrayPtr = GET_BYTEARRAY(objPtr); if (length > byteArrayPtr->allocated) { byteArrayPtr = ckrealloc(byteArrayPtr, BYTEARRAY_SIZE(length)); byteArrayPtr->allocated = length; SET_BYTEARRAY(objPtr, byteArrayPtr); |
︙ | ︙ | |||
527 528 529 530 531 532 533 | */ static int SetByteArrayFromAny( Tcl_Interp *interp, /* Not used. */ Tcl_Obj *objPtr) /* The object to convert to type ByteArray. */ { | | | > > > | | 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 | */ static int SetByteArrayFromAny( Tcl_Interp *interp, /* Not used. */ Tcl_Obj *objPtr) /* The object to convert to type ByteArray. */ { int length; const char *src, *srcEnd; unsigned char *dst; ByteArray *byteArrayPtr; Tcl_UniChar ch; if (objPtr->typePtr == &properByteArrayType) { return TCL_OK; } if (objPtr->typePtr == &tclByteArrayType) { return TCL_OK; } src = TclGetStringFromObj(objPtr, &length); srcEnd = src + length; byteArrayPtr = ckalloc(BYTEARRAY_SIZE(length)); for (dst = byteArrayPtr->bytes; src < srcEnd; ) { src += Tcl_UtfToUniChar(src, &ch); if (ch > 255) { ckfree(byteArrayPtr); return TCL_ERROR; } *dst++ = UCHAR(ch); } byteArrayPtr->used = dst - byteArrayPtr->bytes; byteArrayPtr->allocated = length; TclFreeIntRep(objPtr); objPtr->typePtr = &properByteArrayType; SET_BYTEARRAY(objPtr, byteArrayPtr); return TCL_OK; } /* *---------------------------------------------------------------------- * |
︙ | ︙ | |||
727 728 729 730 731 732 733 | } if (len == 0) { /* Append zero bytes is a no-op. */ return; } if ((objPtr->typePtr != &properByteArrayType) && (objPtr->typePtr != &tclByteArrayType)) { | | > > | 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 | } if (len == 0) { /* Append zero bytes is a no-op. */ return; } if ((objPtr->typePtr != &properByteArrayType) && (objPtr->typePtr != &tclByteArrayType)) { if (TCL_ERROR == SetByteArrayFromAny(NULL, objPtr)) { Tcl_Panic("attempt to append bytes to non-bytearray"); } } byteArrayPtr = GET_BYTEARRAY(objPtr); if (len > INT_MAX - byteArrayPtr->used) { Tcl_Panic("max size for a Tcl value (%d bytes) exceeded", INT_MAX); } |
︙ | ︙ |