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#pragma clang diagnostic push
15#pragma clang diagnostic ignored "-Wprotocol"
16#pragma clang diagnostic ignored "-Wincomplete-implementation"
17@interface OC_TestProtocolClass : NSObject <OC_TestProtocol>
18{}
19@end
20
21@implementation OC_TestProtocolClass
22@end
23#pragma clang diagnostic pop
24
25static PyMethodDef mod_methods[] = {
26	{ 0, 0, 0, 0 }
27};
28
29#if PY_VERSION_HEX >= 0x03000000
30
31static struct PyModuleDef mod_module = {
32	PyModuleDef_HEAD_INIT,
33	"protocols",
34	NULL,
35	0,
36	mod_methods,
37	NULL,
38	NULL,
39	NULL,
40	NULL
41};
42
43#define INITERROR() return NULL
44#define INITDONE() return m
45
46PyObject* PyInit_protocol(void);
47
48PyObject*
49PyInit_protocol(void)
50
51#else
52
53#define INITERROR() return
54#define INITDONE() return
55
56void initprotocol(void);
57
58void
59initprotocol(void)
60#endif
61{
62	PyObject* m;
63	Protocol* p;
64
65
66#if PY_VERSION_HEX >= 0x03000000
67	m = PyModule_Create(&mod_module);
68#else
69	m = Py_InitModule4("protocol", mod_methods,
70		NULL, NULL, PYTHON_API_VERSION);
71#endif
72	if (!m) {
73		INITERROR();
74	}
75	if (PyObjC_ImportAPI(m) < 0) {
76		INITERROR();
77	}
78
79	p = @protocol(OC_TestProtocol);
80	PyObject* prot = PyObjC_ObjCToPython("@", &p);
81	if (!prot) {
82		INITERROR();
83	}
84	if (PyModule_AddObject(m, "OC_TestProtocol", prot) < 0) {
85		INITERROR();
86	}
87
88	INITDONE();
89}
90