mirror of
https://git.code.sf.net/p/quake/quakeforge
synced 2025-01-18 23:11:38 +00:00
[ruamoko] Correct SetIterator memory handling
This makes SetIterator more compatible with autorelease.
This commit is contained in:
parent
7571231100
commit
2b25748cc4
3 changed files with 21 additions and 5 deletions
|
@ -52,6 +52,7 @@ typedef struct {
|
|||
|
||||
typedef struct {
|
||||
pr_id_t obj;
|
||||
pr_int_t set;
|
||||
pr_int_t iter;
|
||||
} pr_set_iter_t;
|
||||
|
||||
|
|
|
@ -1,8 +1,8 @@
|
|||
#ifndef __ruamoko_Set_h
|
||||
#define __ruamoko_Set_h
|
||||
|
||||
typedef struct set_s *set_t;
|
||||
typedef struct set_iter_s *set_iter_t;
|
||||
typedef struct set_s set_t;
|
||||
typedef struct set_iter_s set_iter_t;
|
||||
|
||||
@extern void set_del_iter (set_iter_t *set_iter);
|
||||
@extern unsigned set_iter_element (set_iter_t *set_iter);
|
||||
|
@ -32,8 +32,11 @@ typedef struct set_iter_s *set_iter_t;
|
|||
|
||||
#include <Object.h>
|
||||
|
||||
@class Set;
|
||||
|
||||
@interface SetIterator: Object
|
||||
{
|
||||
Set *set;
|
||||
set_iter_t *iter;
|
||||
}
|
||||
- (SetIterator *) next;
|
||||
|
|
|
@ -27,20 +27,32 @@ string set_as_string (set_t *set) = #0;
|
|||
|
||||
|
||||
@implementation SetIterator: Object
|
||||
- initWithIterator: (set_iter_t *) iter
|
||||
|
||||
- initWithSet: (Set *)set iterator:(set_iter_t *) iter
|
||||
{
|
||||
if (!(self = [super init])) {
|
||||
return nil;
|
||||
}
|
||||
self.set = [set retain];
|
||||
self.iter = iter;
|
||||
return self;
|
||||
}
|
||||
|
||||
+ (id) withSet: (Set *)set iterator:(set_iter_t *) iter
|
||||
{
|
||||
return [[[self alloc] initWithSet: set iterator: iter] autorelease];
|
||||
}
|
||||
|
||||
- (void) dealloc
|
||||
{
|
||||
[set release];
|
||||
[super dealloc];
|
||||
}
|
||||
|
||||
- (SetIterator *) next
|
||||
{
|
||||
if ((iter = set_next (iter)))
|
||||
return self;
|
||||
[self dealloc];
|
||||
return nil;
|
||||
}
|
||||
|
||||
|
@ -93,7 +105,7 @@ string set_as_string (set_t *set) = #0;
|
|||
|
||||
if (!iter)
|
||||
return nil;
|
||||
iterator = [[SetIterator alloc] initWithIterator: iter];
|
||||
iterator = [SetIterator withSet: self iterator: iter];
|
||||
return iterator;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue