Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 87a3092

Browse files
committed
Added hash() and compare() functions. Needed because multiple WinObj's can now refer to the same underlying WindowRef.
1 parent 620e914 commit 87a3092

2 files changed

Lines changed: 35 additions & 2 deletions

File tree

Mac/Modules/win/Winmodule.c

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2165,11 +2165,21 @@ static PyObject *WinObj_getattr(self, name)
21652165

21662166
#define WinObj_setattr NULL
21672167

2168-
#define WinObj_compare NULL
2168+
static int WinObj_compare(self, other)
2169+
WindowObject *self, *other;
2170+
{
2171+
if ( self->ob_itself > other->ob_itself ) return 1;
2172+
if ( self->ob_itself < other->ob_itself ) return -1;
2173+
return 0;
2174+
}
21692175

21702176
#define WinObj_repr NULL
21712177

2172-
#define WinObj_hash NULL
2178+
static int WinObj_hash(self)
2179+
WindowObject *self;
2180+
{
2181+
return (int)self->ob_itself;
2182+
}
21732183

21742184
PyTypeObject Window_Type = {
21752185
PyObject_HEAD_INIT(&PyType_Type)

Mac/Modules/win/winsupport.py

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,29 @@ def outputCleanupStructMembers(self):
126126
OutRbrace()
127127
Output("self->ob_itself = NULL;")
128128
Output("self->ob_freeit = NULL;")
129+
130+
def outputCompare(self):
131+
Output()
132+
Output("static int %s_compare(self, other)", self.prefix)
133+
IndentLevel()
134+
Output("%s *self, *other;", self.objecttype)
135+
DedentLevel()
136+
OutLbrace()
137+
Output("if ( self->ob_itself > other->ob_itself ) return 1;")
138+
Output("if ( self->ob_itself < other->ob_itself ) return -1;")
139+
Output("return 0;")
140+
OutRbrace()
141+
142+
def outputHash(self):
143+
Output()
144+
Output("static int %s_hash(self)", self.prefix)
145+
IndentLevel()
146+
Output("%s *self;", self.objecttype)
147+
DedentLevel()
148+
OutLbrace()
149+
Output("return (int)self->ob_itself;")
150+
OutRbrace()
151+
129152
## def outputFreeIt(self, itselfname):
130153
## Output("DisposeWindow(%s);", itselfname)
131154
# From here on it's basically all boiler plate...

0 commit comments

Comments
 (0)