diff options
author | josh.macdonald <jmacd@users.noreply.github.com> | 2007-01-28 20:09:48 +0000 |
---|---|---|
committer | josh.macdonald <jmacd@users.noreply.github.com> | 2007-01-28 20:09:48 +0000 |
commit | 19ab311b65d55c748672a5d1d914f2af83c27956 (patch) | |
tree | ab19a7f621dfd60356b30555b8e6850f93f99496 /xdelta1/libedsio/default.c | |
parent | f33c5dde63152070c53add0e664b9a70530ddac9 (diff) |
Fixes the source-allocation problem, should resolve 64bit platform
issues.
Diffstat (limited to 'xdelta1/libedsio/default.c')
-rwxr-xr-x | xdelta1/libedsio/default.c | 65 |
1 files changed, 15 insertions, 50 deletions
diff --git a/xdelta1/libedsio/default.c b/xdelta1/libedsio/default.c index 8c9f347..0da2176 100755 --- a/xdelta1/libedsio/default.c +++ b/xdelta1/libedsio/default.c | |||
@@ -18,6 +18,7 @@ sink_type_default (SerialSink* sink, SerialType type, guint32 len, gboolean set_ | |||
18 | if (! sink->next_uint32 (sink, type)) | 18 | if (! sink->next_uint32 (sink, type)) |
19 | return FALSE; | 19 | return FALSE; |
20 | 20 | ||
21 | /* Note: set_allocation is deprecated in 1.1.4 */ | ||
21 | if (set_allocation && !sink->next_uint32 (sink, len)) | 22 | if (set_allocation && !sink->next_uint32 (sink, len)) |
22 | return FALSE; | 23 | return FALSE; |
23 | 24 | ||
@@ -146,7 +147,9 @@ source_type_default (SerialSource* source, gboolean set_allocation) | |||
146 | 147 | ||
147 | if (set_allocation) | 148 | if (set_allocation) |
148 | { | 149 | { |
149 | if (! source->next_uint32 (source, &source->alloc_total)) | 150 | /* Note: set_allocation is deprecated in 1.1.4 */ |
151 | guint32 bogus; | ||
152 | if (! source->next_uint32 (source, &bogus)) | ||
150 | return ST_Error; | 153 | return ST_Error; |
151 | } | 154 | } |
152 | 155 | ||
@@ -283,66 +286,27 @@ source_next_bytes_known (SerialSource* source, guint8 *ptr, guint32 len) | |||
283 | void* | 286 | void* |
284 | serializeio_source_alloc (SerialSource* source, guint32 len) | 287 | serializeio_source_alloc (SerialSource* source, guint32 len) |
285 | { | 288 | { |
289 | AllocList *al; | ||
286 | void* ret; | 290 | void* ret; |
287 | 291 | ||
288 | if (! source->alloc_buf) | 292 | if (source->salloc_func) |
289 | { | 293 | { |
290 | if (source->salloc_func) | 294 | ret = source->salloc_func (source, len); |
291 | source->alloc_buf_orig = source->salloc_func (source, source->alloc_total + 8); | 295 | al = source->salloc_func (source, sizeof(AllocList)); |
292 | else | ||
293 | source->alloc_buf_orig = g_malloc0 (source->alloc_total + 8); | ||
294 | |||
295 | source->alloc_buf = source->alloc_buf_orig; | ||
296 | |||
297 | { long x = source->alloc_buf; ALIGN_8 (x); source->alloc_buf = x; } | ||
298 | |||
299 | } | 296 | } |
300 | 297 | else | |
301 | if (len+source->alloc_pos > source->alloc_total) | ||
302 | { | 298 | { |
303 | edsio_generate_source_event (EC_EdsioIncorrectAllocation, source); | 299 | ret = g_malloc0 (len); |
304 | return NULL; | 300 | al = g_malloc0 (sizeof(AllocList)); |
305 | } | 301 | } |
306 | 302 | ||
307 | ret = ((guint8*)source->alloc_buf) + source->alloc_pos; | 303 | al->ptr = ret; |
308 | 304 | al->next = source->alloc_list; | |
309 | source->alloc_pos += len; | 305 | source->alloc_list = al; |
310 | |||
311 | ALIGN_8 (source->alloc_pos); | ||
312 | |||
313 | g_assert (((long)ret) % 8 == 0); | ||
314 | g_assert (source->alloc_pos % 8 == 0); | ||
315 | 306 | ||
316 | return ret; | 307 | return ret; |
317 | } | 308 | } |
318 | 309 | ||
319 | gboolean | ||
320 | serializeio_source_object_received (SerialSource* source) | ||
321 | { | ||
322 | source->alloc_pos = 0; | ||
323 | source->alloc_total = 0; | ||
324 | source->alloc_buf_orig = NULL; | ||
325 | source->alloc_buf = NULL; | ||
326 | |||
327 | return TRUE; | ||
328 | } | ||
329 | |||
330 | void | ||
331 | serializeio_source_reset_allocation (SerialSource* source) | ||
332 | { | ||
333 | source->alloc_pos = 0; | ||
334 | source->alloc_total = 0; | ||
335 | source->alloc_buf = NULL; | ||
336 | |||
337 | if (source->alloc_buf_orig) | ||
338 | { | ||
339 | if (source->sfree_func) | ||
340 | source->sfree_func (source, source->alloc_buf_orig); | ||
341 | else | ||
342 | g_free (source->alloc_buf_orig); | ||
343 | } | ||
344 | } | ||
345 | |||
346 | void | 310 | void |
347 | serializeio_source_init (SerialSource* it, | 311 | serializeio_source_init (SerialSource* it, |
348 | SerialType (* source_type) (SerialSource* source, | 312 | SerialType (* source_type) (SerialSource* source, |
@@ -357,6 +321,7 @@ serializeio_source_init (SerialSource* it, | |||
357 | void (* sfree_func) (SerialSource* source, | 321 | void (* sfree_func) (SerialSource* source, |
358 | void* ptr)) | 322 | void* ptr)) |
359 | { | 323 | { |
324 | it->alloc_list = NULL; | ||
360 | it->next_bytes_known = source_next_bytes_known; | 325 | it->next_bytes_known = source_next_bytes_known; |
361 | it->next_bytes = source_next_bytes; | 326 | it->next_bytes = source_next_bytes; |
362 | it->next_uint = source_next_uint; | 327 | it->next_uint = source_next_uint; |