Showing posts with label string access shims. Show all posts
Showing posts with label string access shims. Show all posts

Wednesday, December 26, 2018

STLSoft 1.10.1 (beta 12) released

The latest beta of STLSoft 1.10.1 is available, at https://github.com/synesissoftware/STLSoft-1.10/tree/beta-12.

Getting the beta

As usual, there are two ways to obtain the latest beta:
  1. Select one of the release archives (.zip, .tar.gz) at https://github.com/synesissoftware/STLSoft-1.10/releases/tag/1.10.1-beta12; or
  2. Clone the repo https://github.com/synesissoftware/STLSoft-1.10 and checkout the beta-12 branch (as in "$ git checkout -b beta-10 origin/beta-12").

Changes

The substantive changes are:
  • added stlsoft::sas_to_string() (and related - _m and _w form) function templates, which create instances of std::basic_string<> by applying String Access Shims to the given parameter;
  • added stlsoft::errno_exception exception class (from the 1.12 branch);
  • added stlsoft::locale_scope scoping class;
  • STLSoft's struct tm String Access Shims now work for arbitrary locale;
  • UNIXSTL's timeval String Access Shims now work for arbitrary locale.

I'll describe these changes in a future blog post.

Friday, December 21, 2018

STLSoft 1.10.1 (beta 10) released

The latest beta of STLSoft 1.10.1 is available, at https://github.com/synesissoftware/STLSoft-1.10/tree/beta-10.

Getting the beta

As usual, there are two ways to obtain the latest beta:
  1. Select one of the release archives (.zip, .tar.gz) at https://github.com/synesissoftware/STLSoft-1.10/releases/tag/1.10.1-beta10; or
  2. Clone the repo https://github.com/synesissoftware/STLSoft-1.10 and checkout the beta-10 branch (as in "$ git checkout -b beta-10 origin/beta-10").

Changes

The substantive changes are:
  • winstl::process_mutex() now provides two additional ctor overloads that take an additional HANDLE parameter to pass an event that will be signalled in case of an ABANDONED wait, which should (almost) always be treated as a terminal condition. This means that crucial mutex instances may now be connected to a shutdown event;
  • Special String Instances - those types generated by specialisations of stlsoft::special_string_instance_0 and stlsoft::special_string_instance_1 - are now automatically provided (in)equality operators: operator ==() and operator !=(). There are a bunch of such types, including (along with all their _a and _w variants):
    • unixstl::current_directory;
    • unixstl::home_directory;
    • winstl::absolute_path;
    • winstl::current_directory;
    • winstl::home_directory;
    • winstl::host_name;
    • winstl::module_directory;
    • winstl::module_filename;
    • winstl::system_directory;
    • winstl::temporary_directory;
    • winstl::temporary_file_name;
    • winstl::user_name; and
    • winstl::windows_directory.
These will be explained below with a few short examples.

Examples

Process Mutex abandonment

The Old New Thing's "Understanding the consequences of WAIT_ABANDONED" explains the situation well, so I won't repeat here. I'll just include code from a component test for the new functionality in winstl::process_mutex():

    SECTION("waiting on an abandoned mutex with an event") {

        winstl::event         ev(true, false);

        winstl::process_mutex mx(L"my-mx", false, nullptr, ev.handle());

        CHECK(!mx.abandoned());

        std::thread thread([&] {

            mx.lock(); // acquire but don't release, then quit (=> abandon)
        });

        thread.join();

        CHECK(mx.try_lock()); // acquire, which notes the abandonment

        DWORD const r = ::WaitForSingleObject(ev.handle(), 0);

        CHECK(WAIT_OBJECT_0 == r);

        CHECK(mx.abandoned());
    }

FYI: we're changing over to using the Catch Unit-testing library for STLSoft 1.10. (Still currently using Catch v1, tho ...)

Special String Instance(s)

Simply, where (in)equality-comparison would previously have been manual tasks, as in:

  unixstl::current_directory cwd;

  if (0 == ::strcmp("/Users/matt/dev/STLSoft/Releases/1.10", cwd.c_str())
  {}

and

  winstl::current_directory cwd;

  if (0 != ::stricmp("C:\\Users\\matt\\dev\\STLSoft\\Releases\\1.10", cwd.c_str())
  {}

they are now provided with a natural syntax (due to internal use of String Access Shims):

  unixstl::current_directory cwd;

  if ("/Users/matt/dev/STLSoft/Releases/1.10" == cwd)
  {}


and

  winstl::current_directory cwd;

  if (cwd != "C:\\Users\\matt\\dev\\STLSoft\\Releases\\1.10")
  {}


Note that the case-sensitivity is handled automatically. Hence winstl::current_directory's specialising policy template now includes the member constant caseSensitive, which is now required by the special string instance class templates:

  template <typename C>
  struct cwd_policy
  {
    typedef C                         char_type;
    typedef processheap_allocator<C>  allocator_type;
    typedef size_t                    size_type;
    typedef size_type               (*pfn_type)(char_type *, size_type);

    enum { internalBufferSize       =   128 };
    enum { allowImplicitConversion  =   1   };
    enum { caseSensitive            =   0   };
    enum { sharedState              =   0   };

    static pfn_type get_fn()
    {
      return winstl::filesystem_traits::get_current_directory;
    }
  };


There's a further benefit in that the comparisons are all length-aware, so that (tiny) bit more efficient. Which is nice.






Monday, November 8, 2010

Wide String Shims for std::exception

The latest release of STLSoft (1.9.102) includes wide string additions to the string access shims for std::exception (and derived types). The most obvious and immediate benefit is that code using FastFormat and/or Pantheios in wide string builds can now work seamlessly with exceptions, just as has always been the case in multibyte string builds:

#include <fastformat/ff.hpp>
. . .
#include <pantheios/pan.hpp>
. . . 

int main()
{
. . .
  catch(std::exception& x)
  {
    pan::log_CRITICAL(L"exception: ", x);
    ff::fmtln(std::wcerr, L"program: {0}", x);
  }
. . .