Changeset 256 in dev for trunk/abdev/BasicCompiler_Common/include/NativeCode.h
- Timestamp:
- Aug 1, 2007, 11:19:01 PM (17 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/abdev/BasicCompiler_Common/include/NativeCode.h
r253 r256 39 39 template<class Archive> void serialize(Archive& ar, const unsigned int version) 40 40 { 41 trace_for_serialize( "serializing - Schedule" ); 42 41 43 ar & BOOST_SERIALIZATION_NVP( type ); 42 44 ar & BOOST_SERIALIZATION_NVP( offset ); … … 94 96 template<class Archive> void load(Archive& ar, const unsigned int version) 95 97 { 98 trace_for_serialize( "serializing(load) - NativeCode" ); 99 96 100 std::string code; 97 101 ar & BOOST_SERIALIZATION_NVP( code ); … … 103 107 for( int i=0; i<size; i++ ) 104 108 { 105 char c;106 sscanf( code.c_str() + i*3, "%02x,", & c);107 codeBuffer[i] = c;109 ULONG_PTR l; 110 sscanf( code.c_str() + i*3, "%02x,", &l ); 111 codeBuffer[i] = (char)l; 108 112 } 109 113 } 110 114 template<class Archive> void save(Archive& ar, const unsigned int version) const 111 115 { 116 trace_for_serialize( "serializing(save) - NativeCode" ); 117 112 118 // 保存準備 113 char *tempCode = (char *) malloc( (size+1) * 3);119 char *tempCode = (char *)calloc( (size+1) * 3, 1 ); 114 120 for( int i=0; i<size; i++ ) 115 121 { 116 122 char temp[32]; 117 sprintf( temp, "%02x,", codeBuffer[i] );123 sprintf( temp, "%02x,", (unsigned char)codeBuffer[i] ); 118 124 tempCode[i*3] = temp[0]; 119 125 tempCode[i*3+1] = temp[1]; … … 130 136 131 137 132 void Realloc( int additionSize = 0)133 { 134 if( allocateSize < size + 8192 + additionSize)135 { 136 while( allocateSize < size + 8192 + additionSize)138 void Realloc( int newSize ) 139 { 140 if( allocateSize < newSize + 8192 ) 141 { 142 while( allocateSize < newSize + 8192 ) 137 143 { 138 144 allocateSize += 8192; … … 149 155 { 150 156 } 157 NativeCode( const NativeCode &nativeCode ) 158 : allocateSize( 8192 ) 159 , codeBuffer( (char *)malloc( allocateSize ) ) 160 , size( 0 ) 161 { 162 Put( nativeCode ); 163 } 151 164 NativeCode( const char *codeBuffer, int size ) 152 165 : allocateSize( 8192 ) … … 165 178 } 166 179 180 void operator =( const NativeCode &nativeCode ) 181 { 182 Clear(); 183 Put( nativeCode ); 184 } 185 167 186 int GetSize() const 168 187 { … … 203 222 void Put( const char *codeBuffer, int size ) 204 223 { 205 Realloc( size );224 Realloc( this->size + size ); 206 225 207 226 memcpy( this->codeBuffer + this->size, codeBuffer, size ); … … 268 287 void Put( char c ) 269 288 { 289 Realloc( size + 1 ); 270 290 codeBuffer[size++] = c; 271 Realloc();272 291 273 292
Note:
See TracChangeset
for help on using the changeset viewer.