Author: mlytwyn
Date: Tue Mar  8 23:04:34 2016
New Revision: 39489

URL: http://svn.gna.org/viewcvs/gnustep?rev=39489&view=rev
Log:
Merge with base main branch revision 39486

Added:
    
libs/base/branches/gnustep_testplant_branch/Headers/GNUstepBase/NSHashTable+GNUstepBase.h
    
libs/base/branches/gnustep_testplant_branch/Source/Additions/NSHashTable+GNUstepBase.m
Modified:
    libs/base/branches/gnustep_testplant_branch/Source/Additions/GNUmakefile
    libs/base/branches/gnustep_testplant_branch/Source/Additions/GSObjCRuntime.m
    
libs/base/branches/gnustep_testplant_branch/Source/Additions/GSTypeEncoding.c
    libs/base/branches/gnustep_testplant_branch/Source/Additions/GSXML.m
    
libs/base/branches/gnustep_testplant_branch/Source/Additions/NSData+GNUstepBase.m
    
libs/base/branches/gnustep_testplant_branch/Source/Additions/NSObject+GNUstepBase.m

Added: 
libs/base/branches/gnustep_testplant_branch/Headers/GNUstepBase/NSHashTable+GNUstepBase.h
URL: 
http://svn.gna.org/viewcvs/gnustep/libs/base/branches/gnustep_testplant_branch/Headers/GNUstepBase/NSHashTable%2BGNUstepBase.h?rev=39489&view=auto
==============================================================================
--- 
libs/base/branches/gnustep_testplant_branch/Headers/GNUstepBase/NSHashTable+GNUstepBase.h
   (added)
+++ 
libs/base/branches/gnustep_testplant_branch/Headers/GNUstepBase/NSHashTable+GNUstepBase.h
   Tue Mar  8 23:04:34 2016
@@ -0,0 +1,53 @@
+/** Declaration of extension methods for base additions
+
+   Copyright (C) 2015 Free Software Foundation, Inc.
+
+   Written by:  Niels Grewe <[email protected]>
+
+   This file is part of the GNUstep Base Library.
+
+   This library is free software; you can redistribute it and/or
+   modify it under the terms of the GNU Lesser General Public
+   License as published by the Free Software Foundation; either
+   version 2 of the License, or (at your option) any later version.
+   
+   This library is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+   Library General Public License for more details.
+
+   You should have received a copy of the GNU Lesser General Public
+   License along with this library; if not, write to the Free
+   Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+   Boston, MA 02111 USA.
+
+*/
+
+#ifndef        INCLUDED_NSHashTable_GNUstepBase_h
+#define        INCLUDED_NSHashTable_GNUstepBase_h
+
+#import <GNUstepBase/GSVersionMacros.h>
+#import <Foundation/NSHashTable.h>
+
+#if    defined(__cplusplus)
+extern "C" {
+#endif
+
+#if    OS_API_VERSION(GS_API_NONE,GS_API_LATEST)
+
+@interface NSHashTable (GNUstepBase)
+  /**
+   * Adds each object contained in the given array that is not already
+   * in the hash table.
+   */
+- (void)addObjectsFromArray: (NSArray*)array;
+@end
+
+#endif /* OS_API_VERSION */
+
+#if    defined(__cplusplus)
+}
+#endif
+
+#endif /* INCLUDED_NSHashTable_GNUstepBase_h */
+

Modified: 
libs/base/branches/gnustep_testplant_branch/Source/Additions/GNUmakefile
URL: 
http://svn.gna.org/viewcvs/gnustep/libs/base/branches/gnustep_testplant_branch/Source/Additions/GNUmakefile?rev=39489&r1=39488&r2=39489&view=diff
==============================================================================
--- libs/base/branches/gnustep_testplant_branch/Source/Additions/GNUmakefile    
(original)
+++ libs/base/branches/gnustep_testplant_branch/Source/Additions/GNUmakefile    
Tue Mar  8 23:04:34 2016
@@ -51,6 +51,7 @@
        NSData+GNUstepBase.m \
        NSDebug+GNUstepBase.m \
        NSError+GNUstepBase.m \
+       NSHashTable+GNUstepBase.m \
        NSFileHandle+GNUstepBase.m \
        NSLock+GNUstepBase.m \
        NSMutableString+GNUstepBase.m \

