lang/gnu-apl: try to unbreak the port's build on recent -CURRENT

The base template for std::char_traits<> has been removed in LLVM 19;
specializations are only provided for char, wchar_t, char8_t, char16_t,
and char32_t.  This had severely impacted GNU APL which derived its
UTF8 and UCS string classes from std::basic_string<>.  The author had
made several attempts to convert these classes to use std::vector<>
instead.  Carefully cherry-pick required changes so these fixes could
be applied on top of version 1.8 as trunk had diverged significantly.

Obtained from:	upstream (SVN revisions 1823, 1831, and 1837)
Reported by:	pkg-fallout
This commit is contained in:
Alexey Dokuchaev
2025-06-04 06:51:24 +00:00
parent a11f845a82
commit 5baf43483c
9 changed files with 403 additions and 0 deletions
@@ -0,0 +1,29 @@
--- src/CDR_string.hh.orig 2019-06-23 12:39:20 UTC
+++ src/CDR_string.hh
@@ -73,7 +73,7 @@ class CDR_string : public std::vector<uint8_t> (public
/// return the bytes of this CDR
const uint8_t * get_items() const
- { return &front(); }
+ { return utf8P(&front()); }
/// return the header of this CDR
const CDR_header & header() const
@@ -92,7 +92,7 @@ class CDR_string : public std::vector<uint8_t> (public
/// return the ravel of this CDR
const uint8_t * ravel() const
- { return &(*this)[0] + 16 + 4*get_rank(); }
+ { return utf8P(&(*this)[0] + 16 + 4*get_rank()); }
/// return true if this CDR is bool or integer
bool is_integer() const
@@ -131,7 +131,7 @@ class CDR_string : public std::vector<uint8_t> (public
protected:
/// return 4 bytes of the header (the header is always big endian)
uint32_t get_4(unsigned int offset) const
- { return CDR_header::get_be32(&(*this)[0] + offset); }
+ { return CDR_header::get_be32(utf8P(&(*this)[0] + offset)); }
};
#endif // __CDR_STRING_HH_DEFINED__
+11
View File
@@ -0,0 +1,11 @@
--- src/InputFile.hh.orig 2019-06-23 12:39:20 UTC
+++ src/InputFile.hh
@@ -42,7 +42,7 @@ struct InputFile
InputFile(const UTF8_string & _filename, FILE * _file,
bool _test, bool _echo, bool _is_script, LX_mode LX)
: file (_file),
- filename (&_filename[0], _filename.size()),
+ filename (_filename),
test (_test),
echo (_echo),
is_script(_is_script),
+58
View File
@@ -0,0 +1,58 @@
--- src/LibPaths.cc.orig 2019-06-23 12:39:20 UTC
+++ src/LibPaths.cc
@@ -70,33 +70,22 @@ LibPaths::compute_bin_path(const char * argv0, bool lo
//
// we fix this by searching argv0 in $PATH
//
- const char * path = getenv("PATH"); // must NOT be modified
-
- if (path)
+ if (const char * paths = getenv("PATH"))
{
logit && CERR << "initializing paths from $PATH = "
- << path << endl;
+ << paths << endl;
- // we must not modify path, so we copy it to path1 and
- // replace the semicolons in path1 by 0. That converts
- // p1;p2; ... into a sequence of 0-terminated strings
- // p1 p2 ... The variable next points to the start of each
- // string.
- //
- const size_t plen = strlen(path);
- std::string path1;
- path1.reserve(plen + 1);
- loop(p, (plen + 1)) path1 += path[p];
- char * next = &path1[0];
- for (;;)
- {
- char * semi = strchr(next, ':');
- if (semi) *semi = 0;
- UTF8_string filename;
- for (const char * n = next; *n; ++n) filename += *n;
- filename += '/';
- for (const char * a = argv0; *a; ++a) filename += *a;
+ while (*paths)
+ {
+ size_t dir_len;
+ if (const char * colon = strchr(paths, ':'))
+ dir_len = colon - paths;
+ else
+ dir_len = strlen(paths);
+ std::string filename(paths, dir_len);
+ filename += '/';
+ filename.append(argv0);
if (access(filename.c_str(), X_OK) == 0)
{
strncpy(APL_bin_path, filename.c_str(),
@@ -110,8 +99,7 @@ LibPaths::compute_bin_path(const char * argv0, bool lo
goto done;
}
- if (semi == 0) break;
- next = semi + 1;
+ paths += dir_len + 1; // next $PATH item
}
}
else
+20
View File
@@ -0,0 +1,20 @@
--- src/Nabla.cc.orig 2019-06-23 12:39:20 UTC
+++ src/Nabla.cc
@@ -219,7 +219,7 @@ Nabla::start()
// ∇FUN[⎕]∇
// etc.
//
-UCS_string::iterator c(first_command.begin());
+UCS_string::iterator c(first_command);
// skip leading spaces
//
@@ -375,7 +375,7 @@ Nabla::parse_oper(UCS_string & oper, bool initial)
if (oper.size() == 0 && do_close) return 0;
-UCS_string::iterator c(oper.begin());
+UCS_string::iterator c(oper);
Unicode cc = c.next();
UCS_string text = oper;
while (cc == ' ') cc = c.next(); // skip leading whitespace
@@ -0,0 +1,13 @@
--- src/PrimitiveFunction.cc.orig 2019-06-23 12:39:20 UTC
+++ src/PrimitiveFunction.cc
@@ -2668,8 +2668,8 @@ Value_P Z(ShapeItem(line_starts.size() - 1), LOC);
else
len = result_utf8.size() - line_starts[l];
- UTF8_string line_utf8(&result_utf8[line_starts[l]], len);
- UCS_string line_ucs(line_utf8);
+ const UTF8_string line_utf8(utf8P(&result_utf8[line_starts[l]]), len);
+ const UCS_string line_ucs(line_utf8);
Value_P ZZ(line_ucs, LOC);
new (Z->next_ravel()) PointerCell(ZZ.get(), Z.getref());
}
+27
View File
@@ -0,0 +1,27 @@
--- src/Quad_CR.cc.orig 2019-06-23 12:39:20 UTC
+++ src/Quad_CR.cc
@@ -1041,17 +1041,15 @@ Value_P Z(utf, LOC);
Value_P
Quad_CR::do_CR19(const Value & B)
{
-UTF8_string utf(B);
- for (size_t l = 0; l < utf.size();)
- {
- int len = 0;
- const Unicode uni = UTF8_string::toUni(&utf[l], len, false);
- if (uni == Invalid_Unicode) DOMAIN_ERROR;
+ if (B.get_rank() > 1) RANK_ERROR;
+const ShapeItem len_B = B.element_count();
- l += len;
- }
+UTF8 bytes_utf[len_B + 10];
+ loop(b, len_B) bytes_utf[b] = B.get_ravel(b).get_byte_value();
+ bytes_utf[len_B] = 0;
-UCS_string ucs(utf);
+const UTF8_string utf(bytes_utf, len_B);
+const UCS_string ucs(utf);
Value_P Z(ucs, LOC);
return Z;
}
@@ -0,0 +1,89 @@
--- src/UCS_string.cc.orig 2019-06-23 12:39:20 UTC
+++ src/UCS_string.cc
@@ -43,32 +43,36 @@ UCS_string::UCS_string()
}
//-----------------------------------------------------------------------------
UCS_string::UCS_string(Unicode uni)
- : basic_string<Unicode>(1, uni)
{
+ push_back(uni);
create(LOC);
}
//-----------------------------------------------------------------------------
UCS_string::UCS_string(const Unicode * data, size_t len)
- : basic_string<Unicode>(data, len)
{
+ reserve(2*len);
+ loop(l, len) push_back(data[l]);
create(LOC);
}
//-----------------------------------------------------------------------------
UCS_string::UCS_string(size_t len, Unicode uni)
- : basic_string<Unicode>(len, uni)
{
+ reserve(2*len);
+ loop(l, len) push_back(uni);
create(LOC);
}
//-----------------------------------------------------------------------------
UCS_string::UCS_string(const UCS_string & ucs)
- : basic_string<Unicode>(ucs)
+ : vector<Unicode>(ucs)
{
create(LOC);
}
//-----------------------------------------------------------------------------
UCS_string::UCS_string(const UCS_string & ucs, size_t pos, size_t len)
- : basic_string<Unicode>(ucs, pos, len)
{
+ if (len > ucs.size() - pos) len = ucs.size() - pos;
+ reserve(2*len);
+ loop(l, len) push_back(ucs[pos + l]);
create(LOC);
}
//-----------------------------------------------------------------------------
@@ -88,7 +92,7 @@ UCS_string::UCS_string(const char * cstring)
while (*cstring)
{
Assert((0x80 & *cstring) == 0); // ASCII
- *this += Unicode(*cstring++);
+ push_back(Unicode(*cstring++));
}
}
//-----------------------------------------------------------------------------
@@ -127,7 +131,7 @@ UCS_string::UCS_string(const UTF8_string & utf)
<< " len " << utf.size() << " at " << LOC << endl;
if (utf.size() >= 40)
{
- const UTF8_string end(&utf[utf.size() - 10], 10);
+ const UTF8_string end(utf8P(&utf[utf.size() - 10]), 10);
end.dump_hex(CERR << endl << "(ending with : ", 20)
<< ")" << endl;
}
@@ -141,7 +145,7 @@ UCS_string::UCS_string(const UTF8_string & utf)
<< " len " << utf.size() << " at " << LOC << endl;
if (utf.size() >= 40)
{
- const UTF8_string end(&utf[utf.size() - 10], 10);
+ const UTF8_string end(utf8P(&utf[utf.size() - 10]), 10);
end.dump_hex(CERR << endl << "(ending with : ", 20)
<< ")" << endl;
}
@@ -479,7 +483,7 @@ UCS_string::remove_trailing_whitespaces()
void
UCS_string::remove_leading_whitespaces()
{
-int count = 0;
+ShapeItem count = 0;
loop(s, size())
{
if (at(s) <= UNI_ASCII_SPACE) ++count;
@@ -488,7 +492,7 @@ int count = 0;
if (count == 0) return; // no leading whitspaces
if (count == size()) clear(); // only whitespaces
- else basic_string::erase(0, count);
+ else vector<Unicode>::erase(begin(), begin() + count);
}
//-----------------------------------------------------------------------------
void
+127
View File
@@ -0,0 +1,127 @@
--- src/UCS_string.hh.orig 2019-06-23 12:39:20 UTC
+++ src/UCS_string.hh
@@ -23,7 +23,7 @@
#include <stdint.h>
#include <stdio.h>
-#include <string>
+#include <vector>
#include "Assert.hh"
#include "Common.hh"
@@ -44,7 +44,7 @@ class UCS_string_vector;
//=============================================================================
/// A string of Unicode characters (32-bit)
-class UCS_string : public basic_string<Unicode>
+class UCS_string : public vector<Unicode>
{
public:
/// default constructor: empty string
@@ -186,7 +186,7 @@ class UCS_string : public basic_string<Unicode> (publ
/// remove the last character in \b this string
void pop_back()
- { Assert(size() > 0); resize(size() - 1); }
+ { Assert(size() > 0); vector<Unicode>::pop_back(); }
/// return this string reversed (i.e. characters from back to front).
UCS_string reverse() const;
@@ -216,13 +216,13 @@ class UCS_string : public basic_string<Unicode> (publ
int atoi() const;
/// append UCS_string other to this string
- void append(const UCS_string & other)
- { basic_string::append(other); }
+ void append(const UCS_string & suffix)
+ { loop(s, suffix.size()) push_back(suffix[s]); }
/// append 0-terminated ASCII string \b str to this string. str is NOT
/// interpreted as UTF8 string (use append_UTF8() if such interpretation /// is desired)
void append_ASCII(const char * ascii)
- { while (*ascii) *this += Unicode(*ascii++); }
+ { while (const char cc = *ascii++) push_back(Unicode(cc)); }
/// append 0-terminated UTF8 string str to \b this UCS_string.
@@ -241,7 +241,7 @@ class UCS_string : public basic_string<Unicode> (publ
/// more intuitive insert() function
void insert(ShapeItem pos, Unicode uni)
- { basic_string::insert(pos, 1, uni); }
+ { vector<Unicode>::insert(begin() + pos, uni); }
/// prepend character \b uni
void prepend(Unicode uni)
@@ -249,7 +249,7 @@ class UCS_string : public basic_string<Unicode> (publ
/// return \b this string and \b other concatenated
UCS_string operator +(const UCS_string & other) const
- { UCS_string ret(*this); ret += other; return ret; }
+ { UCS_string ret(*this); ret.append(other); return ret; }
/// append C-string \b str
UCS_string & operator <<(const char * str)
@@ -261,11 +261,11 @@ class UCS_string : public basic_string<Unicode> (publ
/// append character \b uni
UCS_string & operator <<(Unicode uni)
- { *this += uni; return *this; }
+ { push_back(uni); return *this; }
/// append UCS_string \b other
UCS_string & operator <<(const UCS_string & other)
- { basic_string::append(other); return *this; }
+ { append(other); return *this; }
/// compare \b this with UCS_string \b other
Comp_result compare(const UCS_string & other) const
@@ -301,16 +301,16 @@ class UCS_string : public basic_string<Unicode> (publ
/// the inverse of \b un_escape().
UCS_string do_escape(bool double_quoted) const;
- /// overload basic_string::size() so that it returns a signed length
+ /// overload vector::size() so that it returns a signed length
ShapeItem size() const
- { return basic_string::size(); }
+ { return ShapeItem(vector<Unicode>::size()); }
/// an iterator for UCS_strings
class iterator
{
public:
/// constructor: start at position p
- iterator(const UCS_string & ucs, int p)
+ iterator(const UCS_string & ucs, int p = 0)
: s(ucs),
pos(p)
{}
@@ -335,10 +335,6 @@ class UCS_string : public basic_string<Unicode> (publ
int pos;
};
- /// an iterator set to the start of this string
- UCS_string::iterator begin() const
- { return iterator(*this, 0); }
-
/// round last digit and discard it.
void round_last_digit();
@@ -362,7 +358,7 @@ class UCS_string : public basic_string<Unicode> (publ
/// erase 1 (!) character at pos
void erase(ShapeItem pos)
- { basic_string::erase(pos, 1); }
+ { vector<Unicode>::erase(begin() + pos); }
/// helper function for Heapsort<Unicode>::sort()
static bool greater_uni(const Unicode & u1, const Unicode & u2, const void *)
@@ -425,7 +421,7 @@ class UCS_string : public basic_string<Unicode> (publ
private:
/// prevent accidental usage of the rather dangerous default len parameter
/// in basic_strng::erase(pos, len = npos)
- basic_string & erase(size_type pos, size_type len);
+ vector<Unicode> & erase(size_type pos, size_type len);
};
//-----------------------------------------------------------------------------
inline void
@@ -0,0 +1,29 @@
--- src/UTF8_string.hh.orig 2019-06-23 12:39:20 UTC
+++ src/UTF8_string.hh
@@ -45,7 +45,7 @@ utf8P(const void * vp)
}
//-----------------------------------------------------------------------------
/// an UTF8 encoded Unicode (RFC 3629) string
-class UTF8_string : public std::basic_string<UTF8>
+class UTF8_string : public std::string
{
public:
/// constructor: empty UTF8_string
@@ -79,15 +79,9 @@ class UTF8_string : public std::basic_string<UTF8> (pu
return true;
}
- /// return \b this string as a 0-termionated C string
- const char * c_str() const
- { return reinterpret_cast<const char *>
- (std::basic_string<UTF8>::c_str()); }
-
- /// prevent basic_string::erase() with its dangerous default value for
- /// the number of erased character.
+ /// erase one item at \b pos
void erase(size_t pos)
- { basic_string::erase(pos, 1); }
+ { std::string::erase(begin() + pos); }
/// return the last byte in this string
UTF8 back() const