Commit 9db1a30d
9db1a30d1619Merged
Yukihiro "Matz" Matsumoto <[email protected]> · 6 months ago · 3 files · +2 added · ~1 modified
Description
fix(codegen): box mutable_str into poly as SP_TAG_STR not SP_TAG_OBJ/0
Sam Ruby's #541 (roundhouse real-blog returning HTTP 200 with
empty body). View functions returning sp_String * flowed into a
body slot that had been widened to poly across unrelated
classes (Article.body holds a String, Comment.body holds a
String, ArticleParams.body holds something else, etc.), so the
analyzer pinned the slot's effective type as poly. At the
call site the box went through
box_non_nullable_value_to_poly("mutable_str", val), which fell
into the catch-all type_is_pointer arm:
return "sp_box_obj((void *)(val), 0)"
Generic SP_TAG_OBJ box with cls_id 0 (BasicObject). Downstream dispatch (Tep::Server#write_response in roundhouse, computing Content-Length and writing the body to the wire) had no arm matching SP_TAG_OBJ + cls_id 0, so the body was silently dropped -- 200 OK with Content-Length: 0.
Add a mutable_str arm in box_non_nullable_value_to_poly
before the type_is_pointer catch-all. Box through
sp_box_str(s->data) (SP_TAG_STR with the underlying char*
buffer); consumers reading v.v.s on the tag find the string
content. The statement-expression temp holds the recv so side
effects fire exactly once; the ? : sp_box_nil() arm handles
the NULL recv (shouldn't happen for mutable_str but matches
the sp_box_nullable_str shape).
Sam noted in #541 he tried 5 minimal shapes that didn't
reproduce; my test/mutable_str_into_poly_slot.rb does
reproduce by widening body across two unrelated classes,
mirroring the real-blog dataset's per-class same-named slot
collision. The fix-on-master output matches CRuby:
"<h1>title</h1><p>body</p>" instead of 0 / empty.
Closes #541
Co-Authored-By: Claude Opus 4.7 (1M context) [email protected]
Details
- Commit
- 9db1a30d1619
- Parent
- 35122ae5b78d
spinel_codegen.rbmodifiedView file
if hcid != "" return "sp_box_obj((void *)(" + val + "), " + hcid + ")" end # Other pointer types (mutable strings, etc.) — box with a # neutral cls_id of 0 rather than truncating the pointer to int. # A `sp_String *` (mutable_str) is a heap buffer with a `data` # field of const char *. Box it as a string (SP_TAG_STR) so # consumers that dispatch on the tag (sp_poly_to_s, write_response # in roundhouse's Tep::Server, etc.) read the string content # instead of falling through to the SP_TAG_OBJ cls_id=0 case # which matches no arm. Issue #541. Spill the recv to a temp via # a statement-expression so side effects fire exactly once. if at == "mutable_str" mtmp = new_temp return "({ sp_String *" + mtmp + " = " + val + "; " + mtmp + " ? sp_box_str(" + mtmp + "->data) : sp_box_nil(); })" end # Other pointer types — box with a neutral cls_id of 0 rather # than truncating the pointer to int. if type_is_pointer(at) == 1 return "sp_box_obj((void *)(" + val + "), 0)" endtest/mutable_str_into_poly_slot.rbaddedView file
Loading diff…
test/mutable_str_into_poly_slot.rb.expectedaddedView file
Loading diff…