ObjFW  Diff

Differences From Artifact [ab9d9164f8]:

To Artifact [7044157852]:

  • File src/OFString.m — part of check-in [0f260e0fd5] at 2020-11-06 02:37:02 on branch trunk — OFString: Make freeWhenDone behave like in OFData

    In particular, this means that if initialization fails, the buffer is
    NOT free'd. While freeing it on error in convenient when not handling
    the error, it makes handling the error and retrying impossible (e.g.
    retrying with a different encoding). (user: js, size: 65913) [annotate] [blame] [check-ins using]


832
833
834
835
836
837
838
839

840
841
842
843
844
845


846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862





863
864
865
866
867
868
869
870
832
833
834
835
836
837
838

839
840





841
842

843
844
845
846
847
848
849
850








851
852
853
854
855

856
857
858
859
860
861
862







-
+

-
-
-
-
-
+
+
-








-
-
-
-
-
-
-
-
+
+
+
+
+
-







			    encoding: OF_STRING_ENCODING_UTF_8
			      length: UTF8StringLength];
}

- (instancetype)initWithUTF8StringNoCopy: (char *)UTF8String
			    freeWhenDone: (bool)freeWhenDone
{
	id ret;
	id ret = [self initWithUTF8String: UTF8String];

	@try {
		ret = [self initWithUTF8String: UTF8String];
	} @finally {
		if (freeWhenDone)
			free(UTF8String);
	if (freeWhenDone)
		free(UTF8String);
	}

	return ret;
}

- (instancetype)initWithUTF8StringNoCopy: (char *)UTF8String
				  length: (size_t)UTF8StringLength
			    freeWhenDone: (bool)freeWhenDone
{
	id ret;

	@try {
		ret = [self initWithUTF8String: UTF8String
					length: UTF8StringLength];
	} @finally {
		if (freeWhenDone)
			free(UTF8String);
	id ret = [self initWithUTF8String: UTF8String
				   length: UTF8StringLength];

	if (freeWhenDone)
		free(UTF8String);
	}

	return ret;
}

- (instancetype)initWithCString: (const char *)cString
		       encoding: (of_string_encoding_t)encoding
{