#include "Config.h"
#include <assert.h>
#include <dlfcn.h>
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include "Class.h"
#include "Object.h"
Go to the source code of this file.
◆ _alloc()
Instantiate a type through the given Class.
Definition at line 123 of file Class.c.
123 {
124
127
129
131 object->clazz = clazz;
132 object->referenceCount = 1;
133
134 ident interface = clazz->interface;
135 do {
138
140}
#define OBJECTIVELY_MAGIC
The header value identifying Objectively types.
void * ident
The identity type, similar to Objective-C id.
size_t instanceSize
The instance size (required).
ptrdiff_t interfaceOffset
The interface offset (required).
Class * superclass
The superclass (required). e.g. _Object().
ClassDef def
The Class definition.
Object is the root Class of The Objectively Class hierarchy.
unsigned int magic
A header to allow introspection of Object types.
◆ _cast()
Perform a type-checking cast.
Definition at line 142 of file Class.c.
142 {
143
146 while (c) {
147
148
149 if (c == clazz || clazz ==
_Object()) {
150 break;
151 }
152
154 }
155 assert(c);
156 }
157
159}
The runtime representation of a Class.
◆ _initialize()
Initializes the given Class.
- Parameters
-
| clazz | The Class descriptor. |
- Returns
- The initialized Class.
Definition at line 86 of file Class.c.
86 {
87
90
91 assert(def);
96
98 assert(clazz);
99
101
104
106 if (superclass) {
107
110
112 }
113
116 }
117
118 clazz->
next = __sync_lock_test_and_set(&
_classes, clazz);
119
120 return clazz;
121}
static void setup(void)
Called when initializing Object to setup Objectively.
#define do_once(once, block)
Executes the given block at most one time.
size_t interfaceSize
The interface size (required).
const char * name
The Class name (required).
void(* initialize)(Class *clazz)
The Class initializer (optional).
Class * next
Provides chaining of initialized Classes.
ident interface
The interface of the Class.
◆ classForName()
| Class * classForName |
( |
const char * |
name | ) |
|
- Returns
- The Class with the given name, or
NULL if no such Class has been initialized.
Definition at line 161 of file Class.c.
161 {
162
163 if (name) {
165 while (c) {
166 if (strcmp(name, c->
def.
name) == 0) {
167 return c;
168 }
170 }
171
172 char *s;
173 if (asprintf(&s, "_%s", name) > 0) {
175#if defined(_WIN32)
178 do_once(&once, { handle = dlopen(NULL, RTLD_LAZY); });
179 Class *(*archetype)(void) = handle ? dlsym(handle, s) : NULL;
180#else
181 Class *(*archetype)(void) = dlsym(RTLD_DEFAULT, s);
182#endif
183 if (archetype) {
184 clazz = archetype();
185 }
186
187 free(s);
188 return clazz;
189 }
190 }
191
192 return NULL;
193}
◆ release()
Atomically decrement the given Object's reference count. If the resulting reference count is 0, the Object is deallocated.
- Returns
- This function always returns
NULL.
Definition at line 195 of file Class.c.
195 {
196
199
200 assert(object);
201
202 if (__sync_add_and_fetch(&object->referenceCount, -1) == 0) {
204 }
205 }
206
207 return NULL;
208}
static void dealloc(Object *self)
#define cast(type, obj)
Safely cast obj to type.
◆ retain()
Atomically increment the given Object's reference count.
- Returns
- The Object.
Definition at line 210 of file Class.c.
210 {
211
213
214 assert(object);
215
216 __sync_add_and_fetch(&object->referenceCount, 1);
217
219}
◆ setup()
| static void setup |
( |
void |
| ) |
|
|
static |
Called when initializing Object to setup Objectively.
Definition at line 73 of file Class.c.
73 {
74
76
77#if !defined(_SC_PAGESIZE)
79#else
81#endif
82
84}
static void teardown(void)
Called atexit to teardown Objectively.
◆ teardown()
| static void teardown |
( |
void |
| ) |
|
|
static |
Called atexit to teardown Objectively.
Definition at line 46 of file Class.c.
46 {
48
50 while (c) {
53 }
54
56 }
57
59 while (c) {
60
62
64 free(c);
65
67 }
68}
static Unicode next(StringReader *self, StringReaderMode mode)
void(* destroy)(Class *clazz)
The Class destructor (optional). This method is run for initialized Classes when your application exi...
◆ _classes
◆ _pageSize