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@interface ClassWithVariables : NSObject
10{
11	int	intValue;
12	double	floatValue;
13	char	charValue;
14	char*	strValue;
15	NSRect  rectValue;
16	NSObject* nilValue;
17	PyObject* pyValue;
18	NSObject* objValue;
19}
20-(instancetype)init;
21-(void)dealloc;
22@end
23
24@implementation ClassWithVariables
25-(instancetype)init
26{
27	self = [super init];
28	if (self == nil) return nil;
29
30	intValue = 42;
31	floatValue = -10.055;
32	charValue = 'a';
33	strValue = "hello world";
34	rectValue = NSMakeRect(1,2,3,4);
35	nilValue = nil;
36	pyValue = PySlice_New(
37			PyLong_FromLong(1),
38			PyLong_FromLong(10),
39			PyLong_FromLong(4));
40	objValue = [[NSObject alloc] init];
41	return self;
42}
43
44-(void)dealloc
45{
46	PyObjC_BEGIN_WITH_GIL
47		Py_XDECREF(pyValue);
48	PyObjC_END_WITH_GIL
49	[objValue release];
50	[nilValue release];
51	[super dealloc];
52}
53
54@end
55
56
57static PyMethodDef mod_methods[] = {
58	{ 0, 0, 0, 0 }
59};
60
61#if PY_VERSION_HEX >= 0x03000000
62
63static struct PyModuleDef mod_module = {
64	PyModuleDef_HEAD_INIT,
65	"instanceVariables",
66	NULL,
67	0,
68	mod_methods,
69	NULL,
70	NULL,
71	NULL,
72	NULL
73};
74
75#define INITERROR() return NULL
76#define INITDONE() return m
77
78PyObject* PyInit_instanceVariables(void);
79
80PyObject*
81PyInit_instanceVariables(void)
82
83#else
84
85#define INITERROR() return
86#define INITDONE() return
87
88void initinstanceVariables(void);
89
90void
91initinstanceVariables(void)
92#endif
93{
94	PyObject* m;
95
96#if PY_VERSION_HEX >= 0x03000000
97	m = PyModule_Create(&mod_module);
98#else
99	m = Py_InitModule4("instanceVariables", mod_methods,
100		NULL, NULL, PYTHON_API_VERSION);
101#endif
102	if (!m) {
103		INITERROR();
104	}
105
106	if (PyObjC_ImportAPI(m) < 0) {
107		INITERROR();
108	}
109	if (PyModule_AddObject(m, "ClassWithVariables",
110		PyObjCClass_New([ClassWithVariables class])) < 0) {
111		INITERROR();
112	}
113	INITDONE();
114}
115