Skip to content

Commit

Permalink
Xplat alpine changes (#1094)
Browse files Browse the repository at this point in the history
  • Loading branch information
david-puglielli authored Feb 20, 2020
1 parent af3097d commit cd64173
Show file tree
Hide file tree
Showing 4 changed files with 93 additions and 49 deletions.
11 changes: 8 additions & 3 deletions source/pdo_sqlsrv/config.m4
Original file line number Diff line number Diff line change
Expand Up @@ -78,10 +78,15 @@ if test "$PHP_PDO_SQLSRV" != "no"; then

HOST_OS_ARCH=`uname`
if test "${HOST_OS_ARCH}" = "Darwin"; then
PDO_SQLSRV_SHARED_LIBADD="$PDO_SQLSRV_SHARED_LIBADD -Wl,-bind_at_load"
MACOSX_DEPLOYMENT_TARGET=`sw_vers -productVersion`
PDO_SQLSRV_SHARED_LIBADD="$PDO_SQLSRV_SHARED_LIBADD -Wl,-bind_at_load"
MACOSX_DEPLOYMENT_TARGET=`sw_vers -productVersion`
else
PDO_SQLSRV_SHARED_LIBADD="$PDO_SQLSRV_SHARED_LIBADD -Wl,-z,now"
PDO_SQLSRV_SHARED_LIBADD="$PDO_SQLSRV_SHARED_LIBADD -Wl,-z,now"
IS_ALPINE_1=`uname -a | cut -f 4 -d ' ' | cut -f 2 -d '-'`
IS_ALPINE_2=`cat /etc/os-release | grep ID | grep alpine | cut -f 2 -d '='`
if test "${IS_ALPINE_1}" = "Alpine" || test "${IS_ALPINE_2}" = "alpine"; then
AC_DEFINE(__MUSL__, 1, [ ])
fi
fi

PHP_REQUIRE_CXX()
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
20 changes: 13 additions & 7 deletions source/sqlsrv/config.m4
Original file line number Diff line number Diff line change
Expand Up @@ -44,25 +44,31 @@ if test "$PHP_SQLSRV" != "no"; then
pdo_sqlsrv_inc_path=$srcdir/ext/pdo_sqlsrv/shared/
shared_src_class=""
elif test -f $srcdir/ext/sqlsrv/shared/core_sqlsrv.h; then
sqlsrv_inc_path=$srcdir/ext/sqlsrv/shared/
sqlsrv_inc_path=$srcdir/ext/sqlsrv/shared/
elif test -f $srcdir/shared/core_sqlsrv.h; then
sqlsrv_inc_path=$srcdir/shared/
sqlsrv_inc_path=$srcdir/shared/
else
AC_MSG_ERROR([Cannot find SQLSRV headers])
AC_MSG_ERROR([Cannot find SQLSRV headers])
fi
AC_MSG_RESULT($sqlsrv_inc_path)
AC_MSG_RESULT($sqlsrv_inc_path)

CXXFLAGS="$CXXFLAGS -std=c++11"
CXXFLAGS="$CXXFLAGS -D_FORTIFY_SOURCE=2 -O2"
CXXFLAGS="$CXXFLAGS -fstack-protector"

HOST_OS_ARCH=`uname`
if test "${HOST_OS_ARCH}" = "Darwin"; then
SQLSRV_SHARED_LIBADD="$SQLSRV_SHARED_LIBADD -Wl,-bind_at_load"
MACOSX_DEPLOYMENT_TARGET=`sw_vers -productVersion`
SQLSRV_SHARED_LIBADD="$SQLSRV_SHARED_LIBADD -Wl,-bind_at_load"
MACOSX_DEPLOYMENT_TARGET=`sw_vers -productVersion`
else
SQLSRV_SHARED_LIBADD="$SQLSRV_SHARED_LIBADD -Wl,-z,now"
SQLSRV_SHARED_LIBADD="$SQLSRV_SHARED_LIBADD -Wl,-z,now"
IS_ALPINE_1=`uname -a | cut -f 4 -d ' ' | cut -f 2 -d '-'`
IS_ALPINE_2=`cat /etc/os-release | grep ID | grep alpine | cut -f 2 -d '='`
if test "${IS_ALPINE_1}" = "Alpine" || test "${IS_ALPINE_2}" = "alpine"; then
AC_DEFINE(__MUSL__, 1, [ ])
fi
fi


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

0 comments on commit cd64173

Please sign in to comment.