Apophis
view release on metacpan or search on metacpan
lib/Apophis.xs view on Meta::CPAN
/*
* Apophis.xs - Content-addressable storage with deterministic UUID v5
*
* Named after Apophis, the Egyptian serpent of chaos â here tamed
* to bring order to content through deterministic hashing.
*
* 100% XS: all logic in C, Perl layer is just XSLoader.
* Uses Horus library for RFC 9562 UUID v5 (SHA-1 namespace) generation.
*/
#define PERL_NO_GET_CONTEXT
#include "EXTERN.h"
#include "perl.h"
#include "XSUB.h"
#include "../ppport.h"
#include <sys/stat.h>
#include <errno.h>
#ifndef _WIN32
# include <unistd.h>
#else
# include <io.h>
# include <direct.h>
#endif
/*
* Windows compatibility:
* perl.h on threaded Windows redefines mkdir, stat, unlink etc. as macros
* requiring the interpreter context (my_perl). Our static C helper functions
* don't have pTHX, so we undo those overrides and use the real libc calls.
*/
#ifdef WIN32
# undef mkdir
# undef stat
# undef unlink
# undef rename
# undef open
# undef close
# undef read
# undef write
/* Windows mkdir takes only one arg */
# define apophis_mkdir(p, m) _mkdir(p)
#else
# define apophis_mkdir(p, m) mkdir(p, m)
#endif
/* Portable stat type â Stat_t handles struct w32_stat on Windows */
#define apophis_stat_t Stat_t
/* Horus UUID library - pure C, no Perl deps */
#define HORUS_FATAL(msg) croak("%s", (msg))
#include "horus_core.h"
/* ------------------------------------------------------------------ */
/* Constants */
/* ------------------------------------------------------------------ */
#define APOPHIS_STREAM_BUF 65536 /* 64KB read chunks for streaming */
#define APOPHIS_PATH_MAX 4096
/* ------------------------------------------------------------------ */
/* Internal: namespace UUID generation */
/* ------------------------------------------------------------------ */
/* Derive a namespace UUID from a human-readable string via v5(DNS, name) */
static void
apophis_derive_namespace(unsigned char *ns_out,
const char *name, STRLEN name_len)
{
horus_uuid_v5(ns_out, HORUS_NS_DNS,
(const unsigned char *)name, (size_t)name_len);
}
/* Format 16-byte UUID binary to 36-char string SV */
static SV *
apophis_uuid_to_sv(pTHX_ const unsigned char *uuid)
{
char buf[HORUS_FMT_STR_LEN + 1];
horus_format_uuid(buf, uuid, HORUS_FMT_STR);
return newSVpvn(buf, HORUS_FMT_STR_LEN);
}
/* ------------------------------------------------------------------ */
/* Internal: content identification */
/* ------------------------------------------------------------------ */
/* Identify in-memory content: v5(namespace, content) */
static void
( run in 0.947 second using v1.01-cache-2.11-cpan-22024b96cdf )