ObjFW  Check-in [df2ee1f2f9]

Overview
Comment:Fix using asprintf_l
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA3-256: df2ee1f2f974220673a4f83e829ed8af40edd7d10ca8f896890b439d17f4b478
User & Date: js on 2017-03-12 01:33:01
Other Links: manifest | tags
Context
2017-03-12
01:37
configure: Define _GNU_SOURCE for newlib check-in: 8c712272d2 user: js tags: trunk
01:33
Fix using asprintf_l check-in: df2ee1f2f9 user: js tags: trunk
01:06
OFLocalization: Handle nil language / territory check-in: 58c2a71294 user: js tags: trunk
Changes

Modified configure.ac from [abed6f0dda] to [6c231caadc].

926
927
928
929
930
931
932
933

934
935
936
937
938
939
940
926
927
928
929
930
931
932

933
934
935
936
937
938
939
940







-
+







	])
	OBJCFLAGS="$old_OBJCFLAGS"
])

AC_CHECK_FUNCS([sysconf gmtime_r localtime_r nanosleep fcntl])

AC_CHECK_HEADERS(xlocale.h)
AC_CHECK_FUNCS([strtod_l strtof_l vasprintf_l])
AC_CHECK_FUNCS([strtod_l strtof_l asprintf_l])

AC_CHECK_FUNC(pipe, [
	AC_DEFINE(OF_HAVE_PIPE, 1, [Whether we have pipe()])
])

AC_ARG_ENABLE(sockets,
	AS_HELP_STRING([--disable-sockets], [disable socket support]))

Modified src/of_asprintf.m from [096a7db2b7] to [c0ebec1591].

78
79
80
81
82
83
84
85

86
87
88
89
90
91
92
78
79
80
81
82
83
84

85
86
87
88
89
90
91
92







-
+







	} lengthModifier;
	bool useLocale;
};

#ifdef HAVE_ASPRINTF_L
static locale_t cLocale;

static void __attribute__((init))
static void __attribute__((constructor))
init(void)
{
	if ((cLocale = newlocale(LC_ALL_MASK, "C", NULL)) == NULL)
		@throw [OFInitializationFailedException exception];
}
#endif

510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526









527

528
529

530
531

532
533
534
535
536
537
538
539
540
541
542







543
544
545



546
547
548
549
550

551
552
553
554
555
556
557
510
511
512
513
514
515
516










517
518
519
520
521
522
523
524
525

526
527

528


529











530
531
532
533
534
535
536



537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552







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

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





+







	case 'F':
	case 'e':
	case 'E':
	case 'g':
	case 'G':
	case 'a':
	case 'A':
#ifdef HAVE_ASPRINTF_L
		{
			locale_t locale = (ctx->useLocale ? NULL : cLocale);

			switch (ctx->lengthModifier) {
			case LENGTH_MODIFIER_NONE:
			case LENGTH_MODIFIER_L:
				tmpLen = asprintf(&tmp, ctx->subformat,
				    va_arg(ctx->arguments, double), locale);
				break;
		switch (ctx->lengthModifier) {
		case LENGTH_MODIFIER_NONE:
		case LENGTH_MODIFIER_L:
#ifdef HAVE_ASPRINTF_L
			if (!ctx->useLocale)
				tmpLen = asprintf_l(&tmp, cLocale,
				    ctx->subformat,
				    va_arg(ctx->arguments, double));
			else
			case LENGTH_MODIFIER_CAPITAL_L:
#endif
				tmpLen = asprintf(&tmp, ctx->subformat,
				    va_arg(ctx->arguments, long double),
				    va_arg(ctx->arguments, double));
				    locale);
				break;
			break;
			default:
				return false;
			}
		}
#else
		switch (ctx->lengthModifier) {
		case LENGTH_MODIFIER_NONE:
		case LENGTH_MODIFIER_L:
			tmpLen = asprintf(&tmp, ctx->subformat,
			    va_arg(ctx->arguments, double));
			break;
		case LENGTH_MODIFIER_CAPITAL_L:
#ifdef HAVE_ASPRINTF_L
			if (!ctx->useLocale)
				tmpLen = asprintf_l(&tmp, cLocale,
				    ctx->subformat,
				    va_arg(ctx->arguments, long double));
			else
		case LENGTH_MODIFIER_CAPITAL_L:
			tmpLen = asprintf(&tmp, ctx->subformat,
			    va_arg(ctx->arguments, long double));
#endif
				tmpLen = asprintf(&tmp, ctx->subformat,
				    va_arg(ctx->arguments, long double));
			break;
		default:
			return false;
		}

#ifndef HAVE_ASPRINTF_L
		/*
		 * If there's no asprintf_l, we have no other choice than to
		 * use this ugly hack to replace the locale's decimal point
		 * back to ".".
		 */
		if (!ctx->useLocale) {
			void *pool = objc_autoreleasePoolPush();