Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitc1d2301

Browse files
Implement binary representation of PATH and add tests for it
1 parent35d24ca commitc1d2301

File tree

2 files changed

+13
-10
lines changed

2 files changed

+13
-10
lines changed

‎blobstamper/helpers.h

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -95,24 +95,28 @@ template<class T, class ArrayT> class VLATO_ptr
9595
private:
9696
T* _ptr{nullptr};
9797
size_t _length;
98+
size_t _offset;
9899
public:
99100

100101
operator T*()const {return _ptr;};
101102
operator sized_ptr<T>() {sized_ptr<T>res(_ptr,size()); _ptr=NULL;return res;};
102103

103104
size_tlength() {return _length;};
104-
size_tsize() {returnsizeof(T) + _length *sizeof(ArrayT);};
105-
VLATO_ptr(size_t length);
106-
VLATO_ptr(T* ptr,size_t length): _ptr{ptr}, _length{length} {};
105+
size_toffset() {return _offset;};
106+
size_tsize() {return _offset + _length *sizeof(ArrayT);};
107+
108+
VLATO_ptr(size_t offsrt,size_t length);
109+
VLATO_ptr(T* ptr,size_t offset,size_t length): _ptr{ptr}, _offset{offset}, _length{length} {};
107110
~VLATO_ptr() {if (_ptr)free(_ptr);}
108111
};
109112

110113

111114
template<classT,classArrayT>
112-
VLATO_ptr<T,ArrayT>::VLATO_ptr(size_t length)
115+
VLATO_ptr<T,ArrayT>::VLATO_ptr(size_toffset,size_tlength)
113116
{
114-
_ptr = (T*)malloc(sizeof(T) +sizeof(ArrayT) * length);
117+
_ptr = (T*)malloc( offset +sizeof(ArrayT) * length);
115118
_length = length;
119+
_offset = offset;
116120
}
117121

118122

‎t/050-sized_prt_and_vsato_ptr.cpp

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ typedef struct
2727

2828

2929
intmain() {
30-
TEST_START(10);
30+
TEST_START(9);
3131

3232
// #tests for sized_ptr
3333
{/* 1..3*/
@@ -45,17 +45,16 @@ int main() {
4545
// free(l); /*Do not need to free it. sized_ptr will do it for you*/
4646
}
4747
{/* 4..10*/
48-
is(sizeof(FixedLengthObject),sizeof(VariableLengthObject),"sizes sainity check VLATO_prt expects this to be true");
49-
VLATO_ptr<VariableLengthObject,shortint>vp(5);
48+
VLATO_ptr<VariableLengthObject,shortint>vp(offsetof(VariableLengthObject,arr),5);
5049
is(vp.length(),5,"Number of elements is ok");
51-
is(vp.size(),sizeof(VariableLengthObject) +sizeof(shortint) *5,"Size of object is ok");
50+
is(vp.size(),offsetof(VariableLengthObject,arr) +sizeof(shortint) *5,"Size of object is ok");
5251
VariableLengthObject *p1 = vp;
5352
p1->arr[4]=100;
5453

5554
sized_ptr<VariableLengthObject> sp = vp;// from now on vp does not exit
5655
VariableLengthObject *p2 = vp;
5756
ok(!p2,"now vp should not point anywere");
58-
is(sp.size(),sizeof(VariableLengthObject) +sizeof(shortint) *5,"Size of sized object is ok");
57+
is(sp.size(),offsetof(VariableLengthObject,arr) +sizeof(shortint) *5,"Size of sized object is ok");
5958

6059
VariableLengthObject *p3 = sp;
6160
ok(p1 == p3,"Still same object");

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp