~ubuntu-branches/ubuntu/trusty/gnustep-base/trusty

« back to all changes in this revision

Viewing changes to Source/NSZone.m

  • Committer: Package Import Robot
  • Author(s): Benjamin Drung
  • Date: 2012-11-21 13:56:22 UTC
  • mfrom: (8.1.5 experimental)
  • Revision ID: package-import@ubuntu.com-20121121135622-1w035dpxneardw8q
Tags: 1.24.0-1ubuntu1
Backport upstream fix for recent libxml2.

Show diffs side-by-side

added added

removed removed

Lines of Context:
23
23
   Boston, MA 02111 USA.
24
24
 
25
25
   <title>NSZone class reference</title>
26
 
   $Date: 2011-02-27 17:53:14 +0000 (Sun, 27 Feb 2011) $ $Revision: 32388 $
 
26
   $Date: 2012-01-09 01:28:27 -0700 (Mon, 09 Jan 2012) $ $Revision: 34468 $
27
27
*/
28
28
 
29
29
/*  Design goals:
102
102
void *
103
103
GSOutOfMemory(NSUInteger size, BOOL retry)
104
104
{
105
 
  fprintf(stderr, "GSOutOfMemory ... wanting %lu bytes.\n",
106
 
    (unsigned long)size);
 
105
  fprintf(stderr, "GSOutOfMemory ... wanting %"PRIuPTR" bytes.\n", size);
107
106
  return 0;
108
107
}
109
108
 
227
226
    zone = NSDefaultMallocZone();
228
227
  return zone->name;
229
228
}
230
 
 
231
 
#if     GS_WITH_GC
 
229
#if __OBJC_GC__
 
230
 
 
231
#include <objc/objc-auto.h>
 
232
 
 
233
__strong void *
 
234
NSAllocateCollectable(NSUInteger size, NSUInteger options)
 
235
{
 
236
  if (!objc_collecting_enabled())
 
237
    {
 
238
      return calloc(1, size);
 
239
    }
 
240
  id obj = objc_gc_allocate_collectable(size, 
 
241
             ((options & NSScannedOption) == NSScannedOption));
 
242
  if ((options & NSCollectorDisabledOption) == NSCollectorDisabledOption)
 
243
    {
 
244
      obj = objc_gc_retain(obj);
 
245
    }
 
246
  return obj;
 
247
}
 
248
 
 
249
__strong void *
 
250
NSReallocateCollectable(void *ptr, NSUInteger size, NSUInteger options)
 
251
{
 
252
  if (!objc_collecting_enabled())
 
253
    {
 
254
      return realloc(ptr, size);
 
255
    }
 
256
  return objc_gc_reallocate_collectable(ptr, size, 
 
257
             ((options & NSScannedOption) == NSScannedOption));
 
258
}
 
259
 
 
260
id NSMakeCollectable(id obj)
 
261
{
 
262
  if (objc_collecting_enabled())
 
263
    {
 
264
      objc_gc_release(obj);
 
265
    }
 
266
  return obj;
 
267
}
 
268
 
 
269
NSZone*
 
270
NSCreateZone (NSUInteger start, NSUInteger gran, BOOL canFree)
 
271
{
 
272
  return &default_zone;
 
273
}
 
274
 
 
275
NSZone*
 
276
NSDefaultMallocZone (void)
 
277
{
 
278
  return &default_zone;
 
279
}
 
280
 
 
281
NSZone*
 
282
NSZoneFromPointer (void *ptr)
 
283
{
 
284
  return &default_zone;
 
285
}
 
286
 
 
287
void
 
288
NSRecycleZone (NSZone *zone) { }
 
289
 
 
290
BOOL
 
291
NSZoneCheck (NSZone *zone)
 
292
{
 
293
  return YES;
 
294
}
 
295
 
 
296
struct
 
297
NSZoneStats NSZoneStats (NSZone *zone)
 
298
{
 
299
  struct NSZoneStats stats = { 0 };
 
300
  return stats;
 
301
}
 
302
 
 
303
void
 
304
GSMakeWeakPointer(Class theClass, const char *iVarName) { }
 
305
 
 
306
BOOL
 
307
GSAssignZeroingWeakPointer(void **destination, void *source)
 
308
{
 
309
  objc_assign_weak(source, (id*)destination);
 
310
  return YES;
 
311
}
 
312
 
 
313
void*
 
314
NSZoneMalloc (NSZone *zone, NSUInteger size)
 
315
{
 
316
  return NSZoneCalloc(zone, 1, size);
 
317
}
 
318
 
 
319
void*
 
320
NSZoneCalloc (NSZone *zone, NSUInteger elems, NSUInteger bytes)
 
321
{
 
322
  if (objc_collecting_enabled())
 
323
    {
 
324
      // FIXME: Overflow checking
 
325
      size_t size = elems * bytes;
 
326
      return objc_gc_allocate_collectable(size, YES);
 
327
    }
 
328
  return calloc(elems, bytes);
 
329
}
 
330
 
 
331
void*
 
332
NSZoneRealloc (NSZone *zone, void *ptr, NSUInteger size)
 
333
{
 
334
  if (objc_collecting_enabled())
 
335
    {
 
336
      return objc_gc_reallocate_collectable(ptr, size, YES);
 
337
    }
 
338
  return realloc(ptr, size);
 
339
}
 
340
 
 
341
void NSZoneFree (NSZone *zone, void *ptr) { }
 
342
 
 
343
#elif   GS_WITH_GC
232
344
 
233
345
#if     defined(DEBUG)
234
346
#define GC_DEBUG        1