Skip to content
DnsLister Forum

Where domain hunters compare notes

SGCL update: five new modules (time, hash, math, encoding, net), regex in txt, and a pass over the whole API

Since the first post, 229 commits went into the public repo as one merge. Five new modules, the rest of the text module, a new namespace layout, and a review of the whole API. Everything below is on main now.

New modules

  • time: Go's time package in C++.
    • sgcl::duration lives in core, because the timers take one. It reads and writes Go's text ("1h30m0.5s"), and every std::chrono duration converts to it.
    • Calendar dates use the Euclidean affine functions of Neri and Schneider. Time zones come from the system's tz database.
    • Layouts work in both Go's and strftime's notation, and txt::format understands the <chrono> types.
    • Measured against Go and std::format.
  • hash:
    • the CRC family, Adler-32 and FNV;
    • XXH3 64 and 128, written from the algorithm's description;
    • SipHash;
    • one interface, so a stream can be written into any of them.
  • math:
    • big_integer and rational, as in Go's math/big: Karatsuba, Toom-3 and Burnikel–Ziegler, plus number theory (pow, mod_pow, gcd, mod_inverse, sqrt, is_probable_prime);
    • random, the same ChaCha8 stream as Go's math/rand/v2.
  • encoding:
    • hex, base32, base64, ascii85, varint and PEM;
    • JSON (RFC 8259) with a token reader, an immutable value, a writer, and typed reading and writing of your own types described by their fields;
    • CSV as Go's encoding/csv reads it;
    • XML with namespaces, a token reader, a tree and the same typed form.
  • net:
    • TCP, UDP and DNS on the reactor;
    • a URL parser following the WHATWG URL Standard, checked against the web platform tests;
    • HTTP/1.1: a client with a connection pool and redirects, and a server with Go 1.22-style routes.

​

net::http::server server; server.route("GET /hello/{name}", [](net::http::request req, net::http::response_writer w) { w.set_header("Content-Type", "text/plain"); w.write("hello, " + req.path_value("name") + "\n"); }); auto listener = net::tcp::listen("127.0.0.1:0"); auto serving = async::spawn(server.async_serve(*listener)); net::http::client client; auto res = client.get("http://127.0.0.1:" + to_string(listener->local_endpoint().port()) + "/hello/world"); 

txt grows

  • Regular expressions in linear time, RE2-style: no backreferences and no lookaround, which is the price of that guarantee. A prefilter takes a literal search from 24.6 ns to 0.039 ns per byte.
  • IDNA 2008, with punycode and percent encoding.
  • A template engine, checked against Go's text/template.
  • Collation: the fourth strength level of the collator, and a search that agrees with it.

Breaking changes

  • A directory is a namespace: sgcl::io, sgcl::async, sgcl::concurrent… Only core stays flat. The containers moved into core, and the immutable ones into sgcl::immutable.
  • io is synchronous by default, with async_ forms for tasks. Streams are checked structurally, and io::reader / io::writer are one-word handles over any stream.
  • Every function that can fail returns expected<T, E> with a message().
  • Every wait in async has one form: an operation or a completion object, waited for with co_await or .wait().
  • Public constants are snake_case, as in std (config::page_size, config::workers). Names are consistent across modules, and internal details moved out of the public classes.

The API was then audited by a second reviewer and checked twice. The bugs the audit found (a once whose body throws, a URL setter, a formatter, a read at the end of a stream) were each fixed with a test.

The collector

In debug builds, the check that warns when a pointer shares its word with data no longer reports two false alarms: an owner stored next to a raw pointer into what it owns, and data that happens to point inside an object.

Still true

Tested only on macOS / Apple Silicon so far. Linux and Windows are pending.

Next

compress, crypto (with TLS 1.3), then the rest of net (TLS, HTTP/2), serialization of object graphs, and codec.

Source: r/sgcl · by /u/pebalx

Leave a Reply

Your email address will not be published. Required fields are marked *