From 5ee185a4896e43c67b6d299becfa616da78fb9f4 Mon Sep 17 00:00:00 2001 From: Bruce Hill Date: Fri, 21 Mar 2025 21:48:53 -0400 Subject: Move stdlib into src/ --- stdlib/c_strings.c | 86 ------------------------------------------------------ 1 file changed, 86 deletions(-) delete mode 100644 stdlib/c_strings.c (limited to 'stdlib/c_strings.c') diff --git a/stdlib/c_strings.c b/stdlib/c_strings.c deleted file mode 100644 index 7987a234..00000000 --- a/stdlib/c_strings.c +++ /dev/null @@ -1,86 +0,0 @@ -// Type info and methods for CString datatype (char*) -#include -#include -#include -#include -#include -#include -#include - -#include "text.h" -#include "siphash.h" -#include "util.h" - -public Text_t CString$as_text(const void *c_string, bool colorize, const TypeInfo_t *info) -{ - (void)info; - if (!c_string) return Text("CString"); - Text_t text = Text$from_str(*(const char**)c_string); - return Text$concat(colorize ? Text("\x1b[34mCString\x1b[m(") : Text("CString("), Text$quoted(text, colorize), Text(")")); -} - -public Text_t CString$as_text_simple(const char *str) -{ - return Text$format("%s", str); -} - -PUREFUNC public int32_t CString$compare(const void *x, const void *y, const TypeInfo_t*) -{ - if (x == y) - return 0; - - if (!*(const char**)x != !*(const char**)y) - return (!*(const char**)y) - (!*(const char**)x); - - return strcmp(*(const char**)x, *(const char**)y); -} - -PUREFUNC public bool CString$equal(const void *x, const void *y, const TypeInfo_t *type) -{ - return CString$compare(x, y, type) == 0; -} - -PUREFUNC public uint64_t CString$hash(const void *c_str, const TypeInfo_t*) -{ - if (!*(const char**)c_str) return 0; - return siphash24(*(void**)c_str, strlen(*(const char**)c_str)); -} - -PUREFUNC public bool CString$is_none(const void *c_str, const TypeInfo_t*) -{ - return *(const char**)c_str == NULL; -} - -static void CString$serialize(const void *obj, FILE *out, Table_t *pointers, const TypeInfo_t*) -{ - const char *str = *(const char **)obj; - int64_t len = (int64_t)strlen(str); - Int64$serialize(&len, out, pointers, &Int64$info); - fwrite(str, sizeof(char), (size_t)len, out); -} - -static void CString$deserialize(FILE *in, void *out, Array_t *pointers, const TypeInfo_t *) -{ - int64_t len = -1; - Int64$deserialize(in, &len, pointers, &Int64$info); - char *str = GC_MALLOC_ATOMIC((size_t)len+1); - fread(str, sizeof(char), (size_t)len, in); - str[len+1] = '\0'; - *(const char**)out = str; -} - -public const TypeInfo_t CString$info = { - .size=sizeof(const char*), - .align=__alignof__(const char*), - .metamethods={ - .hash=CString$hash, - .compare=CString$compare, - .equal=CString$equal, - .as_text=CString$as_text, - .is_none=CString$is_none, - .serialize=CString$serialize, - .deserialize=CString$deserialize, - }, -}; - -// vim: ts=4 sw=0 et cino=L2,l1,(0,W4,m1,\:0 -- cgit v1.2.3