ObjFW  Check-in [c5e7dd679b]

Overview
Comment:Work around Android bugs.

Includes:
* Check environ against NULL before using it, since Android sets it to
NULL.
* Cast st_size of struct stat to off_t. Android uses long long for
st_size as its off_t is only 32 bit, but st_size should be off_t
according to POSIX.
* Android's strtod() does not accept 0x, as specified by C99. Thus,
the test is disabled if __ANDROID__ is defined.

Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA3-256: c5e7dd679b8343fa877a6ceef98a9b67188aada3ce479108cd67176916f22f8f
User & Date: js on 2013-09-17 16:12:37
Other Links: manifest | tags
Context
2013-09-17
16:51
tests/Makefile: Add run-on-android target. check-in: c7b788abab user: js tags: trunk
16:12
Work around Android bugs. check-in: c5e7dd679b user: js tags: trunk
14:14
Only compare with PTHREAD_CANCELED if defined. check-in: 2ac6cc1247 user: js tags: trunk
Changes

Modified src/OFApplication.m from [65cd40e6d2] to [91fefa5006].

220
221
222
223
224
225
226

227
228
229





230
231

232
233
234
235
236
237





238
239
240
241
242
243
244
245







246
247
248


249
250


251
252
253
254
255
256
257
220
221
222
223
224
225
226
227



228
229
230
231
232
233

234
235





236
237
238
239
240
241







242
243
244
245
246
247
248
249


250
251
252

253
254
255
256
257
258
259
260
261







+
-
-
-
+
+
+
+
+

-
+

-
-
-
-
-
+
+
+
+
+

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

-
-
+
+

-
+
+







					forKey: key];

			objc_autoreleasePoolPop(pool);
		}

		FreeEnvironmentStringsW(env);
#elif !defined(OF_IOS)
		if (env != NULL) {
		for (; *env != NULL; env++) {
			OFString *key, *value;
			char *sep;
			for (; *env != NULL; env++) {
				OFString *key, *value;
				char *sep;
				const of_string_encoding_t encoding =
				    OF_STRING_ENCODING_NATIVE;

			pool = objc_autoreleasePoolPush();
				pool = objc_autoreleasePoolPush();

			if ((sep = strchr(*env, '=')) == NULL) {
				fprintf(stderr, "Warning: Invalid environment "
				    "variable: %s\n", *env);
				continue;
			}
				if ((sep = strchr(*env, '=')) == NULL) {
					fprintf(stderr, "Warning: Invalid "
					    "environment variable: %s\n", *env);
					continue;
				}

			key = [OFString
			    stringWithCString: *env
				     encoding: OF_STRING_ENCODING_NATIVE
				       length: sep - *env];
			value = [OFString
			    stringWithCString: sep + 1
				     encoding: OF_STRING_ENCODING_NATIVE];
				key = [OFString
				    stringWithCString: *env
					     encoding: encoding
					       length: sep - *env];
				value = [OFString
				    stringWithCString: sep + 1
					     encoding: encoding];

			[environment setObject: value
					forKey: key];
				[environment setObject: value
						forKey: key];

			objc_autoreleasePoolPop(pool);
				objc_autoreleasePoolPop(pool);
			}
		}
#else
		/*
		 * iOS does not provide environ and Apple does not allow using
		 * _NSGetEnviron on iOS. Therefore, we just get a few common
		 * variables from the environment which applications might
		 * expect.

Modified src/OFFile.m from [6d3006c532] to [1f1aa20392].

403
404
405
406
407
408
409

410

411
412
413
414
415
416
417
403
404
405
406
407
408
409
410

411
412
413
414
415
416
417
418







+
-
+








	if (_wstat([path UTF16String], &s) == -1)
#endif
		/* FIXME: Maybe use another exception? */
		@throw [OFOpenFileFailedException exceptionWithPath: path
							       mode: @"r"];

	/* On Android, off_t is 32 bit, but st_size is long long there */
	return s.st_size;
	return (off_t)s.st_size;
}

+ (OFDate*)modificationDateOfFileAtPath: (OFString*)path
{
	if (path == nil)
		@throw [OFInvalidArgumentException exception];

Modified tests/OFStringTests.m from [b0a9478f37] to [3c7c95496c].

375
376
377
378
379
380
381

382
383




384
385
386
387
388
389
390
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395







+


+
+
+
+







	 */
	TEST(@"-[floatValue]",
	    [@"\t-0.25 " floatValue] == -0.25 &&
	    [@"\r-INFINITY\n" floatValue] == -INFINITY &&
	    isnan([@"   NAN\t\t" floatValue]))

	TEST(@"-[doubleValue]",
#ifndef __ANDROID__
	    [@"\t-0x1.FFFFFFFFFFFFFP-1020 " doubleValue] ==
	    -0x1.FFFFFFFFFFFFFP-1020 &&
#else
	    /* strtod() does not accept 0x on Android */
	    [@"\t-0.123456789 " doubleValue] == -0.123456789 &&
#endif
	    [@"\r-INFINITY\n" doubleValue] == -INFINITY &&
	    isnan([@"   NAN\t\t" doubleValue]))

	EXPECT_EXCEPTION(@"Detect invalid characters in -[decimalValue] #1",
	    OFInvalidFormatException, [@"abc" decimalValue])
	EXPECT_EXCEPTION(@"Detect invalid characters in -[decimalValue] #2",
	    OFInvalidFormatException, [@"0a" decimalValue])