1/*
2 * This module is used in the unittests for object identity.
3 */
4#include "Python.h"
5#include "pyobjc-api.h"
6
7#import <Foundation/Foundation.h>
8
9@protocol OC_TestProtocol
10-(int)method1;
11-(void)method2:(int)v;
12@end
13
14@interface OC_TestProtocolClass : NSObject <OC_TestProtocol>
15{}
16@end
17
18@implementation OC_TestProtocolClass
19@end
20
21static PyMethodDef mod_methods[] = {
22	{ 0, 0, 0, 0 }
23};
24
25#if PY_VERSION_HEX >= 0x03000000
26
27static struct PyModuleDef mod_module = {
28	PyModuleDef_HEAD_INIT,
29	"protocols",
30	NULL,
31	0,
32	mod_methods,
33	NULL,
34	NULL,
35	NULL,
36	NULL
37};
38
39#define INITERROR() return NULL
40#define INITDONE() return m
41
42PyObject* PyInit_protocol(void);
43
44PyObject*
45PyInit_protocol(void)
46
47#else
48
49#define INITERROR() return
50#define INITDONE() return
51
52void initprotocol(void);
53
54void
55initprotocol(void)
56#endif
57{
58	PyObject* m;
59	Protocol* p;
60
61
62#if PY_VERSION_HEX >= 0x03000000
63	m = PyModule_Create(&mod_module);
64#else
65	m = Py_InitModule4("protocol", mod_methods,
66		NULL, NULL, PYTHON_API_VERSION);
67#endif
68	if (!m) {
69		INITERROR();
70	}
71	if (PyObjC_ImportAPI(m) < 0) {
72		INITERROR();
73	}
74
75	p = @protocol(OC_TestProtocol);
76	PyObject* prot = PyObjC_ObjCToPython("@", &p);
77	if (!prot) {
78		INITERROR();
79	}
80	if (PyModule_AddObject(m, "OC_TestProtocol", prot) < 0) {
81		INITERROR();
82	}
83
84	INITDONE();
85}
86