Commit aba5e824

aba5e824bdd8Merged

Yukihiro "Matz" Matsumoto <[email protected]> · 5 months ago · 5 files · ~5 modified

Description

Fix NUL bytes in string literals, Array#to_h, sort! with block, reduce/inject seed type

  • Track true byte length through node_table unescape_dup so strings containing embedded NUL bytes (e.g. "hello\x00*") emit correctly via sp_str_from_bytes with explicit length rather than truncating at NUL
  • Add Array#to_h codegen for poly array receivers, inferring hash key type from the first literal pair element
  • Extend sort!/sort comparator block to typed int/str/float arrays (sort! sorts in place; sort returns a copy), fix analyze block param seeding for sort! with block
  • Fix reduce/inject: accumulator type now comes from the init seed when provided, not from the array element type; block params are shadowed with the correct C type using the same temp-override pattern as sort

Co-Authored-By: Claude Sonnet 4.6 [email protected]

Details

Commit
aba5e824bdd8
Parent
02b691cab375

lib/sp_runtime.hmodifiedView file

@@ -461,6 +461,12 @@
461461 }
462462 }
463463
464+static const char *sp_str_from_bytes(const char *data, size_t len) {
465+ char *s = sp_str_alloc(len);
466+ if (data) memcpy(s, data, len);
467+ s[len] = 0;
468+ return s;
469+}
464470 static const char *sp_str_dup_external(const char *s) {
465471 if (!s) return NULL;
466472 size_t n = strlen(s);