Skip to contentSkip to conversation

Add support for printf formatting with non-monetary grouping chars

PATCH In review [email protected] 2 participants 3 messages Jan 14

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 Add support for printf formatting with non-monetary grouping chars

From: Eugene Loh <[email protected]>

Non-monetary grouping characters are used to separate groups of digits in numbers that are not monetary values. DTrace used to document support for printf formatting, using a single quote, for such grouping.

Add such support.

Orabug: 30430270

---
 cmd/dtrace.c                         |  5 ++++-
 test/unittest/printf/tst.grouping.r  |  5 +++++
 test/unittest/printf/tst.grouping.sh | 29 ++++++++++++++++++++++++++++
 test/unittest/printf/tst.grouping.x  | 13 +++++++++++++
 4 files changed, 51 insertions(+), 1 deletion(-)
 create mode 100644 test/unittest/printf/tst.grouping.r
 create mode 100755 test/unittest/printf/tst.grouping.sh
 create mode 100755 test/unittest/printf/tst.grouping.x
cmd/dtrace.c +4 -1
index baa73e9d7..6cd7aeadb 100644
@@ -1,6 +1,6 @@
 /*
  * Oracle Linux DTrace.
- * Copyright (c) 2006, 2025, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2006, 2026, Oracle and/or its affiliates. All rights reserved.
  * Licensed under the Universal Permissive License v 1.0 as shown at
  * http://oss.oracle.com/licenses/upl.
  */
@@ -9,6 +9,7 @@
 #include <sys/stat.h>
 #include <sys/wait.h>
 #include <sys/compiler.h>
+#include <locale.h>
 
 #include <dtrace.h>
 #include <stdlib.h>
@@ -924,6 +925,8 @@ main(int argc, char *argv[])
 	pid_t pid;
 	struct dtrace_proc *proc;
 
+	setlocale(LC_NUMERIC, "");
+
 	g_ofp = stdout;
 
 	g_pname = basename(argv[0]);
test/unittest/printf/tst.grouping.r new file +5 -0
new file mode 100644
index 000000000..077a0b7f9
@@ -0,0 +1,5 @@
+123456789
+
+123,456,789
+
+success
test/unittest/printf/tst.grouping.sh new file +29 -0
new file mode 100755
index 000000000..13b953758
@@ -0,0 +1,29 @@
+#!/bin/bash
+#
+# Oracle Linux DTrace.
+# Copyright (c) 2026, Oracle and/or its affiliates. All rights reserved.
+# Licensed under the Universal Permissive License v 1.0 as shown at
+# http://oss.oracle.com/licenses/upl.
+#
+
+dtrace=$1
+
+for mylocale in C en_US.UTF-8; do
+	export LC_ALL=$mylocale
+
+	$dtrace $dt_flags -qs /dev/stdin << EOF
+	BEGIN
+	{
+		printf("%'d\n", 123456789);
+		exit(0);
+	}
+EOF
+	if [ $? -ne 0 ]; then
+		echo ERROR: dtrace
+		locale
+		exit 1
+	fi
+done
+
+echo success
+exit 0
test/unittest/printf/tst.grouping.x new file +13 -0
new file mode 100755
index 000000000..9993fbcd3
@@ -0,0 +1,13 @@
+#!/bin/bash
+#
+# Oracle Linux DTrace.
+# Copyright (c) 2026, Oracle and/or its affiliates. All rights reserved.
+# Licensed under the Universal Permissive License v 1.0 as shown at
+# http://oss.oracle.com/licenses/upl.
+
+if locale -a | grep en_US.utf8 ; then
+	exit 0
+fi
+
+echo install glibc-langpack-en yum package for this test
+exit 2
Signature · 1 line
2.47.3
#1 lore raw

I would update the commit summary (one liner) to state that this patch fixes the non-monetary goruping rather than adding support. The code was there to implement it - the only thing we missed was the setlocale() call to ensure that setting the locale with an env var would actually have an effect.

Quoted 8 lines · On Wed, Jan 14, 2026 at 12:09:36AM -0500, [email protected] wrote:

From: Eugene Loh <[email protected]>

Non-monetary grouping characters are used to separate groups of digits in numbers that are not monetary values. DTrace used to document support for printf formatting, using a single quote, for such grouping.

Add such support.

