1#ifndef PyObjC_METHODSIGNATURE_H
2#define PyObjC_METHODSIGNATURE_H
3/*!
4 * @header    method-signature.h
5 * @abstract  A subset of NSMethodSignature, in C
6 * @discussion
7 * 	This module defines a C implementation of a subset of NSMethodSignature,
8 * 	specifically the part of NSMethodSignature that is usefull for the
9 * 	bridge.
10 *
11 *	Implemented because NSMethodSignature has a private constructor and
12 *	because this interface is easier to use.
13 *
14 *	TODO: Check if we don't use NSMethodSignatures where we should use
15 *	this type.
16 */
17#include "pyobjc.h"
18
19extern PyTypeObject PyObjCMethodSignature_Type;
20#define PyObjCMethodSignature_Check(obj) PyObject_TypeCheck(obj, &PyObjCMethodSignature_Type)
21
22enum _PyObjC_PointerType {
23	PyObjC_kPointerPlain = 0,
24	PyObjC_kNullTerminatedArray = 1,
25	PyObjC_kArrayCountInArg = 2,
26	PyObjC_kFixedLengthArray = 3,
27	PyObjC_kVariableLengthArray = 4,
28};
29
30typedef struct _PyObjCMethodSignature PyObjCMethodSignature;
31
32struct _PyObjC_ArgDescr {
33	/* If typeOverride the type field should be freed when the descriptor
34	 * is cleaned up, otherwise is isn't owned by this descriptor.
35	 */
36	const char*     type;
37	PyObjCMethodSignature* callable;
38
39	enum _PyObjC_PointerType        ptrType;
40	int16_t         arrayArg;
41	int16_t         arrayArgOut;
42	const char*	sel_type;
43	BOOL            allowNULL:1;
44	BOOL            typeOverride:1;
45	BOOL		arraySizeInRetval:1;
46	BOOL		printfFormat:1;
47	BOOL 		alreadyRetained:1;
48	BOOL 		alreadyCFRetained:1;
49	BOOL		callableRetained:1; /* False iff the closure can be cleaned up after the call */
50};
51
52struct _PyObjCMethodSignature {
53	PyObject_VAR_HEAD
54
55	const char* signature;
56	int  arrayArg;
57	BOOL variadic:1;
58	BOOL null_terminated_array:1;
59	BOOL		free_result:1;
60	PyObject*   suggestion;
61	struct _PyObjC_ArgDescr rettype;
62	struct _PyObjC_ArgDescr argtype[1];
63};
64
65
66extern PyObjCMethodSignature* PyObjCMethodSignature_WithMetaData(const char* signature, PyObject* metadata, BOOL is_native);
67
68extern PyObjCMethodSignature* PyObjCMethodSignature_ForSelector(
69	Class cls, BOOL isClassMethod, SEL sel, const char* signature, BOOL is_native);
70
71
72
73extern char*
74PyObjC_NSMethodSignatureToTypeString(
75	NSMethodSignature* sig, char* buf, size_t buflen);
76
77extern int
78PyObjC_registerMetaData(PyObject*, PyObject*, PyObject*);
79
80extern PyObject*
81PyObjCMethodSignature_AsDict(PyObjCMethodSignature* methinfo);
82
83static inline PyObjCMethodSignature* PyObjCMethodSignature_FromSignature(
84		const char* sig, BOOL is_native)
85{
86	return PyObjCMethodSignature_WithMetaData(sig, NULL, is_native);
87}
88
89#endif /* PyObjC_METHODSIGNATURE_H */
90