Add more HEAPCHECK
This commit is contained in:
parent
16810b63d4
commit
ee67c6dec1
|
@ -3,52 +3,55 @@ rem @echo off
|
|||
@call :test bitfields.cpp
|
||||
@if %errorlevel% neq 0 goto :error
|
||||
|
||||
@call :test opp_string.cpp
|
||||
@call :testh opp_string.cpp
|
||||
@if %errorlevel% neq 0 goto :error
|
||||
|
||||
@call :test opp_array.cpp
|
||||
@call :testh opp_array.cpp
|
||||
@if %errorlevel% neq 0 goto :error
|
||||
|
||||
@call :test opp_vector.cpp
|
||||
@call :testh opp_vector.cpp
|
||||
@if %errorlevel% neq 0 goto :error
|
||||
|
||||
@call :test opp_vector_string.cpp
|
||||
@call :testh opp_vector_string.cpp
|
||||
@if %errorlevel% neq 0 goto :error
|
||||
|
||||
@call :test opp_streamtest.cpp
|
||||
@call :testh opp_streamtest.cpp
|
||||
@if %errorlevel% neq 0 goto :error
|
||||
|
||||
@call :test opp_pairtest.cpp
|
||||
@call :testh opp_pairtest.cpp
|
||||
@if %errorlevel% neq 0 goto :error
|
||||
|
||||
@call :test opp_parts.cpp
|
||||
@call :testh opp_parts.cpp
|
||||
@if %errorlevel% neq 0 goto :error
|
||||
|
||||
@call :test operatoroverload.cpp
|
||||
@call :testh opp_list.cpp
|
||||
@if %errorlevel% neq 0 goto :error
|
||||
|
||||
@call :test virtualdestruct.cpp
|
||||
@call :testh operatoroverload.cpp
|
||||
@if %errorlevel% neq 0 goto :error
|
||||
|
||||
@call :test vcalltest.cpp
|
||||
@call :testh virtualdestruct.cpp
|
||||
@if %errorlevel% neq 0 goto :error
|
||||
|
||||
@call :test vcalltree.cpp
|
||||
@call :testh vcalltest.cpp
|
||||
@if %errorlevel% neq 0 goto :error
|
||||
|
||||
@call :test constructortest.cpp
|
||||
@call :testh vcalltree.cpp
|
||||
@if %errorlevel% neq 0 goto :error
|
||||
|
||||
@call :test copyconstructor.cpp
|
||||
@call :testh constructortest.cpp
|
||||
@if %errorlevel% neq 0 goto :error
|
||||
|
||||
@call :test copyassign.cpp
|
||||
@call :testh copyconstructor.cpp
|
||||
@if %errorlevel% neq 0 goto :error
|
||||
|
||||
@call :test arrayconstruct.cpp
|
||||
@call :testh copyassign.cpp
|
||||
@if %errorlevel% neq 0 goto :error
|
||||
|
||||
@call :test stdlibtest.c
|
||||
@call :testh arrayconstruct.cpp
|
||||
@if %errorlevel% neq 0 goto :error
|
||||
|
||||
@call :testh stdlibtest.c
|
||||
@if %errorlevel% neq 0 goto :error
|
||||
|
||||
@call :test testint16.c
|
||||
|
@ -225,6 +228,45 @@ rem @echo off
|
|||
echo Failed with error #%errorlevel%.
|
||||
exit /b %errorlevel%
|
||||
|
||||
:testh
|
||||
..\release\oscar64 -e -bc %~1
|
||||
@if %errorlevel% neq 0 goto :error
|
||||
|
||||
..\release\oscar64 -e -n %~1
|
||||
@if %errorlevel% neq 0 goto :error
|
||||
|
||||
..\release\oscar64 -e -O2 -bc %~1
|
||||
@if %errorlevel% neq 0 goto :error
|
||||
|
||||
..\release\oscar64 -e -O2 -n %~1
|
||||
@if %errorlevel% neq 0 goto :error
|
||||
|
||||
..\release\oscar64 -e -O2 -n -dHEAPCHECK %~1
|
||||
@if %errorlevel% neq 0 goto :error
|
||||
|
||||
..\release\oscar64 -e -O0 -bc %~1
|
||||
@if %errorlevel% neq 0 goto :error
|
||||
|
||||
..\release\oscar64 -e -O0 -n %~1
|
||||
@if %errorlevel% neq 0 goto :error
|
||||
|
||||
..\release\oscar64 -e -Os -bc %~1
|
||||
@if %errorlevel% neq 0 goto :error
|
||||
|
||||
..\release\oscar64 -e -Os -n %~1
|
||||
@if %errorlevel% neq 0 goto :error
|
||||
|
||||
..\release\oscar64 -e -O3 -bc %~1
|
||||
@if %errorlevel% neq 0 goto :error
|
||||
|
||||
..\release\oscar64 -e -O3 -n %~1
|
||||
@if %errorlevel% neq 0 goto :error
|
||||
|
||||
..\release\oscar64 -e -O3 -n -dHEAPCHECK %~1
|
||||
@if %errorlevel% neq 0 goto :error
|
||||
|
||||
@exit /b 0
|
||||
|
||||
:test
|
||||
..\release\oscar64 -e -bc %~1
|
||||
@if %errorlevel% neq 0 goto :error
|
||||
|
|
|
@ -0,0 +1,57 @@
|
|||
#include <opp/list.h>
|
||||
#include <opp/algorithm.h>
|
||||
#include <assert.h>
|
||||
#include <opp/iostream.h>
|
||||
|
||||
int main(void)
|
||||
{
|
||||
opp::list<int> a;
|
||||
|
||||
for(int i=0; i<10; i++)
|
||||
a.push_back(i);
|
||||
|
||||
int s = 0;
|
||||
for(auto i : a)
|
||||
s += i;
|
||||
|
||||
assert(s == 45);
|
||||
|
||||
auto li = a.begin();
|
||||
for(int i=0; i<5; i++)
|
||||
{
|
||||
li = a.erase(li);
|
||||
li++;
|
||||
}
|
||||
|
||||
s = 0;
|
||||
for(auto i : a)
|
||||
s += i;
|
||||
|
||||
assert(s == 1 + 3 + 5 + 7 + 9);
|
||||
|
||||
opp::list<int> b;
|
||||
|
||||
b = a;
|
||||
|
||||
s = 0;
|
||||
for(auto i : b)
|
||||
s += i;
|
||||
|
||||
assert(s == 1 + 3 + 5 + 7 + 9);
|
||||
|
||||
opp::list<int> c = opp::list<int>(b);
|
||||
|
||||
s = 0;
|
||||
for(auto i : c)
|
||||
s += i;
|
||||
|
||||
assert(s == 1 + 3 + 5 + 7 + 9);
|
||||
|
||||
s = 0;
|
||||
for(auto i : b)
|
||||
s += i;
|
||||
|
||||
assert(s == 1 + 3 + 5 + 7 + 9);
|
||||
|
||||
return 0;
|
||||
}
|
|
@ -4127,10 +4127,16 @@ __asm malloc
|
|||
{
|
||||
// make room for two additional bytes
|
||||
// to store pointer to end of used memory
|
||||
// in case of heap check we add six bytes to
|
||||
// add some guards
|
||||
|
||||
clc
|
||||
lda accu + 0
|
||||
#ifdef HEAPCHECK
|
||||
adc #6
|
||||
#else
|
||||
adc #2
|
||||
#endif
|
||||
sta tmp
|
||||
lda accu + 1
|
||||
adc #$00
|
||||
|
@ -4224,8 +4230,13 @@ avail:
|
|||
|
||||
clc
|
||||
lda tmp + 2
|
||||
#ifdef HEAPCHECK
|
||||
adc #7
|
||||
and #$f8
|
||||
#else
|
||||
adc #3
|
||||
and #$fc
|
||||
#endif
|
||||
sta tmp + 4
|
||||
lda tmp + 3
|
||||
adc #0
|
||||
|
@ -4285,11 +4296,38 @@ found:
|
|||
lda tmp + 3
|
||||
sta (accu), y
|
||||
|
||||
#ifdef HEAPCHECK
|
||||
|
||||
// add guard range to memory segment
|
||||
|
||||
ldy #2
|
||||
lda #$bd
|
||||
sta (accu), y
|
||||
iny
|
||||
sta (accu), y
|
||||
|
||||
sec
|
||||
lda tmp + 2
|
||||
sbc #2
|
||||
sta tmp + 2
|
||||
bcs hc1
|
||||
dec tmp + 3
|
||||
hc1:
|
||||
lda #$be
|
||||
ldy #0
|
||||
sta (tmp + 2), y
|
||||
iny
|
||||
sta (tmp + 2), y
|
||||
|
||||
lda accu
|
||||
ora #4
|
||||
sta accu
|
||||
#else
|
||||
// advanve by two bytes to skip size
|
||||
lda accu
|
||||
ora #2
|
||||
sta accu
|
||||
|
||||
#endif
|
||||
rts
|
||||
}
|
||||
|
||||
|
@ -4309,9 +4347,54 @@ __asm free
|
|||
// two bytes back to fix remembered end of block
|
||||
|
||||
lda accu
|
||||
#ifdef HEAPCHECK
|
||||
ora accu + 1
|
||||
bne hcnn
|
||||
rts
|
||||
hcnn:
|
||||
lda accu
|
||||
and #$07
|
||||
cmp #$04
|
||||
bne hfail
|
||||
lda accu
|
||||
and #$f8
|
||||
#else
|
||||
and #$fc
|
||||
#endif
|
||||
sta accu
|
||||
|
||||
#ifdef HEAPCHECK
|
||||
ldy #2
|
||||
lda (accu), y
|
||||
cmp #$bd
|
||||
bne hfail
|
||||
iny
|
||||
lda (accu), y
|
||||
cmp #$bd
|
||||
bne hfail
|
||||
|
||||
ldy #0
|
||||
sec
|
||||
lda (accu), y
|
||||
sbc #2
|
||||
sta tmp + 0
|
||||
iny
|
||||
lda (accu), y
|
||||
sbc #0
|
||||
sta tmp + 1
|
||||
|
||||
ldy #0
|
||||
lda (tmp), y
|
||||
cmp #$be
|
||||
bne hfail
|
||||
iny
|
||||
lda (tmp), y
|
||||
cmp #$be
|
||||
bne hfail
|
||||
|
||||
lda accu
|
||||
#endif
|
||||
|
||||
// check nullptr free
|
||||
|
||||
ora accu + 1
|
||||
|
@ -4336,7 +4419,12 @@ hchk1:
|
|||
bne hfail
|
||||
cpx #<HeapEnd
|
||||
bcs hfail
|
||||
hckh2:
|
||||
hchk2:
|
||||
ldy #2
|
||||
lda #$bf
|
||||
sta (accu), y
|
||||
iny
|
||||
sta (accu), y
|
||||
#endif
|
||||
// cache end of block, rounding to next four byte
|
||||
// address
|
||||
|
@ -4344,8 +4432,13 @@ hckh2:
|
|||
clc
|
||||
ldy #0
|
||||
lda (accu), y
|
||||
#ifdef HEAPCHECK
|
||||
adc #7
|
||||
and #$f8
|
||||
#else
|
||||
adc #3
|
||||
and #$fc
|
||||
#endif
|
||||
sta accu + 2
|
||||
iny
|
||||
lda (accu), y
|
||||
|
|
|
@ -118,6 +118,31 @@ public:
|
|||
list(void)
|
||||
{}
|
||||
|
||||
list(const list & l);
|
||||
|
||||
list(list && l)
|
||||
{
|
||||
head.succ = l.head.succ;
|
||||
head.pred = l.head.pred;
|
||||
head.succ->pred = head;
|
||||
head.pred->succ = head;
|
||||
l.head.succ = (listnode<T> *)&(l.head);
|
||||
l.head.pred = (listnode<T> *)&(l.head);
|
||||
}
|
||||
|
||||
list & operator=(const list & l);
|
||||
|
||||
list & operator=(list && l)
|
||||
{
|
||||
head.succ = l.head.succ;
|
||||
head.pred = l.head.pred;
|
||||
head.succ->pred = head;
|
||||
head.pred->succ = head;
|
||||
l.head.succ = (listnode<T> *)&(l.head);
|
||||
l.head.pred = (listnode<T> *)&(l.head);
|
||||
return *this;
|
||||
}
|
||||
|
||||
~list(void)
|
||||
{
|
||||
listnode<T> * n = head.succ;
|
||||
|
@ -175,11 +200,32 @@ public:
|
|||
|
||||
void push_back(T && t);
|
||||
|
||||
void clear(void);
|
||||
|
||||
void append(const list & l);
|
||||
|
||||
list_iterator<T> insert(list_iterator<T> it, const T & t);
|
||||
|
||||
list_iterator<T> insert(list_iterator<T> it, T && t);
|
||||
};
|
||||
|
||||
template <class T>
|
||||
list<T>::list(const list<T> & l)
|
||||
{
|
||||
append(l);
|
||||
}
|
||||
|
||||
template <class T>
|
||||
list<T> & list<T>::operator=(const list<T> & l)
|
||||
{
|
||||
if (&l != this)
|
||||
{
|
||||
clear();
|
||||
append(l);
|
||||
}
|
||||
return *this;
|
||||
}
|
||||
|
||||
template <class T>
|
||||
void list<T>::pop_front(void)
|
||||
{
|
||||
|
@ -293,6 +339,32 @@ list_iterator<T> list<T>::insert(list_iterator<T> it, T && t)
|
|||
return list_iterator<T>(n);
|
||||
}
|
||||
|
||||
|
||||
template <class T>
|
||||
void list<T>::clear(void)
|
||||
{
|
||||
listnode<T> * n = head.succ;
|
||||
while (n != &head)
|
||||
{
|
||||
listnode<T> * m = n->succ;
|
||||
delete n;
|
||||
n = m;
|
||||
}
|
||||
head.succ = (listnode<T> *)&head;
|
||||
head.pred = (listnode<T> *)&head;
|
||||
}
|
||||
|
||||
template <class T>
|
||||
void list<T>::append(const list<T> & l)
|
||||
{
|
||||
listnode<T> * n = l.head.succ;
|
||||
while (n != &(l.head))
|
||||
{
|
||||
push_back(n->data);
|
||||
n = n->succ;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
#endif
|
||||
|
|
|
@ -672,8 +672,8 @@ void Linker::Link(void)
|
|||
|
||||
if (lsec->mType == LST_HEAP)
|
||||
{
|
||||
lsec->mStart = (lrgn->mStart + lrgn->mUsed + 3) & ~3;
|
||||
lsec->mEnd = lrgn->mEnd & ~3;
|
||||
lsec->mStart = (lrgn->mStart + lrgn->mUsed + 7) & ~7;
|
||||
lsec->mEnd = lrgn->mEnd & ~7;
|
||||
|
||||
if (lsec->mStart + lsec->mSize > lsec->mEnd)
|
||||
{
|
||||
|
|
Loading…
Reference in New Issue