This is also a bit misleading I think. Not only does DTrace cocument the support - the code actually supports it. Just the setlocale() call was missing.

I think the commit message should point that out rather than potentially giving the impression that this patch implements it.

Quoted 60 lines

Orabug: 30430270

---
 cmd/dtrace.c                         |  5 ++++-
 test/unittest/printf/tst.grouping.r  |  5 +++++
 test/unittest/printf/tst.grouping.sh | 29 ++++++++++++++++++++++++++++
 test/unittest/printf/tst.grouping.x  | 13 +++++++++++++
 4 files changed, 51 insertions(+), 1 deletion(-)
 create mode 100644 test/unittest/printf/tst.grouping.r
 create mode 100755 test/unittest/printf/tst.grouping.sh
 create mode 100755 test/unittest/printf/tst.grouping.x
cmd/dtrace.c +4 -1
index baa73e9d7..6cd7aeadb 100644
@@ -1,6 +1,6 @@
 /*
  * Oracle Linux DTrace.
- * Copyright (c) 2006, 2025, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2006, 2026, Oracle and/or its affiliates. All rights reserved.
  * Licensed under the Universal Permissive License v 1.0 as shown at
  * http://oss.oracle.com/licenses/upl.
  */
@@ -9,6 +9,7 @@
 #include <sys/stat.h>
 #include <sys/wait.h>
 #include <sys/compiler.h>
+#include <locale.h>
 
 #include <dtrace.h>
 #include <stdlib.h>
@@ -924,6 +925,8 @@ main(int argc, char *argv[])
 	pid_t pid;
 	struct dtrace_proc *proc;
 
+	setlocale(LC_NUMERIC, "");
+
 	g_ofp = stdout;
 
 	g_pname = basename(argv[0]);
test/unittest/printf/tst.grouping.r new file +5 -0
new file mode 100644
index 000000000..077a0b7f9
@@ -0,0 +1,5 @@
+123456789
+
+123,456,789
+
+success
test/unittest/printf/tst.grouping.sh new file +2 -0
new file mode 100755
index 000000000..13b953758
@@ -0,0 +1,29 @@
+#!/bin/bash
+#

test/unittest/printf/tst.grouping.sh line 12

Quoted 10 lines
test/unittest/printf/tst.grouping.sh new file +10 -0
+# Oracle Linux DTrace.
+# Copyright (c) 2026, Oracle and/or its affiliates. All rights reserved.
+# Licensed under the Universal Permissive License v 1.0 as shown at
+# http://oss.oracle.com/licenses/upl.
+#
+
+dtrace=$1
+
+for mylocale in C en_US.UTF-8; do
+	export LC_ALL=$mylocale

Shouldn't you test both LC_ALL and LC_NUMERIC, especially since many sources seem to suggest that setting LC_ALL is a bad idea, and that people should set the specific sub-areas they need (since LC_ALL is an override for all and might have other effects people do not intend).

Quoted 39 lines
test/unittest/printf/tst.grouping.sh new file +17 -0
+
+	$dtrace $dt_flags -qs /dev/stdin << EOF
+	BEGIN
+	{
+		printf("%'d\n", 123456789);
+		exit(0);
+	}
+EOF
+	if [ $? -ne 0 ]; then
+		echo ERROR: dtrace
+		locale
+		exit 1
+	fi
+done
+
+echo success
+exit 0
test/unittest/printf/tst.grouping.x new file +13 -0
new file mode 100755
index 000000000..9993fbcd3
@@ -0,0 +1,13 @@
+#!/bin/bash
+#
+# Oracle Linux DTrace.
+# Copyright (c) 2026, Oracle and/or its affiliates. All rights reserved.
+# Licensed under the Universal Permissive License v 1.0 as shown at
+# http://oss.oracle.com/licenses/upl.
+
+if locale -a | grep en_US.utf8 ; then
+	exit 0
+fi
+
+echo install glibc-langpack-en yum package for this test
+exit 2
Signature · 1 line
2.47.3
author
#2 lore raw

On wording and testing... gotcha.  I'm rescinding this patch. The replacement will have a slightly different title.

Quoted 135 lines · Kris Van Hees

I would update the commit summary (one liner) to state that this patch fixes the non-monetary goruping rather than adding support. The code was there to implement it - the only thing we missed was the setlocale() call to ensure that setting the locale with an env var would actually have an effect.

