Skip to content

PPC64: use pointer-width accesses when resetting string buffer - #276

Open
mchoo7 wants to merge 1 commit into
openresty:v2.1-agentzhfrom
mchoo7:ppc
Open

PPC64: use pointer-width accesses when resetting string buffer#276
mchoo7 wants to merge 1 commit into
openresty:v2.1-agentzhfrom
mchoo7:ppc

Conversation

@mchoo7

@mchoo7 mchoo7 commented Sep 5, 2026

Copy link
Copy Markdown

The PPC string lower/upper/reverse fast-function wrapper resets SBuf::w from SBuf::b using lwz/stw. Both fields are char pointers, so these 32-bit accesses are incorrect on PPC64.

This breaks the reset on big-endian PPC64, causing string.lower(), string.upper(), and string.reverse() to append to stale temporary buffer contents.

Use lp/stp so the accesses have the target pointer width.

The PPC string lower/upper/reverse fast-function wrapper resets
SBuf::w from SBuf::b using lwz/stw. Both fields are char pointers,
so these 32-bit accesses are incorrect on PPC64.

This breaks the reset on big-endian PPC64, causing string.lower(),
string.upper(), and string.reverse() to append to stale temporary
buffer contents.

Use lp/stp so the accesses have the target pointer width.
@zhuizhuhaomeng

Copy link
Copy Markdown
Contributor

Found one blocking issue relative to origin/v2.1-agentzh:

  • [P1] Preserve the array search before calling tab_len_slowsrc/lj_tab.c:672. The slow path assumes hi is a valid non-nil lower bound. Passing t->asize - 1 unconditionally violates that assumption when the array has trailing nil entries, returning allocated capacity instead of length. This breaks #t and operations such as table.remove. Retain the array-boundary search or adapt the slow path to handle trailing nil entries.

Confirmed in an isolated native build with the PPC64 C path enabled:

Check Changed path Original path
{1,2,3} after t[3] = nil 4 2
Empty table.new(100, 0) 100 0
Existing table_remove.lua Fails Passes

Can you check the review by AI @mchoo7

@mchoo7

mchoo7 commented Sep 6, 2026

Copy link
Copy Markdown
Author

Found one blocking issue relative to origin/v2.1-agentzh:

  • [P1] Preserve the array search before calling tab_len_slowsrc/lj_tab.c:672. The slow path assumes hi is a valid non-nil lower bound. Passing t->asize - 1 unconditionally violates that assumption when the array has trailing nil entries, returning allocated capacity instead of length. This breaks #t and operations such as table.remove. Retain the array-boundary search or adapt the slow path to handle trailing nil entries.

Confirmed in an isolated native build with the PPC64 C path enabled:

Check Changed path Original path
{1,2,3} after t[3] = nil 4 2
Empty table.new(100, 0) 100 0
Existing table_remove.lua Fails Passes
Can you check the review by AI @mchoo7

This PR does not touch src/lj_tab.c. All it does is fixing wrong load/store size. Thus this PR has no relation with the AI review mentioned above.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants