Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/main' into optional-codec
Browse files Browse the repository at this point in the history
  • Loading branch information
bernardnormier committed Feb 26, 2024
2 parents 391d7da + c6a4889 commit 252391e
Show file tree
Hide file tree
Showing 208 changed files with 1,404 additions and 5,434 deletions.
19 changes: 18 additions & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,23 @@
"typeinfo": "cpp",
"unordered_map": "cpp",
"variant": "cpp",
"algorithm": "cpp"
"algorithm": "cpp",
"bit": "cpp",
"*.tcc": "cpp",
"chrono": "cpp",
"compare": "cpp",
"concepts": "cpp",
"functional": "cpp",
"iterator": "cpp",
"memory": "cpp",
"memory_resource": "cpp",
"numeric": "cpp",
"random": "cpp",
"type_traits": "cpp",
"utility": "cpp",
"numbers": "cpp",
"semaphore": "cpp",
"stop_token": "cpp",
"cinttypes": "cpp"
}
}
8 changes: 4 additions & 4 deletions cpp/include/Glacier2/SessionHelper.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@
#ifndef GLACIER2_SESSION_HELPER_H
#define GLACIER2_SESSION_HELPER_H

#include <IceUtil/Thread.h>

#include <Ice/Initialize.h>
#include <Ice/Properties.h>
#include <Ice/Communicator.h>
Expand All @@ -18,6 +16,7 @@

#include <map>
#include <string>
#include <thread>
#include <mutex>

namespace Glacier2
Expand Down Expand Up @@ -273,7 +272,8 @@ class GLACIER2_API SessionFactoryHelper : public std::enable_shared_from_this<Se

private:

IceUtil::ThreadPtr addThread(const SessionHelper*, const IceUtil::ThreadPtr&);
void addThread(const SessionHelper*, std::thread&&);
std::thread removeThread(const SessionHelper*);

Ice::InitializationData createInitData();
std::string getRouterFinderStr();
Expand All @@ -291,7 +291,7 @@ class GLACIER2_API SessionFactoryHelper : public std::enable_shared_from_this<Se
SessionCallbackPtr _callback;
std::map<std::string, std::string> _context;
bool _useCallbacks;
std::map<const SessionHelper*, IceUtil::ThreadPtr> _threads;
std::map<const SessionHelper*, std::thread> _threads;
};
using SessionFactoryHelperPtr = std::shared_ptr<SessionFactoryHelper>;

Expand Down
6 changes: 0 additions & 6 deletions cpp/include/Ice/Config.h
Original file line number Diff line number Diff line change
Expand Up @@ -50,12 +50,6 @@ namespace Ice

/** The mapping for the Slice byte type. */
typedef unsigned char Byte;
/** The mapping for the Slice short type. */
typedef short Short;
/** The mapping for the Slice float type. */
typedef float Float;
/** The mapping for the Slice double type. */
typedef double Double;

}

Expand Down
149 changes: 51 additions & 98 deletions cpp/include/Ice/IconvStringConverter.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,11 @@

#include <Ice/StringConverter.h>
#include <IceUtil/StringUtil.h>
#include <IceUtil/ThreadException.h>
#include <IceUtil/UndefSysMacros.h>

#include <algorithm>
#include <memory>

#include <iconv.h>
#include <langinfo.h>

Expand Down Expand Up @@ -89,21 +90,60 @@ class IconvStringConverter : public IceUtil::BasicStringConverter<charT>

IconvStringConverter(const std::string&);

virtual ~IconvStringConverter();

virtual Ice::Byte* toUTF8(const charT*, const charT*, Ice::UTF8Buffer&) const;

virtual void fromUTF8(const Ice::Byte*, const Ice::Byte*, std::basic_string<charT>&) const;

private:

std::pair<iconv_t, iconv_t> createDescriptors() const;
std::pair<iconv_t, iconv_t> getDescriptors() const;
struct DescriptorHolder
{
std::pair<iconv_t, iconv_t> descriptor;

DescriptorHolder(const std::string& internalCode) :
descriptor(iconv_t(-1), iconv_t(-1))
{
const char* externalCode = "UTF-8";

descriptor.first = iconv_open(internalCode.c_str(), externalCode);
if(descriptor.first == iconv_t(-1))
{
std::ostringstream os;
os << "iconv cannot convert from " << externalCode << " to " << internalCode;
throw Ice::IllegalConversionException(__FILE__, __LINE__, os.str());
}

descriptor.second = iconv_open(externalCode, internalCode.c_str());
if(descriptor.second == iconv_t(-1))
{
iconv_close(descriptor.first);
std::ostringstream os;
os << "iconv cannot convert from " << internalCode << " to " << externalCode;
throw Ice::IllegalConversionException(__FILE__, __LINE__, os.str());
}
}

~DescriptorHolder()
{
#ifndef NDEBUG
int rs = iconv_close(descriptor.first);
assert(rs == 0);

rs = iconv_close(descriptor.second);
assert(rs == 0);
#else
iconv_close(descriptor.first);
iconv_close(descriptor.second);
#endif
}

// Non-copyable
DescriptorHolder(const DescriptorHolder&) = delete;
DescriptorHolder& operator=(const DescriptorHolder&) = delete;
};

static void cleanupKey(void*);
static void close(std::pair<iconv_t, iconv_t>);
std::pair<iconv_t, iconv_t> getDescriptors() const;

mutable pthread_key_t _key;
const std::string _internalCode;
};

Expand All @@ -120,106 +160,19 @@ IconvStringConverter<charT>::IconvStringConverter(const std::string& internalCod
//
try
{
close(createDescriptors());
const DescriptorHolder descriptorHolder(internalCode);
}
catch(const Ice::IllegalConversionException& sce)
{
throw Ice::IconvInitializationException(__FILE__, __LINE__, sce.reason());
}

//
// Create thread-specific key
//
int rs = pthread_key_create(&_key, &cleanupKey);

if(rs != 0)
{
throw IceUtil::ThreadSyscallException(__FILE__, __LINE__, rs);
}
}

template<typename charT>
IconvStringConverter<charT>::~IconvStringConverter()
{
void* val = pthread_getspecific(_key);
if(val != 0)
{
cleanupKey(val);
}
if(pthread_key_delete(_key) != 0)
{
assert(0);
}
}

template<typename charT> std::pair<iconv_t, iconv_t>
IconvStringConverter<charT>::createDescriptors() const
{
std::pair<iconv_t, iconv_t> cdp;

const char* externalCode = "UTF-8";

cdp.first = iconv_open(_internalCode.c_str(), externalCode);
if(cdp.first == iconv_t(-1))
{
std::ostringstream os;
os << "iconv cannot convert from " << externalCode << " to " << _internalCode;
throw Ice::IllegalConversionException(__FILE__, __LINE__, os.str());
}

cdp.second = iconv_open(externalCode, _internalCode.c_str());
if(cdp.second == iconv_t(-1))
{
iconv_close(cdp.first);
std::ostringstream os;
os << "iconv cannot convert from " << _internalCode << " to " << externalCode;
throw Ice::IllegalConversionException(__FILE__, __LINE__, os.str());
}
return cdp;
}

template<typename charT> std::pair<iconv_t, iconv_t>
IconvStringConverter<charT>::getDescriptors() const
{
void* val = pthread_getspecific(_key);
if(val != 0)
{
return *static_cast<std::pair<iconv_t, iconv_t>*>(val);
}
else
{
std::pair<iconv_t, iconv_t> cdp = createDescriptors();
int rs = pthread_setspecific(_key, new std::pair<iconv_t, iconv_t>(cdp));
if(rs != 0)
{
throw IceUtil::ThreadSyscallException(__FILE__, __LINE__, rs);
}
return cdp;
}
}

template<typename charT> /*static*/ void
IconvStringConverter<charT>::cleanupKey(void* val)
{
std::pair<iconv_t, iconv_t>* cdp = static_cast<std::pair<iconv_t, iconv_t>*>(val);

close(*cdp);
delete cdp;
}

template<typename charT> /*static*/ void
IconvStringConverter<charT>::close(std::pair<iconv_t, iconv_t> cdp)
{
#ifndef NDEBUG
int rs = iconv_close(cdp.first);
assert(rs == 0);

rs = iconv_close(cdp.second);
assert(rs == 0);
#else
iconv_close(cdp.first);
iconv_close(cdp.second);
#endif
static const thread_local DescriptorHolder descriptorHolder(_internalCode);
return descriptorHolder.descriptor;
}

template<typename charT> Ice::Byte*
Expand Down
Loading

0 comments on commit 252391e

Please sign in to comment.