@@ -1,7 +1,7 @@ /* - * Copyright (c) 2008-2021 Jonathan Schleifer + * Copyright (c) 2008-2022 Jonathan Schleifer * * All rights reserved. * * This file is part of ObjFW. It may be distributed under the terms of the * Q Public License 1.0, which can be found in the file LICENSE.QPL included in @@ -43,15 +43,15 @@ * for OFData with item size 1. */ @interface OFData: OFObject { - unsigned char *_items; + unsigned char *_Nullable _items; size_t _count, _itemSize; bool _freeWhenDone; @private - OFData *_parentData; + OFData *_Nullable _parentData; OF_RESERVE_IVARS(OFData, 4) } /** * @brief The size of a single item in the OFData in bytes. @@ -66,11 +66,12 @@ /** * @brief All elements of the OFData as a C array. * * @warning The pointer is only valid until the OFData is changed! */ -@property (readonly, nonatomic) const void *items OF_RETURNS_INNER_POINTER; +@property OF_NULLABLE_PROPERTY (readonly, nonatomic) const void *items + OF_RETURNS_INNER_POINTER; /** * @brief The first item of the OFData or `NULL`. */ @property OF_NULLABLE_PROPERTY (readonly, nonatomic) const void *firstItem @@ -118,10 +119,13 @@ itemSize: (size_t)itemSize; /** * @brief Creates a new OFData with the specified `count` items of size 1 by * taking over ownership of the specified items pointer. + * + * If initialization fails for whatever reason, the passed memory is *not* + * free'd if `freeWhenDone` is true. * * @param items The items to store in the OFData * @param count The number of items * @param freeWhenDone Whether to free the pointer when it is no longer needed * by the OFData @@ -132,10 +136,13 @@ freeWhenDone: (bool)freeWhenDone; /** * @brief Creates a new OFData with the specified `count` items of the * specified size by taking ownership of the specified items pointer. + * + * If initialization fails for whatever reason, the passed memory is *not* + * free'd if `freeWhenDone` is true. * * @param items The items to store in the OFData * @param count The number of items * @param itemSize The item size of a single item in bytes * @param freeWhenDone Whether to free the pointer when it is no longer needed @@ -167,13 +174,13 @@ */ + (instancetype)dataWithContentsOfURL: (OFURL *)URL; /** * @brief Creates a new OFData with an item size of 1, containing the data of - * the string representation. + * the hex string representation. * - * @param string The string representation of the data + * @param string The hex string representation of the data * @return A new autoreleased OFData */ + (instancetype)dataWithStringRepresentation: (OFString *)string; /** @@ -184,21 +191,21 @@ * @return A new autoreleased OFData */ + (instancetype)dataWithBase64EncodedString: (OFString *)string; /** - * @brief Initialized an already allocated OFData with the specified `count` + * @brief Initializes an already allocated OFData with the specified `count` * items of size 1. * * @param items The items to store in the OFData * @param count The number of items * @return An initialized OFData */ - (instancetype)initWithItems: (const void *)items count: (size_t)count; /** - * @brief Initialized an already allocated OFData with the specified `count` + * @brief Initializes an already allocated OFData with the specified `count` * items of the specified size. * * @param items The items to store in the OFData * @param count The number of items * @param itemSize The item size of a single item in bytes @@ -210,10 +217,13 @@ /** * @brief Initializes an already allocated OFData with the specified `count` * items of size 1 by taking over ownership of the specified items * pointer. + * + * If initialization fails for whatever reason, the passed memory is *not* + * free'd if `freeWhenDone` is true. * * @param items The items to store in the OFData * @param count The number of items * @param freeWhenDone Whether to free the pointer when it is no longer needed * by the OFData @@ -225,10 +235,13 @@ /** * @brief Initializes an already allocated OFData with the specified `count` * items of the specified size by taking ownership of the specified * items pointer. + * + * If initialization fails for whatever reason, the passed memory is *not* + * free'd if `freeWhenDone` is true. * * @param items The items to store in the OFData * @param count The number of items * @param itemSize The item size of a single item in bytes * @param freeWhenDone Whether to free the pointer when it is no longer needed @@ -260,13 +273,13 @@ */ - (instancetype)initWithContentsOfURL: (OFURL *)URL; /** * @brief Initializes an already allocated OFData with an item size of 1, - * containing the data of the string representation. + * containing the data of the hex string representation. * - * @param string The string representation of the data + * @param string The hex string representation of the data * @return A new autoreleased OFData */ - (instancetype)initWithStringRepresentation: (OFString *)string; /**