Modified: 
libs/base/branches/gnustep_testplant_branch/Source/Additions/GSObjCRuntime.m
URL: 
http://svn.gna.org/viewcvs/gnustep/libs/base/branches/gnustep_testplant_branch/Source/Additions/GSObjCRuntime.m?rev=39489&r1=39488&r2=39489&view=diff
==============================================================================
--- 
libs/base/branches/gnustep_testplant_branch/Source/Additions/GSObjCRuntime.m    
    (original)
+++ 
libs/base/branches/gnustep_testplant_branch/Source/Additions/GSObjCRuntime.m    
    Tue Mar  8 23:04:34 2016
@@ -1090,23 +1090,23 @@
            }
            break;
 
-#if     defined(_C_BOOL)
+#if __GNUC__ > 2 && defined(_C_BOOL)
           case _C_BOOL:
             {
-              bool      v;
+              _Bool     v;
  
               if (sel == 0)
                 {
-                  v = *(bool *)((char *)self + offset);
+                  v = *(_Bool *)((char *)self + offset);
                 }
               else
                 {
-                  bool  (*imp)(id, SEL) =
-                    (bool (*)(id, SEL))[self methodForSelector: sel];
+                  _Bool (*imp)(id, SEL) =
+                    (_Bool (*)(id, SEL))[self methodForSelector: sel];
  
                   v = (*imp)(self, sel);
                 }
-              val = [NSNumber numberWithBool: v];
+              val = [NSNumber numberWithBool: (BOOL)v];
             }
             break;
 #endif
@@ -1555,21 +1555,21 @@
            }
            break;
 
-#if     defined(_C_BOOL)
+#if __GNUC__ > 2 && defined(_C_BOOL)
           case _C_BOOL:
             {
-              bool      v = [val boolValue];
+              _Bool     v = (_Bool)[val boolValue];
  
               if (sel == 0)
                 {
-                  bool *ptr = (bool*)((char *)self + offset);
+                  _Bool *ptr = (_Bool*)((char *)self + offset);
  
                   *ptr = v;
                 }
               else
                 {
-                  void  (*imp)(id, SEL, bool) =
-                    (void (*)(id, SEL, bool))[self methodForSelector: sel];
+                  void  (*imp)(id, SEL, _Bool) =
+                    (void (*)(id, SEL, _Bool))[self methodForSelector: sel];
  
                   (*imp)(self, sel, v);
                 }

Modified: 
libs/base/branches/gnustep_testplant_branch/Source/Additions/GSTypeEncoding.c
URL: 
http://svn.gna.org/viewcvs/gnustep/libs/base/branches/gnustep_testplant_branch/Source/Additions/GSTypeEncoding.c?rev=39489&r1=39488&r2=39489&view=diff
==============================================================================
--- 
libs/base/branches/gnustep_testplant_branch/Source/Additions/GSTypeEncoding.c   
    (original)
+++ 
libs/base/branches/gnustep_testplant_branch/Source/Additions/GSTypeEncoding.c   
    Tue Mar  8 23:04:34 2016
@@ -24,9 +24,10 @@
  * THE SOFTWARE.
  */
 
+#include "GNUstepBase/GSTypeEncoding.h"
+
 #include <stdlib.h>
 #include <string.h>
-#include "GNUstepBase/GSTypeEncoding.h"
 
 #undef  MAX
 #define MAX(X, Y)                     \

Modified: libs/base/branches/gnustep_testplant_branch/Source/Additions/GSXML.m
URL: 
http://svn.gna.org/viewcvs/gnustep/libs/base/branches/gnustep_testplant_branch/Source/Additions/GSXML.m?rev=39489&r1=39488&r2=39489&view=diff
==============================================================================
--- libs/base/branches/gnustep_testplant_branch/Source/Additions/GSXML.m        
(original)
+++ libs/base/branches/gnustep_testplant_branch/Source/Additions/GSXML.m        
Tue Mar  8 23:04:34 2016
@@ -2878,7 +2878,15 @@
       for (i = j = 0; i < nb_attributes; i++, j += 5)
        {
          NSString      *key = UTF8Str(atts[j]);
-         NSString      *obj = UTF8StrLen(atts[j+3], atts[j+4]-atts[j+3]);
+          NSString      *obj = nil;
+          // We need to append the namespace prefix
+          if (atts[j+1] != NULL)
+            {
+              key =
+               [[UTF8Str(atts[j+1]) stringByAppendingString: @":"]
+                                      stringByAppendingString: key];
+            }
+         obj = UTF8StrLen(atts[j+3], atts[j+4]-atts[j+3]);
 
          [adict setObject: obj forKey: key];
        }

Modified: 
libs/base/branches/gnustep_testplant_branch/Source/Additions/NSData+GNUstepBase.m
URL: 
http://svn.gna.org/viewcvs/gnustep/libs/base/branches/gnustep_testplant_branch/Source/Additions/NSData%2BGNUstepBase.m?rev=39489&r1=39488&r2=39489&view=diff
==============================================================================
--- 
libs/base/branches/gnustep_testplant_branch/Source/Additions/NSData+GNUstepBase.m
   (original)
+++ 
libs/base/branches/gnustep_testplant_branch/Source/Additions/NSData+GNUstepBase.m
   Tue Mar  8 23:04:34 2016
@@ -31,6 +31,10 @@
 
 #include <ctype.h>
 
+#if     USE_ZLIB
+#include <zlib.h>
+#endif
+
 #if    defined(__MINGW32__)
 #include <wincrypt.h>
 #else
@@ -112,33 +116,107 @@
   return AUTORELEASE(d);
 }
 
