summaryrefslogtreecommitdiff
path: root/Objective-C/NSObject-ObjectiveCLWrapperLink.m
blob: 8d34a193954ec472afe3a21ba832b20f1e2c5583 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
/* -*- mode: objc; coding: utf-8 -*- */

#import "NSObject-ObjectiveCLWrapperLink.h"
#import <Foundation/NSSet.h>
#import <Foundation/NSObject.h>
#import <Foundation/NSString.h>

/* A class is considered Lisp-backed if some of its methods are
   implemented as Lisp callbacks.  This is true if and only if
   @selector(retain) and @selector(release) are overridden by
   Objective-CL.  In this case, the corresponding Lisp objects are
   stored in a regular hash table instead of a weak one, as they may
   hold data (like CLOS slots) that we can't do without as long as the
   Objective-C instance is referenced from anywhere (where `anywhere'
   includes both the Lisp and Objective-C worlds). */
static NSMutableSet *lisp_backed_classes = nil;

void
objcl_initialise_instance_wrappers (void)
{
  if (lisp_backed_classes == nil)
    lisp_backed_classes = [[NSMutableSet alloc] init];
}

void
objcl_shutdown_instance_wrappers (void)
{
  if (lisp_backed_classes != nil)
    {
      [lisp_backed_classes release];
      lisp_backed_classes = nil;
    }
}

@implementation NSObject (ObjectiveCLWrapperLink)
+(BOOL) __objcl_isBackedByLispClass
{
  return [lisp_backed_classes containsObject: self];
}

+(void) __objcl_setBackedByLispClass: (BOOL)backed_p
{
  if (backed_p)
    [lisp_backed_classes addObject: self];
  else
    [lisp_backed_classes removeObject: self];
}
@end /* NSObject (ObjectiveCL) */