Tcl Source Code

Check-in [dbff67cd44]
Login

Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.

Overview
Comment:only do the alloc-space maximization when needed
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | mig-alloc-reform
Files: files | file ages | folders
SHA1: dbff67cd44a51300b5dcb7fc6666ba13e83857ae
User & Date: mig 2011-03-24 22:48:21
Context
2011-03-25
01:09
reordering of TEBCdata fields, just for clarity check-in: c98b86fea1 user: mig tags: mig-alloc-reform
2011-03-24
22:48
only do the alloc-space maximization when needed check-in: dbff67cd44 user: mig tags: mig-alloc-reform
22:06
add finalization code; needed? check-in: 5a869d1e11 user: mig tags: mig-alloc-reform
Changes
Hide Diffs Unified Diffs Ignore Whitespace Patch

Changes to generic/tclExecute.c.

1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
     * Make sure the catch stack is large enough to hold the maximum number of
     * catch commands that could ever be executing at the same time (this will
     * be no more than the exception range array's depth). Make sure the
     * execution stack is large enough to execute this ByteCode.
     */

    TD = ckalloc(size);
    size = TclAllocMaximize(TD);
    if (size == UINT_MAX) {
	TD->capacity = codePtr->maxStackDepth;
    } else {
	TD->capacity = size2capacity(size);
    }
        
    TD->tosPtr = initTosPtr;
    
    TD->codePtr     = codePtr;
    TD->pc          = codePtr->codeStart;
    TD->catchDepth  = -1;
    TD->cleanup     = 0;







<
<
|
<
<
<







1565
1566
1567
1568
1569
1570
1571


1572



1573
1574
1575
1576
1577
1578
1579
     * Make sure the catch stack is large enough to hold the maximum number of
     * catch commands that could ever be executing at the same time (this will
     * be no more than the exception range array's depth). Make sure the
     * execution stack is large enough to execute this ByteCode.
     */

    TD = ckalloc(size);


    TD->capacity = codePtr->maxStackDepth;



        
    TD->tosPtr = initTosPtr;
    
    TD->codePtr     = codePtr;
    TD->pc          = codePtr->codeStart;
    TD->catchDepth  = -1;
    TD->cleanup     = 0;

Changes to generic/tclListObj.c.

75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116

static List *
NewListIntRep(
    int objc,
    Tcl_Obj *const objv[])
{
    List *listRepPtr;
    unsigned int allocSize;
    
    if (objc <= 0) {
	return NULL;
    }

    /*
     * First check to see if we'd overflow and try to allocate an object
     * larger than our memory allocator allows. Note that this is actually a
     * fairly small value when you're on a serious 64-bit machine, but that
     * requires API changes to fix. See [Bug 219196] for a discussion.
     */

    if ((size_t)objc > INT_MAX/sizeof(Tcl_Obj *)) {
	return NULL;
    }

    listRepPtr = attemptckalloc(Elems2Size(objc));
    if (listRepPtr == NULL) {
	return NULL;
    }
    allocSize = TclAllocMaximize(listRepPtr);
    
    listRepPtr->canonicalFlag = 0;
    listRepPtr->refCount = 0;
    listRepPtr->maxElemCount = (allocSize == UINT_MAX)
	? objc
	: Size2Elems(allocSize);

    if (objv) {
	Tcl_Obj **elemPtrs;
	int i;

	listRepPtr->elemCount = objc;
	elemPtrs = &listRepPtr->elements;







<




















<



|
<
<







75
76
77
78
79
80
81

82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101

102
103
104
105


106
107
108
109
110
111
112

static List *
NewListIntRep(
    int objc,
    Tcl_Obj *const objv[])
{
    List *listRepPtr;

    
    if (objc <= 0) {
	return NULL;
    }

    /*
     * First check to see if we'd overflow and try to allocate an object
     * larger than our memory allocator allows. Note that this is actually a
     * fairly small value when you're on a serious 64-bit machine, but that
     * requires API changes to fix. See [Bug 219196] for a discussion.
     */

    if ((size_t)objc > INT_MAX/sizeof(Tcl_Obj *)) {
	return NULL;
    }

    listRepPtr = attemptckalloc(Elems2Size(objc));
    if (listRepPtr == NULL) {
	return NULL;
    }

    
    listRepPtr->canonicalFlag = 0;
    listRepPtr->refCount = 0;
    listRepPtr->maxElemCount = objc;



    if (objv) {
	Tcl_Obj **elemPtrs;
	int i;

	listRepPtr->elemCount = objc;
	elemPtrs = &listRepPtr->elements;
580
581
582
583
584
585
586







587
588
589
590
591
592
593

    /*
     * If there is no room in the current array of element pointers, allocate
     * a new, larger array and copy the pointers to it. If the List struct is
     * shared, allocate a new one.
     */








    if (numRequired > listRepPtr->maxElemCount){
	newMax = 2 * numRequired;
	newSize = Elems2Size(newMax);
    } else {
	newMax = listRepPtr->maxElemCount;
	newSize = 0;
    }







>
>
>
>
>
>
>







576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596

    /*
     * If there is no room in the current array of element pointers, allocate
     * a new, larger array and copy the pointers to it. If the List struct is
     * shared, allocate a new one.
     */

    if (numRequired > listRepPtr->maxElemCount){
	unsigned int allocSize = TclAllocMaximize(listRepPtr);
	if (allocSize != UINT_MAX) {
	    listRepPtr->maxElemCount = Size2Elems(allocSize);
	}
    }
	
    if (numRequired > listRepPtr->maxElemCount){
	newMax = 2 * numRequired;
	newSize = Elems2Size(newMax);
    } else {
	newMax = listRepPtr->maxElemCount;
	newSize = 0;
    }
847
848
849
850
851
852
853







854
855
856
857
858
859
860
	 * overflow in determining 'first+count'
	 */
	count = numElems - first;
    }

    isShared = (listRepPtr->refCount > 1);
    numRequired = numElems - count + objc;








    if ((numRequired <= listRepPtr->maxElemCount) && !isShared) {
	int shift;

	/*
	 * Can use the current List struct. First "delete" count elements
	 * starting at first.







>
>
>
>
>
>
>







850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
	 * overflow in determining 'first+count'
	 */
	count = numElems - first;
    }

    isShared = (listRepPtr->refCount > 1);
    numRequired = numElems - count + objc;

    if (numRequired > listRepPtr->maxElemCount){
	unsigned int allocSize = TclAllocMaximize(listRepPtr);
	if (allocSize != UINT_MAX) {
	    listRepPtr->maxElemCount = Size2Elems(allocSize);
	}
    }

    if ((numRequired <= listRepPtr->maxElemCount) && !isShared) {
	int shift;

	/*
	 * Can use the current List struct. First "delete" count elements
	 * starting at first.