Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Xplat alpine changes #1094

Merged
merged 12 commits into from
Feb 20, 2020
5 changes: 5 additions & 0 deletions source/pdo_sqlsrv/config.m4
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,11 @@ if test "$PHP_PDO_SQLSRV" != "no"; then
PDO_SQLSRV_SHARED_LIBADD="$PDO_SQLSRV_SHARED_LIBADD -Wl,-z,now"
fi

IS_ALPINE=`uname -a | cut -f 4 -d ' ' | cut -f 2 -d '-'`
if test "${IS_ALPINE}" = "Alpine"; then
AC_DEFINE(__MUSL__, 1, [ ])
fi
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Forgot to mention that perhaps you can first check uname and if it's Darwin simply skips?


PHP_REQUIRE_CXX()
PHP_ADD_LIBRARY(stdc++, 1, PDO_SQLSRV_SHARED_LIBADD)
PHP_ADD_LIBRARY(odbc, 1, PDO_SQLSRV_SHARED_LIBADD)
Expand Down
3 changes: 3 additions & 0 deletions source/shared/localization.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,9 @@
#define CP_UTF16 1200
#define CP_ACP 0 // default to ANSI code page

bool _setLocale(const char * localeName, std::locale ** pLocale);
void setDefaultLocale(const char ** localeName, std::locale ** pLocale);

// This class provides allocation policies for the SystemLocale and AutoArray classes.
// This is primarily needed for the self-allocating ToUtf16/FromUtf16 methods.
// SNI needs all its allocations to use its own allocator so it would create a separate
Expand Down
108 changes: 69 additions & 39 deletions source/shared/localizationimpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,38 +50,44 @@ struct cp_iconv
// CodePage 2 corresponds to binary. If the attribute PDO::SQLSRV_ENCODING_BINARY
// is set, GetIndex() above hits the assert(false) directive unless we include
// CodePage 2 below and assign an empty string to it.
#ifdef __MUSL__
#define TRANSLIT ""
#else
#define TRANSLIT "//TRANSLIT"
#endif

const cp_iconv cp_iconv::g_cp_iconv[] = {
{ 65001, "UTF-8" },
{ 1200, "UTF-16LE" },
{ 3, "UTF-8" },
{ 2, "" },
{ 1252, "CP1252//TRANSLIT" },
{ 850, "CP850//TRANSLIT" },
{ 437, "CP437//TRANSLIT" },
{ 874, "CP874//TRANSLIT" },
{ 932, "CP932//TRANSLIT" },
{ 936, "CP936//TRANSLIT" },
{ 949, "CP949//TRANSLIT" },
{ 950, "CP950//TRANSLIT" },
{ 1250, "CP1250//TRANSLIT" },
{ 1251, "CP1251//TRANSLIT" },
{ 1253, "CP1253//TRANSLIT" },
{ 1254, "CP1254//TRANSLIT" },
{ 1255, "CP1255//TRANSLIT" },
{ 1256, "CP1256//TRANSLIT" },
{ 1257, "CP1257//TRANSLIT" },
{ 1258, "CP1258//TRANSLIT" },
{ CP_ISO8859_1, "ISO8859-1//TRANSLIT" },
{ CP_ISO8859_2, "ISO8859-2//TRANSLIT" },
{ CP_ISO8859_3, "ISO8859-3//TRANSLIT" },
{ CP_ISO8859_4, "ISO8859-4//TRANSLIT" },
{ CP_ISO8859_5, "ISO8859-5//TRANSLIT" },
{ CP_ISO8859_6, "ISO8859-6//TRANSLIT" },
{ CP_ISO8859_7, "ISO8859-7//TRANSLIT" },
{ CP_ISO8859_8, "ISO8859-8//TRANSLIT" },
{ CP_ISO8859_9, "ISO8859-9//TRANSLIT" },
{ CP_ISO8859_13, "ISO8859-13//TRANSLIT" },
{ CP_ISO8859_15, "ISO8859-15//TRANSLIT" },
{ 1252, "CP1252" TRANSLIT },
{ 850, "CP850" TRANSLIT },
{ 437, "CP437" TRANSLIT },
{ 874, "CP874" TRANSLIT },
{ 932, "CP932" TRANSLIT },
{ 936, "CP936" TRANSLIT },
{ 949, "CP949" TRANSLIT },
{ 950, "CP950" TRANSLIT },
{ 1250, "CP1250" TRANSLIT },
{ 1251, "CP1251" TRANSLIT },
{ 1253, "CP1253" TRANSLIT },
{ 1254, "CP1254" TRANSLIT },
{ 1255, "CP1255" TRANSLIT },
{ 1256, "CP1256" TRANSLIT },
{ 1257, "CP1257" TRANSLIT },
{ 1258, "CP1258" TRANSLIT },
{ CP_ISO8859_1, "ISO8859-1" TRANSLIT },
{ CP_ISO8859_2, "ISO8859-2" TRANSLIT },
{ CP_ISO8859_3, "ISO8859-3" TRANSLIT },
{ CP_ISO8859_4, "ISO8859-4" TRANSLIT },
{ CP_ISO8859_5, "ISO8859-5" TRANSLIT },
{ CP_ISO8859_6, "ISO8859-6" TRANSLIT },
{ CP_ISO8859_7, "ISO8859-7" TRANSLIT },
{ CP_ISO8859_8, "ISO8859-8" TRANSLIT },
{ CP_ISO8859_9, "ISO8859-9" TRANSLIT },
{ CP_ISO8859_13, "ISO8859-13" TRANSLIT },
{ CP_ISO8859_15, "ISO8859-15" TRANSLIT },
{ 12000, "UTF-32LE" }
};
const size_t cp_iconv::g_cp_iconv_count = ARRAYSIZE(cp_iconv::g_cp_iconv);
Expand Down Expand Up @@ -279,22 +285,46 @@ bool EncodingConverter::Initialize()

