cwRuntime, what is it?
cwRuntime is a compiler agnostic and cross platform collection of utility libraries for Delphi and FreePascal.
It is heavily interface based, offering ARC based memory management features and flexible implementation abstraction, with the goal of forming a source bridge for developers familiar with the two supported compilers.
The library was migrated from my personal code collection to become open source under the three clause BSD license.
It was my intention to exorcise the the compiler RTL from the implementation for both compilers, however, this has proven to be impossible. There are several pieces of compiler functionality which absolutely depend on the compiler RTL. For example, the TGUID type is managed by some “compiler magic” in places, and FPC is incompatible with threads created outside of it’s RTL. These, among other issues, could only be resolved by replacing the compiler system-unit, which is out of scope for this project.
Delphi XE7, XE8, Berlin (10.1), Tokyo (10.2), Rio (10.3) and Sydney (10.4)
Windows ( x86, x86_64 )
Linux ( x86, x86_64, arm, arrch64 )
Android ( as binary arm, arrch64 )
Support for Apple devices is currently considered experimental, it should work, but there is no CI integration for testing – TBD –
What’s in it?
The library is comprised of the following sub-libraries…
A unit testing framework written from scratch, approximately comparable with Delphi’s older DUnit framework, or the FPCUnit equivalent. While this lacks some of the nice features of more modern unit testing frameworks, it is trivially simple to use, and compatible with both pascal compilers. Compiler agnosticism being the primary feature, allowing you to keep your code compatible with both.
Provides a data-type named ‘TStatus’, which may be used to send return codes from functions and methods as either a 128-bit integer value (GUID) or as a “reason” string. The GUID form is useful for conditionally handling error states as, you might with a boolean or integer data type, while the string form may be used to return a ‘human-readable’ reason for the error state.
Messages may be registered with the cwStatus library which contain place-holders for inserting run-time values, and may be later translated to other languages by loading of language files.
(Language file feature is currently being rebuilt, and is part of the cwLog feature, see blow)
cwTypes is something of a smorgasbord of type helpers, offering conversion or coercion of types such as strings, chars, integers, floats etc. Many of these conversions are useful in reducing compiler hints and warnings produced when performing the conversions by traditional means.
(* Half precision floating point with permission from, and thanks to Marek Mauder at Galfar’s Lair: galfar.vevb.net *)
Provides data types for managing collections (as-in: bag-of-things) of interface references, such as lists, dictionaries, stacks etc. cwCollections makes heavy use of generics to provide flexible collections to be used in dependency injection, and properties of other interfaces and classes.
Provides an interface for loading dynamic libraries, such as windows DLL files, Linux/Posix .so files and Mac OS .dynlib files. This is particularly useful for implementing plugin systems when combined with the cwCollections features.
An implementation of a Unicode codec (coder, decoder) with support for utf-8, 16 and 32, in both big-endian and little-endian carrier formats. While you may use the codec directly, most of it’s features are made more conveniently accessible via the included TUTFString and TUTF8String advanced records, and via the following cwIO features.
Provides interfaces for working with streams and buffers, and a handful of implementations for each. Tightly integrated with cwUnicode, the cwIO library enables saving and loading of unicode content from files and data streams.
A simple logging system. Multiple instances of a log may be created, and then assigned one or more ‘log-targets’ for log messages to be inserted into. cwLog uses status messages as previously registered from the cwStatus system, to insert translatable messages with place-holders into it’s logs.
(Language translation feature is currently undergoing a rebuild)
- Threading issues when targeting non-windows systems with fpc resolved, but not fully tested. See change-log below.
Essentially a rebuild (and redesign), from the ground up, of my earlier ‘deThreading / darkThreading’ library.
This library has been very useful to me over the past few years, however, it was built as part of another project, resulting in feature/domain-creep, and ultimately made the library more complex than it needed to be.
cwThreading removes this complication, offering a simple interface for running multiple types of thread, including:
- Long-Running threads which run until the application terminates.
- Message Subscriber threads, using light-locking atomic messages.
- Task threads, able to pick up and execute arrays of discrete tasks.
- Parallel ‘for-loop’ tasks.
- Scheduled Tasks which may be scheduled to run at a pre-defined n-second intervals.
A library of simple records representing vectors and matrices (among some other geometric primitives) of half-precision, single-precision or double-precision floats. Offering some utility functions for computing intersections and products.
Provides cross-platform implementations for high-precision timers, allowing for high accuracy simulation and profiling.
A wrapper around WinSock2 under windows, and BSD sockets for posix targets. This is a low-level wrapper, providing vanilla TCP/UPD/Other protocol access for applications to build on top of. It does not provide any protocol support (such as http, ftp etc), but is more useful in raw-socket communications.
A very simple (and somewhat limited) wrapper around the operating system heap calls, for safe allocation of heap buffers among threads. There are intentions to enhance this feature further, and to make it the basis of allocation for the cwIO feature.
Breaking Change - The most recent commit, at revision 108 alters some of the class methods in cwVectors to be virtual methods on the record. These pertain mainly to matrices such that a rotation matrix may be created using "m.rotation( angle )" as opposed to "m := matrix.rotation(angle);" All instances of change are similarly minor, and make for easier use of the matrix types in practice.Breaking Change - As of commit 186, support for XE5 & XE6 is removed. Much of the library will still compile for XE5 and earlier, however, there was a syntax change at XE7 regarding passing of array data-types, which the library now makes use of. Current Commit - There was an issue with threading when compiled using FPC for non-windows targets. The threading library was using pthreads for *nix targets, however, the stack checking functionality of FPC is incompatible with what the documentation refers to as "External Threads", that-is, threads not managed by the FPC RTL. Despite turning off stack checking at the command line, the issue remained. The employed solution is to use the lower level threading functions of the FPC RTL for all targets. These functions are supposed to be cross platform as per FPC's core design, however, testing of them has only been performed on windows at this time (Window is my primary dev host). The changes *should* resolve the issues for *nix targets, testing remains TBD until new CI environment is built.