ObjFW  Diff

Differences From Artifact [deca1fe096]:

To Artifact [c1de4ea884]:

  • File src/OFObject.m — part of check-in [b597d49f43] at 2008-10-08 23:15:26 on branch trunk — Multiple changes, see details.

    * OFObject getMem: renamd to getMemWithSize:.
    * OFString compare: renamed to compareTo:.
    * Exceptions don't throw itself anymore.
    * Exceptions include an error string now.
    * Exceptions now got raise and string.
    * New methods for OFFile:
    * changeModeOfFile:toMode:
    * changeOwnerOfFile:toOwner:andGroup:
    * delete:
    * link:to:
    * symlink:to:
    * OFFile isEndOfFile renamd to atEndOfFile
    * OFNotImplementedExeception newWithObject:andMethod renamed to
    newWithObject:andSelector:.
    * Tests updated accordingly.
    * TODO list added. (user: js, size: 2189) [annotate] [blame] [check-ins using]


18
19
20
21
22
23
24
25
26
27
28
29
30
31
32

33
34
35
36
37
38
39
40
41
42
43
44
45
46
- init
{
	if ((self = [super init]) != nil)
		__mem_pool  = NULL;
	return self;
}

- (void*)getMem: (size_t)size
{
	struct __ofobject_allocated_mem *iter;

	if ((iter = malloc(sizeof(struct __ofobject_allocated_mem))) == NULL) {
		[OFNoMemException newWithObject: self
					andSize: sizeof(struct
						     __ofobject_allocated_mem)];

		return NULL;
	}

	if ((iter->ptr = malloc(size)) == NULL) {
		free(iter);
		[OFNoMemException newWithObject: self
					andSize: size];
		return NULL;
	}

	iter->next = NULL;
	iter->prev = __mem_pool;

	if (__mem_pool != NULL)







|




|

|
>





|
|







18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
- init
{
	if ((self = [super init]) != nil)
		__mem_pool  = NULL;
	return self;
}

- (void*)getMemWithSize: (size_t)size
{
	struct __ofobject_allocated_mem *iter;

	if ((iter = malloc(sizeof(struct __ofobject_allocated_mem))) == NULL) {
		[[OFNoMemException newWithObject: self
					andSize: sizeof(struct
						     __ofobject_allocated_mem)
		    ] raise];
		return NULL;
	}

	if ((iter->ptr = malloc(size)) == NULL) {
		free(iter);
		[[OFNoMemException newWithObject: self
					andSize: size] raise];
		return NULL;
	}

	iter->next = NULL;
	iter->prev = __mem_pool;

	if (__mem_pool != NULL)
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
	    toSize: (size_t)size
{
	struct __ofobject_allocated_mem *iter;

	for (iter = __mem_pool; iter != NULL; iter = iter->prev) {
		if (iter->ptr == ptr) {
			if ((ptr = realloc(iter->ptr, size)) == NULL) {
				[OFNoMemException newWithObject: self
							andSize: size];
				return NULL;
			}
			
			iter->ptr = ptr;
			return ptr;
		}
	}

	[OFMemNotPartOfObjException newWithObject: self
				       andPointer: ptr];
	return NULL;
}

- (void)freeMem: (void*)ptr;
{
	struct __ofobject_allocated_mem *iter;








|
|








|
|







56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
	    toSize: (size_t)size
{
	struct __ofobject_allocated_mem *iter;

	for (iter = __mem_pool; iter != NULL; iter = iter->prev) {
		if (iter->ptr == ptr) {
			if ((ptr = realloc(iter->ptr, size)) == NULL) {
				[[OFNoMemException newWithObject: self
							 andSize: size] raise];
				return NULL;
			}
			
			iter->ptr = ptr;
			return ptr;
		}
	}

	[[OFMemNotPartOfObjException newWithObject: self
					andPointer: ptr] raise];
	return NULL;
}

- (void)freeMem: (void*)ptr;
{
	struct __ofobject_allocated_mem *iter;

90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
			free(iter);
			free(ptr);

			return;
		}
	}

	[OFMemNotPartOfObjException newWithObject: self
				       andPointer: ptr];
}

- free
{
	struct __ofobject_allocated_mem *iter, *iter2;

	for (iter = __mem_pool; iter != NULL; iter = iter2) {







|
|







91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
			free(iter);
			free(ptr);

			return;
		}
	}

	[[OFMemNotPartOfObjException newWithObject: self
					andPointer: ptr] raise];
}

- free
{
	struct __ofobject_allocated_mem *iter, *iter2;

	for (iter = __mem_pool; iter != NULL; iter = iter2) {