summaryrefslogtreecommitdiff
path: root/Objective-C/libobjcl.h
blob: 35d6150bcf07ad7a9f967182a76c779b231a961a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
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
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
/* -*- mode: objc; coding: utf-8 -*- */
/* Objective-CL, an Objective-C bridge for Common Lisp.
 * Copyright (C) 2007  Matthias Andreas Benkard.
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Lesser General Public License as
 * published by the Free Software Foundation, either version 3 of the
 * License, or (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful, but
 * WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this program.  If not, see
 * <http://www.gnu.org/licenses/>.
 */

#import "Foundation/Foundation.h"
#include <objc/objc-api.h>

#include "../config.h"

#import "PyObjC/pyobjc.h"
#import "PyObjC/objc_support.h"
#import "PyObjC/objc-runtime-compat.h"

#ifdef USE_LIBFFI
#ifdef HAVE_FFI_H
#include <ffi.h>
#elif HAVE_FFI_FFI_H
#include <ffi/ffi.h>
#else
/* We are using our own build of libffi. */
#include <ffi.h>
#endif
#endif

#ifdef __NEXT_RUNTIME__
typedef Ivar IVAR_T;
#else
typedef struct objc_ivar *IVAR_T;
#endif

#ifdef HAVE_SYS_SEM_H
#include <sys/sem.h>
#ifndef __APPLE__
/* According to the Single Unix Specification, Version 3, the semun
   union type must be defined by the application writer as follows: */
union semun
{
  int              val;    /* Value for SETVAL */
  struct semid_ds *buf;    /* Buffer for IPC_STAT, IPC_SET */
  unsigned short  *array;  /* Array for GETALL, SETALL */
};
#endif
#endif

extern NSException *objcl_oom_exception;
extern id objcl_current_exception;
extern void *objcl_current_exception_lock;


void
objcl_initialise_runtime (void);

void
objcl_shutdown_runtime (void);

id
objcl_invoke_with_types (int argc,
                         Class superclass_for_send_super,
                         char *return_typespec,
                         char *arg_typespecs[],
                         void *return_value,
                         void **argv);

Class
objcl_find_class (const char *class_name);

Class
objcl_find_meta_class (const char *class_name);

SEL
objcl_find_selector (const char *selector_name);

SEL
objcl_intern_selector (const char *selector_name);

/* Return a null-terminated list of type information strings.
   The first entry describes the type of the method's return value. */
char **
objcl_query_arglist_info (void *receiver,
                          const char *method_name);


const char *
objcl_class_name (Class class);

Class
objcl_class_superclass (Class class);

const char *
objcl_selector_name (SEL selector);

IMP
objcl_get_method_implementation (id object,
                                 SEL selector,
                                 Class superclass_for_send_super);

BOOL
objcl_object_is_class (id obj);

BOOL
objcl_object_is_meta_class (id obj);

Class
objcl_object_get_class (id obj);

Class
objcl_object_get_meta_class (id obj);

id
objcl_get_nil (void);

/* In principle, we do not know whether a BOOL fits into a long.  In
   practise, it is very likely. */
long
objcl_get_yes (void);

long
objcl_get_no (void);

const char *
objcl_get_runtime_type (void);

int
objcl_objc2_p (void);

long
objcl_sizeof_type (const char *typespec);

long
objcl_sizeof_return_type (const char *typespec);

long
objcl_alignof_type (const char *typespec);

void
objcl_set_slot_value (id obj, const char *ivar_name, void *value);

void *
objcl_slot_value (id obj, const char *ivar_name);

/* The following function returns a freshly consed array that the caller
   must deallocate. */
IVAR_T *
objcl_class_direct_slots (Class class,
                          unsigned int *count,
                          unsigned int *element_size);

const char *
objcl_slot_name (IVAR_T ivar);

const char *
objcl_slot_type (IVAR_T ivar);

IMP
objcl_create_imp (IMP callback,
                  int argc,
                  const char *return_typespec,
                  const char *arg_typespecs[]);

void
objcl_acquire_lock (void *lock);

void
objcl_release_lock (void *lock);

void
objcl_initialise_lock (void **lock);

Class
objcl_create_class (const char *class_name,
                    Class superclass,
                    int protocol_number,
                    const char *protocol_names[],
                    int ivar_number,
                    const char *ivar_names[],
                    const char *ivar_typespecs[]);

void
objcl_add_method (Class class,
                  SEL method_name,
                  IMP callback,
                  int argc,
                  const char *return_typespec,
                  const char *arg_typespecs[],
                  const char *signature);

void
objcl_finalise_class (Class class);