objc-auto.mm 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  1. /*
  2. * Copyright (c) 2004-2007 Apple Inc. All rights reserved.
  3. *
  4. * @APPLE_LICENSE_HEADER_START@
  5. *
  6. * This file contains Original Code and/or Modifications of Original Code
  7. * as defined in and that are subject to the Apple Public Source License
  8. * Version 2.0 (the 'License'). You may not use this file except in
  9. * compliance with the License. Please obtain a copy of the License at
  10. * http://www.opensource.apple.com/apsl/ and read it before using this
  11. * file.
  12. *
  13. * The Original Code and all software distributed under the License are
  14. * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
  15. * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
  16. * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
  17. * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
  18. * Please see the License for the specific language governing rights and
  19. * limitations under the License.
  20. *
  21. * @APPLE_LICENSE_HEADER_END@
  22. */
  23. #define OBJC_DECLARE_SYMBOLS 1
  24. #include "objc-private.h"
  25. #include "objc-auto.h"
  26. // GC is no longer supported.
  27. #if OBJC_NO_GC_API
  28. // No GC and no GC symbols needed. We're done here.
  29. # if SUPPORT_GC_COMPAT
  30. # error inconsistent config settings
  31. # endif
  32. #else
  33. // No GC but we do need to export GC symbols.
  34. # if !SUPPORT_GC_COMPAT
  35. # error inconsistent config settings
  36. # endif
  37. void objc_collect(unsigned long options __unused) { }
  38. BOOL objc_collectingEnabled(void) { return NO; }
  39. void objc_setCollectionThreshold(size_t threshold __unused) { }
  40. void objc_setCollectionRatio(size_t ratio __unused) { }
  41. void objc_startCollectorThread(void) { }
  42. #if TARGET_OS_WIN32
  43. BOOL objc_atomicCompareAndSwapPtr(id predicate, id replacement, volatile id *objectLocation)
  44. { void *original = InterlockedCompareExchangePointer((void * volatile *)objectLocation, (void *)replacement, (void *)predicate); return (original == predicate); }
  45. BOOL objc_atomicCompareAndSwapPtrBarrier(id predicate, id replacement, volatile id *objectLocation)
  46. { void *original = InterlockedCompareExchangePointer((void * volatile *)objectLocation, (void *)replacement, (void *)predicate); return (original == predicate); }
  47. #else
  48. BOOL objc_atomicCompareAndSwapPtr(id predicate, id replacement, volatile id *objectLocation)
  49. { return OSAtomicCompareAndSwapPtr((void *)predicate, (void *)replacement, (void * volatile *)objectLocation); }
  50. BOOL objc_atomicCompareAndSwapPtrBarrier(id predicate, id replacement, volatile id *objectLocation)
  51. { return OSAtomicCompareAndSwapPtrBarrier((void *)predicate, (void *)replacement, (void * volatile *)objectLocation); }
  52. #endif
  53. BOOL objc_atomicCompareAndSwapGlobal(id predicate, id replacement, volatile id *objectLocation)
  54. { return objc_atomicCompareAndSwapPtr(predicate, replacement, objectLocation); }
  55. BOOL objc_atomicCompareAndSwapGlobalBarrier(id predicate, id replacement, volatile id *objectLocation)
  56. { return objc_atomicCompareAndSwapPtrBarrier(predicate, replacement, objectLocation); }
  57. BOOL objc_atomicCompareAndSwapInstanceVariable(id predicate, id replacement, volatile id *objectLocation)
  58. { return objc_atomicCompareAndSwapPtr(predicate, replacement, objectLocation); }
  59. BOOL objc_atomicCompareAndSwapInstanceVariableBarrier(id predicate, id replacement, volatile id *objectLocation)
  60. { return objc_atomicCompareAndSwapPtrBarrier(predicate, replacement, objectLocation); }
  61. id objc_assign_strongCast(id val, id *dest)
  62. { return (*dest = val); }
  63. id objc_assign_global(id val, id *dest)
  64. { return (*dest = val); }
  65. id objc_assign_threadlocal(id val, id *dest)
  66. { return (*dest = val); }
  67. id objc_assign_ivar(id val, id dest, ptrdiff_t offset)
  68. { return (*(id*)((char *)dest+offset) = val); }
  69. id objc_read_weak(id *location)
  70. { return *location; }
  71. id objc_assign_weak(id value, id *location)
  72. { return (*location = value); }
  73. void *objc_memmove_collectable(void *dst, const void *src, size_t size)
  74. { return memmove(dst, src, size); }
  75. void objc_finalizeOnMainThread(Class cls __unused) { }
  76. BOOL objc_is_finalized(void *ptr __unused) { return NO; }
  77. void objc_clear_stack(unsigned long options __unused) { }
  78. BOOL objc_collecting_enabled(void) { return NO; }
  79. void objc_set_collection_threshold(size_t threshold __unused) { }
  80. void objc_set_collection_ratio(size_t ratio __unused) { }
  81. void objc_start_collector_thread(void) { }
  82. id objc_allocate_object(Class cls, int extra)
  83. { return class_createInstance(cls, extra); }
  84. void objc_registerThreadWithCollector() { }
  85. void objc_unregisterThreadWithCollector() { }
  86. void objc_assertRegisteredThreadWithCollector() { }
  87. malloc_zone_t* objc_collect_init(int(*callback)() __unused) { return nil; }
  88. malloc_zone_t* objc_collectableZone() { return nil; }
  89. BOOL objc_isAuto(id object __unused) { return NO; }
  90. BOOL objc_dumpHeap(char *filename __unused, unsigned long length __unused)
  91. { return NO; }
  92. // not OBJC_NO_GC_API
  93. #endif