-/**
- * Returns an NSString object containing an ASCII hexadecimal representation
- * of the receiver.  This means that the returned object will contain
- * exactly twice as many characters as there are bytes as the receiver,
- * as each byte in the receiver is represented by two hexadecimal digits.<br />
- * The high order four bits of each byte is encoded before the low
- * order four bits.  Capital letters 'A' to 'F' are used to represent
- * values from 10 to 15.<br />
- * If you need the hexadecimal representation as raw byte data, use code
- * like -
- * <example>
- *   hexData = [[sourceData hexadecimalRepresentation]
- *     dataUsingEncoding: NSASCIIStringEncoding];
- * </example>
- */
+- (NSString*) escapedRepresentation
+{
+  char          *buf;
+  NSUInteger    len;
+  NSString      *string;
+
+  buf = [self escapedRepresentation: &len];
+  string = [[NSString alloc] initWithBytesNoCopy: buf
+                                          length: len
+                                        encoding: NSASCIIStringEncoding
+                                    freeWhenDone: YES];
+  return AUTORELEASE(string);
+}
+
+- (char*) escapedRepresentation: (NSUInteger*)length
+{
+  const uint8_t *bytes = (const uint8_t*)[self bytes];
+  uint8_t       *buf;
+  NSUInteger    count = [self length];
+  NSUInteger    size = count + 1;
+  NSUInteger    index;
+  NSUInteger    pos;
+
+  for (index = 0; index < count; index++)
+    {
+      uint8_t   b = bytes[index];
+
+      if ('\n' == b) size++;
+      else if ('\r' == b) size++;
+      else if ('\t' == b) size++;
+      else if ('\\' == b) size++;
+      else if (b < 32 || b > 126) size += 3;
+    }
+  buf = (uint8_t*)malloc(size);
+  for (pos = index = 0; index < count; index++)
+    {
+      uint8_t   b = bytes[index];
+
+      if ('\n' == b)
+        {
+          buf[pos++] = '\\';
+          buf[pos++] = 'n';
+        }
+      else if ('\r' == b)
+        {
+          buf[pos++] = '\\';
+          buf[pos++] = 'r';
+        }
+      else if ('\t' == b)
+        {
+          buf[pos++] = '\\';
+          buf[pos++] = 't';
+        }
+      else if ('\\' == b)
+        {
+          buf[pos++] = '\\';
+          buf[pos++] = '\\';
+        }
+      else if (b < 32 || b > 126)
+        {
+          sprintf((char*)&buf[pos], "\\x%02x", b);
+          pos += 4;
+        }
+      else
+        {
+          buf[pos++] = b;
+        }
+    }
+  buf[pos] = '\0';
+  if (0 != length)
+    {
+      *length = pos;
+    }
+  return (char*)buf;
+}
+
 - (NSString*) hexadecimalRepresentation
