This is the mail archive of the
libc-alpha@sourceware.org
mailing list for the glibc project.
Re: [PATCH 2/3] Support run bug-setlocale1 directly
- From: "H.J. Lu" <hjl dot tools at gmail dot com>
- To: Roland McGrath <roland at hack dot frob dot com>
- Cc: GNU C Library <libc-alpha at sourceware dot org>
- Date: Thu, 10 Jan 2013 14:04:30 -0800
- Subject: Re: [PATCH 2/3] Support run bug-setlocale1 directly
- References: <20121221005321.GB25282@intel.com><20130110194955.E32982C0B6@topped-with-meat.com>
On Thu, Jan 10, 2013 at 11:49 AM, Roland McGrath <roland@hack.frob.com> wrote:
>> - newargv[1] = (char *) "--library-path";
>> - newargv[2] = argv[1];
>> - newargv[3] = argv[0];
>> - newargv[4] = NULL;
>> +
>> + if (argc == 2)
>> + {
>> + newargv[0] = argv[0];
>> + newargv[1] = NULL;
>> + }
>> + else
>> + {
>> + newargv[0] = argv[1];
>> + newargv[1] = argv[2];
>> + newargv[2] = argv[3];
>> + newargv[3] = argv[4];
>> + newargv[4] = NULL;
>> + }
>
> Use either a loop or memcpy to make this less repetitive.
Here is the updated patch with a static testcase I am
checking in.
Thanks.
--
H.J.
---
2013-01-10 H.J. Lu <hongjiu.lu@intel.com>
* Makefile (tests-static): New variable.
(tests): Add $(tests-static).
(bug-setlocale1-ARGS): Set to -- $(built-program-cmd).
(bug-setlocale1-static-ENV): New variable.
(bug-setlocale1-static-ARGS): Likewise.
* bug-setlocale1.c (do_test): Support run directly. Check env[1]
instead of newargv[0].
* bug-setlocale1-static.c: New file.
diff --git a/localedata/Makefile b/localedata/Makefile
index d9f66c5..9239164 100644
--- a/localedata/Makefile
+++ b/localedata/Makefile
@@ -78,6 +78,8 @@ locale_test_suite := tst_iswalnum tst_iswalpha
tst_iswcntrl \
tests = $(locale_test_suite) tst-digits tst-setlocale bug-iconv-trans \
tst-leaks tst-mbswcs6 tst-xlocale1 tst-xlocale2 bug-usesetlocale \
tst-strfmon1 tst-sscanf bug-setlocale1 tst-setlocale2
+tests-static = bug-setlocale1-static
+tests += $(tests-static)
ifeq (yes,$(build-shared))
ifneq (no,$(PERL))
tests: $(objpfx)mtrace-tst-leaks
@@ -285,7 +287,9 @@ $(objpfx)mtrace-tst-leaks: $(objpfx)tst-leaks.out
$(common-objpfx)malloc/mtrace $(objpfx)tst-leaks.mtrace > $@
bug-setlocale1-ENV = LOCPATH=$(common-objpfx)localedata
-bug-setlocale1-ARGS = $(common-objpfx)
+bug-setlocale1-ARGS = -- $(built-program-cmd)
+bug-setlocale1-static-ENV = $(bug-setlocale1-ENV)
+bug-setlocale1-static-ARGS = $(bug-setlocale1-ARGS)
tst-setlocale2-ENV = LOCPATH=$(common-objpfx)localedata
$(objdir)/iconvdata/gconv-modules:
diff --git a/localedata/bug-setlocale1-static.c
b/localedata/bug-setlocale1-static.c
new file mode 100644
index 0000000..f37177b
--- /dev/null
+++ b/localedata/bug-setlocale1-static.c
@@ -0,0 +1 @@
+#include "bug-setlocale1.c"
diff --git a/localedata/bug-setlocale1.c b/localedata/bug-setlocale1.c
index cf787be..dc7f6f3 100644
--- a/localedata/bug-setlocale1.c
+++ b/localedata/bug-setlocale1.c
@@ -12,16 +12,16 @@ do_test (int argc, char *argv[])
if (argc > 1)
{
char *newargv[5];
- asprintf (&newargv[0], "%self/ld.so", argv[1]);
- if (newargv[0] == NULL)
+ int i;
+ if (argc != 2 && argc != 5)
{
- puts ("asprintf failed");
+ printf ("wrong number of arguments (%d)\n", argc);
return 1;
}
- newargv[1] = (char *) "--library-path";
- newargv[2] = argv[1];
- newargv[3] = argv[0];
- newargv[4] = NULL;
+
+ for (i = 0; i < (argc == 5 ? 4 : 1); i++)
+ newargv[i] = argv[i + 1];
+ newargv[i] = NULL;
char *env[3];
env[0] = (char *) "LC_CTYPE=de_DE.UTF-8";
@@ -32,9 +32,9 @@ do_test (int argc, char *argv[])
return 1;
}
asprintf (&env[1], "LOCPATH=%s", loc);
- if (newargv[0] == NULL)
+ if (env[1] == NULL)
{
- puts ("second asprintf failed");
+ puts ("asprintf failed");
return 1;
}
env[2] = NULL;
--