ObjFW  Diff

Differences From Artifact [64f7431604]:

To Artifact [77311e8f90]:


15
16
17
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
48
49
50
51
52
53
54
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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
 * file.
 */

#include "config.h"

#import "OFObject.h"

static SEL constructSel = NULL;
static SEL destructSel = NULL;

static bool
callConstructors(Class cls, id obj)
{
	Class super = class_getSuperclass(cls);
	id (*construct)(id, SEL);
	id (*last)(id, SEL);

	if (super != nil)
		if (!callConstructors(super, obj))
			return false;

	if (constructSel == NULL)
		constructSel = sel_registerName(".cxx_construct");

	if (!class_respondsToSelector(cls, constructSel))
		return true;

	construct = (id (*)(id, SEL))
	    class_getMethodImplementation(cls, constructSel);
	last = (id (*)(id, SEL))
	    class_getMethodImplementation(super, constructSel);

	if (construct == last)
		return true;

	return (construct(obj, constructSel) != nil);
}

id
objc_constructInstance(Class cls, void *bytes)
{
	id obj = (id)bytes;

	if (cls == Nil || bytes == NULL)
		return nil;

	object_setClass(obj, cls);

	if (!callConstructors(cls, obj))
		return nil;

	return obj;
}

void *
objc_destructInstance(id obj)
{
	Class cls;
	void (*last)(id, SEL) = NULL;

	if (obj == nil)
		return NULL;

#ifdef OF_OBJFW_RUNTIME
	objc_zero_weak_references(obj);
#endif

	if (destructSel == NULL)
		destructSel = sel_registerName(".cxx_destruct");

	for (cls = object_getClass(obj); cls != Nil;
	    cls = class_getSuperclass(cls)) {
		void (*destruct)(id, SEL);

		if (class_respondsToSelector(cls, destructSel)) {
			if ((destruct = (void (*)(id, SEL))
			    class_getMethodImplementation(cls,
			    destructSel)) != last)
				destruct(obj, destructSel);

			last = destruct;
		} else
			break;
	}

	return obj;
}







|
|


|

|




|


|
|

|



|

|




|



|

|

|


|

|


|



|

|


|



|


|
|

|
|


|

|
|
|






|

15
16
17
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
48
49
50
51
52
53
54
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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
 * file.
 */

#include "config.h"

#import "OFObject.h"

static SEL constructSelector = NULL;
static SEL destructSelector = NULL;

static bool
callConstructors(Class class, id object)
{
	Class super = class_getSuperclass(class);
	id (*construct)(id, SEL);
	id (*last)(id, SEL);

	if (super != nil)
		if (!callConstructors(super, object))
			return false;

	if (constructSelector == NULL)
		constructSelector = sel_registerName(".cxx_construct");

	if (!class_respondsToSelector(class, constructSelector))
		return true;

	construct = (id (*)(id, SEL))
	    class_getMethodImplementation(class, constructSelector);
	last = (id (*)(id, SEL))
	    class_getMethodImplementation(super, constructSelector);

	if (construct == last)
		return true;

	return (construct(object, constructSelector) != nil);
}

id
objc_constructInstance(Class class, void *bytes)
{
	id object = (id)bytes;

	if (class == Nil || bytes == NULL)
		return nil;

	object_setClass(object, class);

	if (!callConstructors(class, object))
		return nil;

	return object;
}

void *
objc_destructInstance(id object)
{
	Class class;
	void (*last)(id, SEL) = NULL;

	if (object == nil)
		return NULL;

#ifdef OF_OBJFW_RUNTIME
	objc_zero_weak_references(object);
#endif

	if (destructSelector == NULL)
		destructSelector = sel_registerName(".cxx_destruct");

	for (class = object_getClass(object); class != Nil;
	    class = class_getSuperclass(class)) {
		void (*destruct)(id, SEL);

		if (class_respondsToSelector(class, destructSelector)) {
			if ((destruct = (void (*)(id, SEL))
			    class_getMethodImplementation(class,
			    destructSelector)) != last)
				destruct(object, destructSelector);

			last = destruct;
		} else
			break;
	}

	return object;
}