+{
+  char          *buf;
+  NSUInteger    len;
+  NSString      *string;
+
+  buf = [self hexadecimalRepresentation: &len];
+  string = [[NSString alloc] initWithBytesNoCopy: buf
+                                          length: len
+                                        encoding: NSASCIIStringEncoding
+                                    freeWhenDone: YES];
+  return AUTORELEASE(string);
+}
+
+- (char*) hexadecimalRepresentation: (NSUInteger*)length
 {
   static const char    *hexChars = "0123456789ABCDEF";
   unsigned             slen = [self length];
   unsigned             dlen = slen * 2;
   const unsigned char  *src = (const unsigned char *)[self bytes];
-  char                 *dst = (char*)NSZoneMalloc(NSDefaultMallocZone(), dlen);
+  char                 *dst;
   unsigned             spos = 0;
   unsigned             dpos = 0;
-  NSData               *data;
-  NSString             *string;
-
+
+  dst = (char*)malloc(dlen + 1);
   while (spos < slen)
     {
       unsigned char    c = src[spos++];
@@ -146,12 +224,128 @@
       dst[dpos++] = hexChars[(c >> 4) & 0x0f];
       dst[dpos++] = hexChars[c & 0x0f];
     }
-  data = [NSData allocWithZone: NSDefaultMallocZone()];
-  data = [data initWithBytesNoCopy: dst length: dlen];
-  string = [[NSString alloc] initWithData: data
-                                encoding: NSASCIIStringEncoding];
-  RELEASE(data);
-  return AUTORELEASE(string);
+  dst[dpos] = '\0';
+  if (0 != length)
+    {
+      *length = dpos;
+}
+  return dst;
+}
+
+- (NSData*) gunzipped
+{
+#if     USE_ZLIB
+  NSUInteger    length = [self length];
+  z_stream      stream;
+
+  if (NO == [self isGzipped])
+    {
+      return self;
+    }
+
+  stream.zalloc = Z_NULL;
+  stream.zfree = Z_NULL;
+  stream.avail_in = (unsigned)length;
+  stream.next_in = (uint8_t *)[self bytes];
+  stream.total_out = 0;
+  stream.avail_out = 0;
+
+  if (inflateInit2(&stream, 15 + 32) == Z_OK)   // inflate or gzip
+    {
+      NSZone    *zone = NSDefaultMallocZone();
+      uint8_t   *dst;
+      unsigned  capacity;
+      int       status = Z_OK;
+
+      capacity = 2 * length;
+      dst = NSZoneMalloc(zone, capacity);
+      while (Z_OK == status)
+        {
+          if (stream.total_out >= capacity)
+            {
+              capacity += length / 2;
+              dst = NSZoneRealloc(zone, dst, capacity);
+            }
+          stream.next_out = dst + stream.total_out;
+          stream.avail_out = (unsigned)(capacity - stream.total_out);
+          status = inflate(&stream, Z_SYNC_FLUSH);
+        }
+      if (inflateEnd(&stream) == Z_OK)
+        {
+          if (Z_STREAM_END == status)
+            {
+              NSMutableData     *result;
+
+              result = [NSMutableData alloc];
+              result = [result initWithBytesNoCopy: dst
+                                            length: stream.total_out
+                                      freeWhenDone: YES];
+              return AUTORELEASE(result);
+            }
+        }
+      NSZoneFree(zone, dst);
+    }
+#else
+  [NSException raise: NSGenericException
+              format: @"library was configured without zlib support"];
+#endif
+  return nil;
+}
+
+- (NSData*) gzipped: (int)compressionLevel
+{
+#if     USE_ZLIB
+  NSUInteger    length = [self length];
+  z_stream      stream;
+
+  stream.zalloc = Z_NULL;
+  stream.zfree = Z_NULL;
+  stream.opaque = Z_NULL;
+  stream.avail_in = (unsigned)length;
+  stream.next_in = (uint8_t*)[self bytes];
+  stream.total_out = 0;
+  stream.avail_out = 0;
+
+  if (compressionLevel < 0 || compressionLevel > 9)
+    {
+      compressionLevel = Z_DEFAULT_COMPRESSION;
+    }
+  if (deflateInit2(&stream,
+    compressionLevel,
+    Z_DEFLATED,
+    31,
+    8,
+    Z_DEFAULT_STRATEGY) == Z_OK)
+    {
+      NSMutableData     *result;
+      NSZone            *zone = NSDefaultMallocZone();
+      unsigned          capacity = 1024 * 16;
+      uint8_t           *dst;
+
+      dst = NSZoneMalloc(zone, capacity);
+      while (stream.avail_out == 0)
+        {
+          if (stream.total_out >= capacity)
+            {
+              capacity += 1024 * 16;
+              dst = NSZoneRealloc(zone, dst, capacity);
+            }
+          stream.next_out = dst + stream.total_out;
+          stream.avail_out = (unsigned)(capacity - stream.total_out);
+          deflate(&stream, Z_FINISH);
+        }
+      deflateEnd(&stream);
+      result = [NSMutableData alloc];
+      result = [result initWithBytesNoCopy: dst
+                                    length: stream.total_out
+                              freeWhenDone: YES];
+      return AUTORELEASE(result);
+    }
+#else
+  [NSException raise: NSGenericException
+              format: @"library was configured without zlib support"];
+#endif
+  return nil;
 }
 
 /**
@@ -235,6 +429,14 @@
        NSStringFromSelector(_cmd)];
     }
   return self;
+}
+
+- (BOOL) isGzipped
+{
+  NSUInteger    length = [self length];
+  const uint8_t *bytes = (const uint8_t *)[self bytes];
+
+  return (length >= 2 && bytes[0] == 0x1f && bytes[1] == 0x8b) ? YES : NO;
 }
 
 struct MD5Context
@@ -781,4 +983,5 @@
   [encoded appendBytes: "`\nend\n" length: 6];
   return YES;
 }
+
 @end

Added: 
libs/base/branches/gnustep_testplant_branch/Source/Additions/NSHashTable+GNUstepBase.m
URL: 
http://svn.gna.org/viewcvs/gnustep/libs/base/branches/gnustep_testplant_branch/Source/Additions/NSHashTable%2BGNUstepBase.m?rev=39489&view=auto
==============================================================================
--- 
libs/base/branches/gnustep_testplant_branch/Source/Additions/NSHashTable+GNUstepBase.m
      (added)
+++ 
libs/base/branches/gnustep_testplant_branch/Source/Additions/NSHashTable+GNUstepBase.m
      Tue Mar  8 23:04:34 2016
@@ -0,0 +1,39 @@
+/* Implementation of extension methods to base additions
+
+   Copyright (C) 2015 Free Software Foundation, Inc.
+
+   Written by:  Niels Grewe <[email protected]>
+
+   This file is part of the GNUstep Base Library.
+
+   This library is free software; you can redistribute it and/or
+   modify it under the terms of the GNU Lesser General Public
+   License as published by the Free Software Foundation; either
+   version 2 of the License, or (at your option) any later version.
+
+   This library is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+   Library General Public License for more details.
+
+   You should have received a copy of the GNU Lesser General Public
+   License along with this library; if not, write to the Free
+   Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+   Boston, MA 02111 USA.
+
+*/
+#import "common.h"
+#import "Foundation/NSArray.h"
+#import "GNUstepBase/NSHashTable+GNUstepBase.h"
+#import "GSPrivate.h"
+#import "GSFastEnumeration.h"
+
+@implementation NSHashTable (GNUstepBase)
+
+- (void)addObjectsFromArray: (NSArray*)array
+{
+  FOR_IN(id, obj, array)
+    NSHashInsert(self,obj);
+  END_FOR_IN(array)
+}
+@end