using namespace std;

SystemLocale::SystemLocale( const char * localeName )
: m_uAnsiCP(CP_UTF8)
, m_pLocale(NULL)
{
const char* DEFAULT_LOCALE = "en_US.UTF-8";
#ifndef _countof
#define _countof(obj) (sizeof(obj)/sizeof(obj[0]))
#endif

const char* DEFAULT_LOCALES[] = {"en_US.UTF-8", "C"};

try {
m_pLocale = new std::locale(localeName);
bool _setLocale(const char * localeName, std::locale ** pLocale)
{
try
{
*pLocale = new std::locale(localeName);
}
catch(const std::exception& e) {
localeName = DEFAULT_LOCALE;
catch(const std::exception& e)
{
return false;
}

if(!m_pLocale) {
m_pLocale = new std::locale(localeName);

return true;
}

void setDefaultLocale(const char ** localeName, std::locale ** pLocale)
{
if(!localeName || !_setLocale(*localeName, pLocale))
{
int count = 0;
while(!_setLocale(DEFAULT_LOCALES[count], pLocale) && count < _countof(DEFAULT_LOCALES))
{
count++;
}

if(localeName)
*localeName = count < _countof(DEFAULT_LOCALES)?DEFAULT_LOCALES[count]:NULL;
}
}

SystemLocale::SystemLocale( const char * localeName )
: m_uAnsiCP(CP_UTF8)
, m_pLocale(NULL)
{
setDefaultLocale(&localeName, &m_pLocale);

// Mapping from locale charset to codepage
struct LocaleCP
Expand Down
5 changes: 5 additions & 0 deletions source/sqlsrv/config.m4
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,11 @@ if test "$PHP_SQLSRV" != "no"; then
else
SQLSRV_SHARED_LIBADD="$SQLSRV_SHARED_LIBADD -Wl,-z,now"
fi

IS_ALPINE=`uname -a | cut -f 4 -d ' ' | cut -f 2 -d '-'`
if test "${IS_ALPINE}" = "Alpine"; then
AC_DEFINE(__MUSL__, 1, [ ])
fi

PHP_REQUIRE_CXX()
PHP_ADD_LIBRARY(stdc++, 1, SQLSRV_SHARED_LIBADD)
Expand Down