From 6f6c2694dc7c07bca5086c77ef29f3793e0c61c2 Mon Sep 17 00:00:00 2001
From: Iain Sandoe <iain@sandoe.co.uk>
Date: Sun, 6 Apr 2025 14:56:20 +0100
Subject: [PATCH] cobol: Address some iconv issues.

Darwin/macOS installed libiconv does not accept // trailers on
conversion codes; this causes the init_iconv to fail - and then
that SEGVs later.

Remove the trailing // as it is not needed elsewhere.
Also print a warning if we fail to init the conversion.

gcc/cobol/ChangeLog:

	* symbols.cc : Remove trailing // on standard_internal.
	(cbl_field_t::internalize): Print a warning if we fail to
	initialise iconv.

Signed-off-by: Iain Sandoe <iain@sandoe.co.uk>
---
 gcc/cobol/symbols.cc | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)

diff --git a/gcc/cobol/symbols.cc b/gcc/cobol/symbols.cc
index 50431251a0f..4067459858c 100644
--- a/gcc/cobol/symbols.cc
+++ b/gcc/cobol/symbols.cc
@@ -3567,7 +3567,7 @@ cbl_field_t::is_ascii() const {
  * compilation, if it moves off the default, it adjusts only once, and
  * never reverts.
  */
-static const char standard_internal[] = "CP1252//";
+static const char standard_internal[] = "CP1252";
 extern os_locale_t os_locale;
 
 static const char *
@@ -3595,6 +3595,10 @@ cbl_field_t::internalize() {
   static  iconv_t cd = iconv_open(tocode, fromcode);
   static const size_t noconv = size_t(-1);
 
+  if (cd == (iconv_t)-1) {
+    yywarn("failed iconv_open tocode = '%s' fromcode = %s", tocode, fromcode);
+  }
+
   // Sat Mar 16 11:45:08 2024: require temporary environment for testing
   if( getenv( "INTERNALIZE_NO") ) return data.initial;
 
-- 
2.39.2 (Apple Git-143)