Modified: 
libs/base/branches/gnustep_testplant_branch/Source/Additions/NSObject+GNUstepBase.m
URL: 
http://svn.gna.org/viewcvs/gnustep/libs/base/branches/gnustep_testplant_branch/Source/Additions/NSObject%2BGNUstepBase.m?rev=39489&r1=39488&r2=39489&view=diff
==============================================================================
--- 
libs/base/branches/gnustep_testplant_branch/Source/Additions/NSObject+GNUstepBase.m
 (original)
+++ 
libs/base/branches/gnustep_testplant_branch/Source/Additions/NSObject+GNUstepBase.m
 Tue Mar  8 23:04:34 2016
@@ -25,6 +25,7 @@
 #import "common.h"
 #import "Foundation/NSArray.h"
 #import "Foundation/NSException.h"
+#import "Foundation/NSHashTable.h"
 #import "Foundation/NSLock.h"
 #import "GNUstepBase/NSObject+GNUstepBase.h"
 #import "GNUstepBase/NSDebug+GNUstepBase.h"
@@ -293,6 +294,33 @@
 
 #else
 
+NSUInteger
+GSPrivateMemorySize(NSObject *self, NSHashTable *exclude)
+{
+  if (0 == NSHashGet(exclude, self))
+    {
+      NSHashInsert(exclude, self);
+      return class_getInstanceSize(object_getClass(self));
+    }
+  return 0;
+}
+
+@interface      NSObject (MemoryFootprint)
++ (NSUInteger) sizeInBytesExcluding: (NSHashTable*)exclude
+{
+  return 0;
+}
+- (NSUInteger) sizeInBytesExcluding: (NSHashTable*)exclude
+{
+  if (0 == NSHashGet(exclude, self))
+    {
+      NSHashInsert(exclude, self);
+      return class_getInstanceSize(object_getClass(self));
+    }
+  return 0;
+}
+@end
+
 /* Dummy implementation
  */
 @implementation NSObject(GSCleanup)


_______________________________________________
Gnustep-cvs mailing list
[email protected]
https://mail.gna.org/listinfo/gnustep-cvs

Reply via email to