Quoted 8 lines · On Wed, Jan 14, 2026 at 12:09:36AM -0500, [email protected] wrote:

From: Eugene Loh <[email protected]>

Non-monetary grouping characters are used to separate groups of digits in numbers that are not monetary values. DTrace used to document support for printf formatting, using a single quote, for such grouping.

Add such support.

This is also a bit misleading I think. Not only does DTrace cocument the support - the code actually supports it. Just the setlocale() call was missing.

I think the commit message should point that out rather than potentially giving the impression that this patch implements it.

Quoted 60 lines

Orabug: 30430270

---
  cmd/dtrace.c                         |  5 ++++-
  test/unittest/printf/tst.grouping.r  |  5 +++++
  test/unittest/printf/tst.grouping.sh | 29 ++++++++++++++++++++++++++++
  test/unittest/printf/tst.grouping.x  | 13 +++++++++++++
  4 files changed, 51 insertions(+), 1 deletion(-)

create mode 100644 test/unittest/printf/tst.grouping.r create mode 100755 test/unittest/printf/tst.grouping.sh create mode 100755 test/unittest/printf/tst.grouping.x

cmd/dtrace.c +4 -1
index baa73e9d7..6cd7aeadb 100644
@@ -1,6 +1,6 @@
  /*
   * Oracle Linux DTrace.
- * Copyright (c) 2006, 2025, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2006, 2026, Oracle and/or its affiliates. All rights reserved.
   * Licensed under the Universal Permissive License v 1.0 as shown at
   * http://oss.oracle.com/licenses/upl.
   */
@@ -9,6 +9,7 @@
  #include <sys/stat.h>
  #include <sys/wait.h>
  #include <sys/compiler.h>
+#include <locale.h>
 
  #include <dtrace.h>
  #include <stdlib.h>
@@ -924,6 +925,8 @@ main(int argc, char *argv[])
  	pid_t pid;
  	struct dtrace_proc *proc;
 
+	setlocale(LC_NUMERIC, "");
+
  	g_ofp = stdout;
 
  	g_pname = basename(argv[0]);
test/unittest/printf/tst.grouping.r new file +5 -0
new file mode 100644
index 000000000..077a0b7f9
@@ -0,0 +1,5 @@
+123456789
+
+123,456,789
+
+success
test/unittest/printf/tst.grouping.sh new file +2 -0
new file mode 100755
index 000000000..13b953758
@@ -0,0 +1,29 @@
+#!/bin/bash
+#

test/unittest/printf/tst.grouping.sh line 12

Quoted 10 lines
test/unittest/printf/tst.grouping.sh new file +10 -0
+# Oracle Linux DTrace.
+# Copyright (c) 2026, Oracle and/or its affiliates. All rights reserved.
+# Licensed under the Universal Permissive License v 1.0 as shown at
+# http://oss.oracle.com/licenses/upl.
+#
+
+dtrace=$1
+
+for mylocale in C en_US.UTF-8; do
+	export LC_ALL=$mylocale

Shouldn't you test both LC_ALL and LC_NUMERIC, especially since many sources seem to suggest that setting LC_ALL is a bad idea, and that people should set the specific sub-areas they need (since LC_ALL is an override for all and might have other effects people do not intend).

Quoted 39 lines
test/unittest/printf/tst.grouping.sh new file +17 -0
+
+	$dtrace $dt_flags -qs /dev/stdin << EOF
+	BEGIN
+	{
+		printf("%'d\n", 123456789);
+		exit(0);
+	}
+EOF
+	if [ $? -ne 0 ]; then
+		echo ERROR: dtrace
+		locale
+		exit 1
+	fi
+done
+
+echo success
+exit 0
test/unittest/printf/tst.grouping.x new file +13 -0
new file mode 100755
index 000000000..9993fbcd3
@@ -0,0 +1,13 @@
+#!/bin/bash
+#
+# Oracle Linux DTrace.
+# Copyright (c) 2026, Oracle and/or its affiliates. All rights reserved.
+# Licensed under the Universal Permissive License v 1.0 as shown at
+# http://oss.oracle.com/licenses/upl.
+
+if locale -a | grep en_US.utf8 ; then
+	exit 0
+fi
+
+echo install glibc-langpack-en yum package for this test
+exit 2
Signature · 1 line
2.47.3