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 NSObject (OC_CopyHelper)
10-(void)modify;
11@end
12
13@interface OC_CopyHelper : NSObject
14{ }
15+(NSObject*)doCopySetup:(Class)aClass;
16@end
17
18@implementation OC_CopyHelper
19+(NSObject*)doCopySetup:(Class)aClass
20{
21	NSObject<NSCopying>* tmp;
22	NSObject* retval;
23
24	tmp = (NSObject*)[[aClass alloc] init];
25	[tmp modify];
26
27	retval = [tmp copyWithZone:nil];
28	[tmp release];
29	return retval;
30}
31@end
32
33@interface OC_CopyBase : NSObject <NSCopying>
34{
35	int intVal;
36}
37-init;
38-initWithInt:(int)intVal;
39-(int)intVal;
40-(void)setIntVal:(int)val;
41-copyWithZone:(NSZone*)zone;
42@end
43
44@implementation OC_CopyBase
45-init
46{
47	return [self initWithInt:0];
48}
49
50-initWithInt:(int)value
51{
52	self = [super init];
53	if (self == nil) return nil;
54
55	intVal = value;
56	return self;
57}
58
59-(int)intVal
60{
61	return intVal;
62}
63
64-(void)setIntVal:(int)val
65{
66	intVal = val;
67}
68
69-copyWithZone:(NSZone*)zone
70{
71	return NSCopyObject(self, 0, zone);
72
73}
74@end
75
76
77static PyMethodDef copying_methods[] = {
78	{ 0, 0, 0, 0 }
79};
80
81void initcopying(void);
82void initcopying(void)
83{
84	PyObject* m;
85
86	m = Py_InitModule4("copying", copying_methods,
87			NULL, NULL, PYTHON_API_VERSION);
88
89	PyObjC_ImportAPI(m);
90	PyModule_AddObject(m, "OC_CopyHelper",
91		PyObjCClass_New([OC_CopyHelper class]));
92	PyModule_AddObject(m, "OC_CopyBase",
93		PyObjCClass_New([OC_CopyBase class]));
94}
95