|
Objectively
Object oriented framework for C.
|
#include "Config.h"#include <assert.h>#include <dlfcn.h>#include <stdlib.h>#include <stdio.h>#include <string.h>#include <link.h>#include "Class.h"#include "Object.h"Go to the source code of this file.
Macros | |
| #define | MAX_CLASS_IMAGES 8 |
| The registered images providing Classes. | |
Functions | |
| ident | _alloc (Class *clazz) |
| Instantiate a type through the given Class. | |
| ident | _cast (const Class *clazz, const ident obj) |
| Perform a type-checking cast. | |
| Class * | _initialize (const ClassDef *def) |
| Initializes the given Class. | |
| void | addClassImage (ident handle) |
| Registers an image that provides Classes, e.g. a plugin. | |
| Class * | classForName (const char *name) |
| static const ident | imageForAddress (const ident address) |
| static ident | imageForHandle (ident handle) |
| ident | release (ident obj) |
Atomically decrement the given Object's reference count. If the resulting reference count is 0, the Object is deallocated. | |
| void | removeClassImage (ident handle) |
| Unregisters an image, and every Class it declared. | |
| ident | retain (ident obj) |
| Atomically increment the given Object's reference count. | |
| static void | setup (void) |
Called when initializing Object to setup Objectively. | |
| static void | teardown (void) |
Called atexit to teardown Objectively. | |
Variables | |
| static Class * | _classes |
| static size_t | _classImageCount |
| static ident | _classImages [MAX_CLASS_IMAGES] |
| size_t | _pageSize |
| #define MAX_CLASS_IMAGES 8 |
The registered images providing Classes.
_initialize. Images are added and removed as they are loaded and closed, not per lookup. Instantiate a type through the given Class.
Definition at line 170 of file Class.c.
Initializes the given Class.
| clazz | The Class descriptor. |
Definition at line 129 of file Class.c.
| void addClassImage | ( | ident | handle | ) |
Registers an image that provides Classes, e.g. a plugin.
| handle | A handle from dlopen. |
classForName resolves a name it has not yet initialized through the process-wide namespace, which holds only images loaded RTLD_GLOBAL, and which Windows does not have at all. An application that loads Classes from a plugin registers it here instead, and may then load it RTLD_LOCAL - which is how it keeps two plugins exporting the same symbols from coalescing.
Definition at line 284 of file Class.c.
| Class * classForName | ( | const char * | name | ) |
Definition at line 292 of file Class.c.
address, or NULL. dladdr. UNCHANGED_REFCOUNT matters: without it this would pin the very module the caller is about to release. Definition at line 109 of file Class.c.
handle, or NULL. GetModuleFileName confirms rather than assumes; glibc answers from the link map; and macOS, which has neither, is left with matching the handle against the loaded images. Definition at line 215 of file Class.c.
Atomically decrement the given Object's reference count. If the resulting reference count is 0, the Object is deallocated.
NULL. Definition at line 335 of file Class.c.
| void removeClassImage | ( | ident | handle | ) |
Unregisters an image, and every Class it declared.
| handle | The handle given to addClassImage. |
classForName answers from that cache ahead of any image. On a platform where closing an image really unmaps it - which dlclose does on Linux and FreeLibrary does on Windows - the next lookup would then read a ClassDef that is no longer mapped. classForName compares the name of every Class it walks, so one left behind breaks every lookup, not only its own. dlclose does not unmap on macOS, so an archetype that has already run keeps answering from its own static Class * for as long as the process lives, and would hand back whatever this freed. Unregistering is the only thing that is safe whether the image goes away or stays: the Class becomes unreachable by name, and remains valid for the archetype that owns it. The cost is the Class and its interface, which are not reclaimed.
|
static |
|
static |
Called atexit to teardown Objectively.
Definition at line 64 of file Class.c.
|
static |