From 9908c5b4e9d00b8e212573f051007dd76654cd62 Mon Sep 17 00:00:00 2001 From: macmade Date: Sun, 7 Sep 2014 16:15:29 +0200 Subject: [PATCH] Private definitions for XSData... --- .../XS/Classes/XSData/__XSData_Constructor.c | 6 +- .../source/XS/Classes/XSData/__XSData_Copy.c | 30 ++++++- .../XS/Classes/XSData/__XSData_Destructor.c | 7 -- .../XS/Classes/XSData/__XSData_Equals.c | 12 +-- .../source/XS/Classes/XSData/__XSData_Lock.c | 80 +++++++++++++++++++ .../XS/Classes/XSData/__XSData_ToString.c | 10 +-- .../XS/Classes/XSData/__XSData_Unlock.c | 80 +++++++++++++++++++ 7 files changed, 196 insertions(+), 29 deletions(-) create mode 100644 XSFoundation/source/XS/Classes/XSData/__XSData_Lock.c create mode 100644 XSFoundation/source/XS/Classes/XSData/__XSData_Unlock.c diff --git a/XSFoundation/source/XS/Classes/XSData/__XSData_Constructor.c b/XSFoundation/source/XS/Classes/XSData/__XSData_Constructor.c index 1b721f37..1d1ed754 100644 --- a/XSFoundation/source/XS/Classes/XSData/__XSData_Constructor.c +++ b/XSFoundation/source/XS/Classes/XSData/__XSData_Constructor.c @@ -73,11 +73,7 @@ XSDataRef __XSData_Constructor( XSDataRef object ) { - return object; - - /* - object->lock = XSRecursiveLock_Create(); + ( ( struct __XSData * )object )->lock = XSRecursiveLock_Create(); return object; - */ } diff --git a/XSFoundation/source/XS/Classes/XSData/__XSData_Copy.c b/XSFoundation/source/XS/Classes/XSData/__XSData_Copy.c index 80190bb5..852bf9e2 100644 --- a/XSFoundation/source/XS/Classes/XSData/__XSData_Copy.c +++ b/XSFoundation/source/XS/Classes/XSData/__XSData_Copy.c @@ -73,7 +73,35 @@ XSDataRef __XSData_Copy( XSDataRef source, XSDataRef destination ) { - ( void )source; + ( ( struct __XSData * )destination )->lock = XSRecursiveLock_Create(); + ( ( struct __XSData * )destination )->properties = source->properties; + ( ( struct __XSData * )destination )->length = source->length; + ( ( struct __XSData * )destination )->capacity = source->capacity; + ( ( struct __XSData * )destination )->releaseType = source->releaseType; + + __XSData_Lock( source ); + + if( source->buffer != NULL ) + { + if( source->releaseType == XSData_BufferReleaseTypeRelease && ( source->properties & __XSData_PropertiesMutable ) == 0 ) + { + ( ( struct __XSData * )destination )->buffer = XSRetain( source->buffer ); + } + else + { + ( ( struct __XSData * )destination )->releaseType = XSData_BufferReleaseTypeRelease; + ( ( struct __XSData * )destination )->buffer = XSAlloc( source->capacity ); + + if( destination->buffer == NULL ) + { + XSFatalError( "Error allocating memory for the XSData buffer" ); + } + + memcpy( ( ( struct __XSData * )destination )->buffer, source->buffer, source->length ); + } + } + + __XSData_Unlock( source ); return destination; } diff --git a/XSFoundation/source/XS/Classes/XSData/__XSData_Destructor.c b/XSFoundation/source/XS/Classes/XSData/__XSData_Destructor.c index bf71a0e7..a819055e 100644 --- a/XSFoundation/source/XS/Classes/XSData/__XSData_Destructor.c +++ b/XSFoundation/source/XS/Classes/XSData/__XSData_Destructor.c @@ -73,11 +73,6 @@ void __XSData_Destructor( XSDataRef object ) { - ( void )object; - - /* - XSRecursiveLock_Lock( object->lock ); - switch( object->releaseType ) { case XSData_BufferReleaseTypeRelease: @@ -95,7 +90,5 @@ void __XSData_Destructor( XSDataRef object ) break; } - XSRecursiveLock_Unlock( object->lock ); XSRelease( object->lock ); - */ } diff --git a/XSFoundation/source/XS/Classes/XSData/__XSData_Equals.c b/XSFoundation/source/XS/Classes/XSData/__XSData_Equals.c index 0a59e775..564843a9 100644 --- a/XSFoundation/source/XS/Classes/XSData/__XSData_Equals.c +++ b/XSFoundation/source/XS/Classes/XSData/__XSData_Equals.c @@ -73,9 +73,6 @@ bool __XSData_Equals( XSDataRef object1, XSDataRef object2 ) { - return object1 == object2; - - /* bool equals; if( object1 == object2 ) @@ -85,8 +82,8 @@ bool __XSData_Equals( XSDataRef object1, XSDataRef object2 ) equals = false; - XSRecursiveLock_Lock( object1->lock ); - XSRecursiveLock_Lock( object2->lock ); + __XSData_Lock( object1 ); + __XSData_Lock( object2 ); if( object1->length != object2->length ) { @@ -109,9 +106,8 @@ bool __XSData_Equals( XSDataRef object1, XSDataRef object2 ) end: - XSRecursiveLock_Unlock( object1->lock ); - XSRecursiveLock_Unlock( object2->lock ); + __XSData_Unlock( object1 ); + __XSData_Unlock( object2 ); return equals; - */ } diff --git a/XSFoundation/source/XS/Classes/XSData/__XSData_Lock.c b/XSFoundation/source/XS/Classes/XSData/__XSData_Lock.c new file mode 100644 index 00000000..048228e8 --- /dev/null +++ b/XSFoundation/source/XS/Classes/XSData/__XSData_Lock.c @@ -0,0 +1,80 @@ +/******************************************************************************* + * XSFoundation - XEOS C Foundation Library + * + * Copyright (c) 2010-2014, Jean-David Gadina - www.xs-labs.com + * All rights reserved. + * + * XEOS Software License - Version 1.0 - December 21, 2012 + * + * Permission is hereby granted, free of charge, to any person or organisation + * obtaining a copy of the software and accompanying documentation covered by + * this license (the "Software") to deal in the Software, with or without + * modification, without restriction, including without limitation the rights + * to use, execute, display, copy, reproduce, transmit, publish, distribute, + * modify, merge, prepare derivative works of the Software, and to permit + * third-parties to whom the Software is furnished to do so, all subject to the + * following conditions: + * + * 1. Redistributions of source code, in whole or in part, must retain the + * above copyright notice and this entire statement, including the + * above license grant, this restriction and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright + * notice and this entire statement, including the above license grant, + * this restriction and the following disclaimer in the documentation + * and/or other materials provided with the distribution, unless the + * Software is distributed by the copyright owner as a library. + * A "library" means a collection of software functions and/or data + * prepared so as to be conveniently linked with application programs + * (which use some of those functions and data) to form executables. + * + * 3. The Software, or any substancial portion of the Software shall not + * be combined, included, derived, or linked (statically or + * dynamically) with software or libraries licensed under the terms + * of any GNU software license, including, but not limited to, the GNU + * General Public License (GNU/GPL) or the GNU Lesser General Public + * License (GNU/LGPL). + * + * 4. All advertising materials mentioning features or use of this + * software must display an acknowledgement stating that the product + * includes software developed by the copyright owner. + * + * 5. Neither the name of the copyright owner nor the names of its + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT OWNER AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE, TITLE AND NON-INFRINGEMENT ARE DISCLAIMED. + * + * IN NO EVENT SHALL THE COPYRIGHT OWNER, CONTRIBUTORS OR ANYONE DISTRIBUTING + * THE SOFTWARE BE LIABLE FOR ANY CLAIM, DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; + * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN ACTION OF CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF OR IN CONNECTION WITH + * THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE, EVEN IF ADVISED + * OF THE POSSIBILITY OF SUCH DAMAGE. + ******************************************************************************/ + +/* $Id$ */ + +/*! + * @file __XSData_Lock.c + * @copyright (c) 2010-2014 - Jean-David Gadina - www.xs-labs.com + * @author Jean-David Gadina - www.xs-labs.com + * @abstract Definition for __XSData_Lock + */ + +#include +#include + +void __XSData_Lock( XSDataRef Data ) +{ + if( XSData_IsMutable( Data ) ) + { + XSRecursiveLock_Lock( Data->lock ); + } +} diff --git a/XSFoundation/source/XS/Classes/XSData/__XSData_ToString.c b/XSFoundation/source/XS/Classes/XSData/__XSData_ToString.c index 8484ddf8..fd227e8b 100644 --- a/XSFoundation/source/XS/Classes/XSData/__XSData_ToString.c +++ b/XSFoundation/source/XS/Classes/XSData/__XSData_ToString.c @@ -73,16 +73,11 @@ const char * __XSData_ToString( XSDataRef object ) { - ( void )object; - - return NULL; - - /* XSStringRef description; const XSUInt8 * bytes; XSUInteger length; - XSRecursiveLock_Lock( object->lock ); + __XSData_Lock( object ); length = object->length; bytes = object->buffer; @@ -99,8 +94,7 @@ const char * __XSData_ToString( XSDataRef object ) description = XSString_StringByAppendingCString( description, ">" ); - XSRecursiveLock_Unlock( object->lock ); + __XSData_Unlock( object ); return XSString_GetCString( description ); - */ } diff --git a/XSFoundation/source/XS/Classes/XSData/__XSData_Unlock.c b/XSFoundation/source/XS/Classes/XSData/__XSData_Unlock.c new file mode 100644 index 00000000..28867b6a --- /dev/null +++ b/XSFoundation/source/XS/Classes/XSData/__XSData_Unlock.c @@ -0,0 +1,80 @@ +/******************************************************************************* + * XSFoundation - XEOS C Foundation Library + * + * Copyright (c) 2010-2014, Jean-David Gadina - www.xs-labs.com + * All rights reserved. + * + * XEOS Software License - Version 1.0 - December 21, 2012 + * + * Permission is hereby granted, free of charge, to any person or organisation + * obtaining a copy of the software and accompanying documentation covered by + * this license (the "Software") to deal in the Software, with or without + * modification, without restriction, including without limitation the rights + * to use, execute, display, copy, reproduce, transmit, publish, distribute, + * modify, merge, prepare derivative works of the Software, and to permit + * third-parties to whom the Software is furnished to do so, all subject to the + * following conditions: + * + * 1. Redistributions of source code, in whole or in part, must retain the + * above copyright notice and this entire statement, including the + * above license grant, this restriction and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright + * notice and this entire statement, including the above license grant, + * this restriction and the following disclaimer in the documentation + * and/or other materials provided with the distribution, unless the + * Software is distributed by the copyright owner as a library. + * A "library" means a collection of software functions and/or data + * prepared so as to be conveniently linked with application programs + * (which use some of those functions and data) to form executables. + * + * 3. The Software, or any substancial portion of the Software shall not + * be combined, included, derived, or linked (statically or + * dynamically) with software or libraries licensed under the terms + * of any GNU software license, including, but not limited to, the GNU + * General Public License (GNU/GPL) or the GNU Lesser General Public + * License (GNU/LGPL). + * + * 4. All advertising materials mentioning features or use of this + * software must display an acknowledgement stating that the product + * includes software developed by the copyright owner. + * + * 5. Neither the name of the copyright owner nor the names of its + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT OWNER AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE, TITLE AND NON-INFRINGEMENT ARE DISCLAIMED. + * + * IN NO EVENT SHALL THE COPYRIGHT OWNER, CONTRIBUTORS OR ANYONE DISTRIBUTING + * THE SOFTWARE BE LIABLE FOR ANY CLAIM, DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; + * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN ACTION OF CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF OR IN CONNECTION WITH + * THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE, EVEN IF ADVISED + * OF THE POSSIBILITY OF SUCH DAMAGE. + ******************************************************************************/ + +/* $Id$ */ + +/*! + * @file __XSData_Unlock.c + * @copyright (c) 2010-2014 - Jean-David Gadina - www.xs-labs.com + * @author Jean-David Gadina - www.xs-labs.com + * @abstract Definition for __XSData_Unlock + */ + +#include +#include + +void __XSData_Unlock( XSDataRef Data ) +{ + if( XSData_IsMutable( Data ) ) + { + XSRecursiveLock_Unlock( Data->lock ); + } +}