Skip to content

Doesn't compile when zend_long is 32-bit (32-bit PHP builds, e.g. wasm32 without ZEND_ENABLE_ZVAL_LONG64) #800

Open

Description

@buvinghausen

ext-php-rs doesn't compile against a PHP whose zend_long is 32-bit — any 32-bit PHP build: wasm32-unknown-emscripten without ZEND_ENABLE_ZVAL_LONG64, i686, armv7. Found while statically linking an ext-php-rs extension into an Emscripten build of PHP 8.5.10; reproduced on master (844d387) and 0.16.0.

Five spots assume zend_long is i64 (5 compile errors):

Location Code Fix
src/constant.rs:214, :222 (*self).into() (i64 → zend_long) (*self).try_into().map_err(|_| Error::IntegerOverflow)?
src/types/array/array_key.rs:168 ArrayKey::Long(key) ArrayKey::Long(key.into())
src/types/array/iterators.rs:117 key.set_long(self.current_num) key.set_long(ZendLong::try_from(self.current_num).ok()?)
src/types/iterator.rs:187 i64::try_from(self.zi.index - 1) ZendLong::try_from(...)
src/zend/globals.rs:696 self.content_length returned as i64 i64::from(self.content_length)

With those five changes the crate builds and the extension runs on 32-bit PHP (checked under node and in headless Chromium). Building PHP with -DZEND_ENABLE_ZVAL_LONG64 (as WordPress Playground does) also avoids it, which is presumably why it hasn't come up.

A related footgun, not strictly a bug: nothing checks that the zend_long width bindgen sees matches the target PHP. Playground's 64-bit zend_long comes from a CFLAGS define that isn't recorded in php_config.h, so leaving -DZEND_ENABLE_ZVAL_LONG64 off the bindgen/cc args silently produces a mismatched ABI. A compile-time assertion on size_of::<zend_long>() against something PHP does record (e.g. SIZEOF_ZEND_LONG, if present in the headers) might catch it.

Happy to send the patch as a PR if you'd like one.

Activity

  1. ptondereau commented on Oct 3, 2026

    @ptondereau
    Member

    Thanks report and this is expected as we currently don't document this platform.
    Feel free to open a PR, but there is a lot a place even in Pure Rust that we use 64bits alignment and scalar type.
    It should also prove the support through 8.2 to 8.5 with the CI

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions