ext-php-rs/allowed_bindings.rs

267 lines
7.0 KiB
Rust
Raw Permalink Normal View History

// This is a cheeky hack - since we need the list of allowed bindings in both
2022-09-10 02:14:42 +02:00
// the build script and in the CLI crate (in different formats), we define the
// `allowed_bindings.rs` file, which calls a macro called `bind` that doesn't
// exist in the bindings file. Which ever script include!s the bindings must
// define the `bind` macro. This allows us to have the list in string format
// inside the build script and in macro format inside the CLI crate.
//
// NOTE TO EDITORS:
// When updating this file, you must re-generate the `docsrs_bindings.rs`
// file used by docs.rs to build documentation. To perform this:
//
// $ cargo clean
// $ cargo build
// $ cp target/debug/build/ext-php-rs-e2cb315d27898d01/out/bindings.rs
// docsrs_bindings.rs
// $ git add . && git commit -m "update docs.rs bindings"
//
// The hash after `ext-php-rs-` in the bindings path may change. There should
// be two folders beginning with `ext-php-rs-` in `target/debug/build`, so
2023-03-13 11:51:29 +01:00
// check both for the presence of the bindings file.
bind! {
HashTable,
_Bucket,
_call_user_function_impl,
_efree,
_emalloc,
_zend_executor_globals,
_zend_expected_type,
_zend_expected_type_Z_EXPECTED_ARRAY,
_zend_expected_type_Z_EXPECTED_BOOL,
_zend_expected_type_Z_EXPECTED_DOUBLE,
_zend_expected_type_Z_EXPECTED_LONG,
_zend_expected_type_Z_EXPECTED_OBJECT,
_zend_expected_type_Z_EXPECTED_RESOURCE,
_zend_expected_type_Z_EXPECTED_STRING,
_zend_new_array,
_zval_struct__bindgen_ty_1,
_zval_struct__bindgen_ty_2,
Windows support (#128) * Preliminary Windows support * Start work on cross-platform build script * Fix compilation on macOS * Updated README, tidied up build script * Check linker version before starting compilation It doesn't seem like it's possible to change the linker from within the build script, however, we can retrieve the linker in use and give the user a suggestion if the linker will not work. * Switch to using Github repository for bindgen * Split Windows and Unix implementations into two files * Fix building on Windows * Remove `reqwest` and `zip` as dependencies on Unix * Fix guide tests on Windows * Started work on Windows CI * runs -> run * Use preinstalled LLVM on Windows * Debugging for Windows CI * Switch to upstream `rust-bindgen` master branch * Switch to `rust-lld` for Windows linking * Don't compile `cargo-php` on Windows * Switch to using skeptic for tests * cargo-php: Disable stub generation, fix ext install/remove The plan is to replace the stub generation by generating them with PHP code. This is cross-platform and means we don't need to worry about ABI. We also don't need to embed information into the library. * cargo-php: Fix on unix OS * Fix clippy lint * Updated README * Re-add CI for Unix + PHP 8.0 * Fix building on thread-safe PHP * Tidy up build scripts * Use dynamic lookup on Linux, test with TS Windows * Define `ZTS` when compiling PHP ZTS * Combine Windows and Unix CI, fix linking for Win32TS * Fix exclusions in build CI * rust-toolchain -> rust * Set LLVM version * Only build docs.rs on Ubuntu PHP 8.1 * Fix build on Linux thread-safe * Update guide example
2022-03-18 04:36:51 +01:00
// ext_php_rs_executor_globals,
// ext_php_rs_php_build_id,
// ext_php_rs_zend_object_alloc,
// ext_php_rs_zend_object_release,
// ext_php_rs_zend_string_init,
// ext_php_rs_zend_string_release,
feat: allows ZendStr to contain null bytes (#202) Closes https://github.com/davidcole1340/ext-php-rs/issues/200 ## Rationale In PHP zend_strings are binary strings with no encoding information. They can contain any byte at any position. The current implementation use `CString` to transfer zend_strings between Rust and PHP, which prevents zend_strings containing null-bytes to roundtrip through the ffi layer. Moreover, `ZendStr::new()` accepts only a `&str`, which is incorrect since a zend_string is not required to be valid UTF8. When reading the PHP source code, it is apparent that most functions marked with `ZEND_API` that accept a `const *char` are convenience wrappers that convert the `const *char` to a zend_string and delegate to another function. For example [zend_throw_exception()](https://github.com/php/php-src/blob/eb83e0206c9b9261d786943bf2c5ad61dca287e2/Zend/zend_exceptions.c#L823) takes a `const *char message`, and just converts it to a zend_string before delegating to [zend_throw_exception_zstr()](https://github.com/php/php-src/blob/eb83e0206c9b9261d786943bf2c5ad61dca287e2/Zend/zend_exceptions.c#L795). I kept this PR focused around `ZendStr` and it's usages in the library, but it should be seen as the first step of a more global effort to remove usages of `CString` everywhere possible. Also, I didn't change the return type of the string related methods of `Zval` (e.g. I could have made `Zval::set_string()` accept an `impl AsRef<[u8]>` instead of `&str` and return `()` instead of `Result<()>`). If I get feedback that it should be done in this PR, I'll do it. ## Summary of the changes: ### ZendStr * [BC break]: `ZendStr::new()` and `ZendStr::new_interned()` now accept an `impl AsRef<[u8]>` instead of just `&str`, and are therefore infaillible (outside of the cases where we panic, e.g. when allocation fails). This is a BC break, but it's impact shouldn't be huge (users will most likely just have to remove a bunch of `?` or add a few `Ok()`). * [BC break]: Conversely, `ZendStr::as_c_str()` now returns a `Result<&CStr>` since it can fail on strings containing null bytes. * [BC break]: `ZensStr::as_str()` now returns a `Result<&str>` instead of an `Option<&str>` since we have to return an error in case of invalid UTF8. * adds method `ZendStr::as_bytes()` to return the underlying byte slice. * adds convenience methods `ZendStr::as_ptr()` and `ZendStr::as_mut_ptr()` to return raw pointers to the zend_string. ### ZendStr conversion traits * adds `impl AsRef<[u8]> for ZendStr` * [BC break]: replaces `impl TryFrom<String> for ZBox<ZendStr>` by `impl From<String> for ZBox<ZendStr>`. * [BC break]: replaces `impl TryFrom<&str> for ZBox<ZendStr>` by `impl From<&str> for ZBox<ZendStr>`. * [BC break]: replaces `impl From<&ZendStr> for &CStr` by `impl TryFrom<&ZendStr> for &CStr`. ### Error * adds new enum member `Error::InvalidUtf8` used when converting a `ZendStr` to `String` or `&str`
2022-12-09 10:54:17 +01:00
// ext_php_rs_is_kown_valid_utf8,
// ext_php_rs_set_kown_valid_utf8,
object_properties_init,
php_error_docref,
php_info_print_table_end,
php_info_print_table_header,
php_info_print_table_row,
php_info_print_table_start,
std_object_handlers,
zend_array_destroy,
zend_array_dup,
zend_call_known_function,
2023-06-22 13:31:56 +02:00
zend_fetch_function_str,
zend_hash_str_find_ptr_lc,
zend_ce_argument_count_error,
zend_ce_arithmetic_error,
zend_ce_compile_error,
zend_ce_division_by_zero_error,
zend_ce_error_exception,
zend_ce_exception,
zend_ce_parse_error,
zend_ce_throwable,
zend_ce_type_error,
zend_ce_unhandled_match_error,
zend_ce_value_error,
zend_ce_traversable,
zend_ce_aggregate,
zend_ce_iterator,
zend_ce_arrayaccess,
zend_ce_serializable,
zend_ce_countable,
zend_ce_stringable,
zend_class_entry,
zend_declare_class_constant,
zend_declare_property,
zend_do_implement_interface,
zend_execute_data,
zend_function_entry,
zend_hash_clean,
zend_hash_index_del,
zend_hash_index_find,
zend_hash_index_update,
zend_hash_next_index_insert,
zend_hash_str_del,
zend_hash_str_find,
zend_hash_str_update,
zend_internal_arg_info,
zend_is_callable,
2023-01-19 12:40:24 +01:00
zend_is_identical,
zend_long,
zend_lookup_class_ex,
zend_module_entry,
zend_object,
zend_object_handlers,
zend_object_std_init,
zend_objects_clone_members,
zend_register_bool_constant,
zend_register_double_constant,
zend_register_ini_entries,
zend_ini_entry_def,
zend_register_internal_class_ex,
zend_register_long_constant,
zend_register_string_constant,
zend_resource,
zend_string,
zend_string_init_interned,
zend_throw_exception_ex,
zend_type,
zend_value,
zend_wrong_parameters_count_error,
zval,
CONST_CS,
CONST_DEPRECATED,
CONST_NO_FILE_CACHE,
CONST_PERSISTENT,
E_ERROR,
E_WARNING,
E_PARSE,
E_NOTICE,
E_CORE_ERROR,
E_CORE_WARNING,
E_COMPILE_ERROR,
E_COMPILE_WARNING,
E_USER_ERROR,
E_USER_WARNING,
E_USER_NOTICE,
E_STRICT,
E_RECOVERABLE_ERROR,
E_DEPRECATED,
E_USER_DEPRECATED,
HT_MIN_SIZE,
IS_ARRAY,
IS_ARRAY_EX,
IS_CALLABLE,
IS_CONSTANT_AST,
IS_CONSTANT_AST_EX,
IS_DOUBLE,
IS_FALSE,
IS_INTERNED_STRING_EX,
IS_LONG,
IS_MIXED,
IS_NULL,
IS_OBJECT,
IS_OBJECT_EX,
IS_REFERENCE,
IS_REFERENCE_EX,
IS_RESOURCE,
IS_RESOURCE_EX,
IS_STRING,
IS_STRING_EX,
IS_TRUE,
IS_TYPE_COLLECTABLE,
IS_TYPE_REFCOUNTED,
IS_UNDEF,
IS_VOID,
IS_PTR,
MAY_BE_ANY,
MAY_BE_BOOL,
PHP_INI_USER,
PHP_INI_PERDIR,
PHP_INI_SYSTEM,
PHP_INI_ALL,
USING_ZTS,
ZEND_ACC_ABSTRACT,
ZEND_ACC_ANON_CLASS,
ZEND_ACC_CALL_VIA_TRAMPOLINE,
ZEND_ACC_CHANGED,
ZEND_ACC_CLOSURE,
ZEND_ACC_CONSTANTS_UPDATED,
ZEND_ACC_CTOR,
ZEND_ACC_DEPRECATED,
ZEND_ACC_DONE_PASS_TWO,
ZEND_ACC_EARLY_BINDING,
ZEND_ACC_FAKE_CLOSURE,
ZEND_ACC_FINAL,
ZEND_ACC_GENERATOR,
ZEND_ACC_HAS_FINALLY_BLOCK,
ZEND_ACC_HAS_RETURN_TYPE,
ZEND_ACC_HAS_TYPE_HINTS,
ZEND_ACC_HAS_UNLINKED_USES,
ZEND_ACC_HEAP_RT_CACHE,
ZEND_ACC_IMMUTABLE,
ZEND_ACC_IMPLICIT_ABSTRACT_CLASS,
ZEND_ACC_INTERFACE,
ZEND_ACC_LINKED,
ZEND_ACC_NEARLY_LINKED,
ZEND_ACC_NEVER_CACHE,
ZEND_ACC_NO_DYNAMIC_PROPERTIES,
ZEND_ACC_PRELOADED,
ZEND_ACC_PRIVATE,
ZEND_ACC_PROMOTED,
ZEND_ACC_PROPERTY_TYPES_RESOLVED,
ZEND_ACC_PROTECTED,
ZEND_ACC_PUBLIC,
ZEND_ACC_RESOLVED_INTERFACES,
ZEND_ACC_RESOLVED_PARENT,
ZEND_ACC_RETURN_REFERENCE,
ZEND_ACC_REUSE_GET_ITERATOR,
ZEND_ACC_STATIC,
ZEND_ACC_STRICT_TYPES,
ZEND_ACC_TOP_LEVEL,
ZEND_ACC_TRAIT,
ZEND_ACC_TRAIT_CLONE,
ZEND_ACC_UNRESOLVED_VARIANCE,
ZEND_ACC_USES_THIS,
ZEND_ACC_USE_GUARDS,
ZEND_ACC_VARIADIC,
ZEND_DEBUG,
ZEND_HAS_STATIC_IN_METHODS,
ZEND_ISEMPTY,
Windows support (#128) * Preliminary Windows support * Start work on cross-platform build script * Fix compilation on macOS * Updated README, tidied up build script * Check linker version before starting compilation It doesn't seem like it's possible to change the linker from within the build script, however, we can retrieve the linker in use and give the user a suggestion if the linker will not work. * Switch to using Github repository for bindgen * Split Windows and Unix implementations into two files * Fix building on Windows * Remove `reqwest` and `zip` as dependencies on Unix * Fix guide tests on Windows * Started work on Windows CI * runs -> run * Use preinstalled LLVM on Windows * Debugging for Windows CI * Switch to upstream `rust-bindgen` master branch * Switch to `rust-lld` for Windows linking * Don't compile `cargo-php` on Windows * Switch to using skeptic for tests * cargo-php: Disable stub generation, fix ext install/remove The plan is to replace the stub generation by generating them with PHP code. This is cross-platform and means we don't need to worry about ABI. We also don't need to embed information into the library. * cargo-php: Fix on unix OS * Fix clippy lint * Updated README * Re-add CI for Unix + PHP 8.0 * Fix building on thread-safe PHP * Tidy up build scripts * Use dynamic lookup on Linux, test with TS Windows * Define `ZTS` when compiling PHP ZTS * Combine Windows and Unix CI, fix linking for Win32TS * Fix exclusions in build CI * rust-toolchain -> rust * Set LLVM version * Only build docs.rs on Ubuntu PHP 8.1 * Fix build on Linux thread-safe * Update guide example
2022-03-18 04:36:51 +01:00
// ZEND_MM_ALIGNMENT,
// ZEND_MM_ALIGNMENT_MASK,
ZEND_MODULE_API_NO,
ZEND_PROPERTY_EXISTS,
ZEND_PROPERTY_ISSET,
Z_TYPE_FLAGS_SHIFT,
_IS_BOOL,
_ZEND_IS_VARIADIC_BIT,
_ZEND_SEND_MODE_SHIFT,
_ZEND_TYPE_NULLABLE_BIT,
ts_rsrc_id,
_ZEND_TYPE_NAME_BIT,
2023-07-19 13:15:36 +02:00
ZEND_INTERNAL_FUNCTION,
ZEND_USER_FUNCTION,
ZEND_EVAL_CODE,
zval_ptr_dtor,
zend_refcounted_h,
zend_is_true,
zend_object_std_dtor,
zend_std_read_property,
zend_std_write_property,
zend_std_get_properties,
zend_std_has_property,
zend_objects_new,
zend_standard_class_def,
zend_class_serialize_deny,
zend_class_unserialize_deny,
Windows support (#128) * Preliminary Windows support * Start work on cross-platform build script * Fix compilation on macOS * Updated README, tidied up build script * Check linker version before starting compilation It doesn't seem like it's possible to change the linker from within the build script, however, we can retrieve the linker in use and give the user a suggestion if the linker will not work. * Switch to using Github repository for bindgen * Split Windows and Unix implementations into two files * Fix building on Windows * Remove `reqwest` and `zip` as dependencies on Unix * Fix guide tests on Windows * Started work on Windows CI * runs -> run * Use preinstalled LLVM on Windows * Debugging for Windows CI * Switch to upstream `rust-bindgen` master branch * Switch to `rust-lld` for Windows linking * Don't compile `cargo-php` on Windows * Switch to using skeptic for tests * cargo-php: Disable stub generation, fix ext install/remove The plan is to replace the stub generation by generating them with PHP code. This is cross-platform and means we don't need to worry about ABI. We also don't need to embed information into the library. * cargo-php: Fix on unix OS * Fix clippy lint * Updated README * Re-add CI for Unix + PHP 8.0 * Fix building on thread-safe PHP * Tidy up build scripts * Use dynamic lookup on Linux, test with TS Windows * Define `ZTS` when compiling PHP ZTS * Combine Windows and Unix CI, fix linking for Win32TS * Fix exclusions in build CI * rust-toolchain -> rust * Set LLVM version * Only build docs.rs on Ubuntu PHP 8.1 * Fix build on Linux thread-safe * Update guide example
2022-03-18 04:36:51 +01:00
zend_executor_globals,
zend_objects_store_del,
zend_hash_move_forward_ex,
zend_hash_get_current_key_type_ex,
zend_hash_get_current_key_zval_ex,
zend_hash_get_current_data_ex,
zend_hash_move_backwards_ex,
zend_array_count,
gc_possible_root,
ZEND_ACC_NOT_SERIALIZABLE,
2022-02-24 10:45:32 +01:00
executor_globals,
2022-02-25 00:37:36 +01:00
php_printf,
Windows support (#128) * Preliminary Windows support * Start work on cross-platform build script * Fix compilation on macOS * Updated README, tidied up build script * Check linker version before starting compilation It doesn't seem like it's possible to change the linker from within the build script, however, we can retrieve the linker in use and give the user a suggestion if the linker will not work. * Switch to using Github repository for bindgen * Split Windows and Unix implementations into two files * Fix building on Windows * Remove `reqwest` and `zip` as dependencies on Unix * Fix guide tests on Windows * Started work on Windows CI * runs -> run * Use preinstalled LLVM on Windows * Debugging for Windows CI * Switch to upstream `rust-bindgen` master branch * Switch to `rust-lld` for Windows linking * Don't compile `cargo-php` on Windows * Switch to using skeptic for tests * cargo-php: Disable stub generation, fix ext install/remove The plan is to replace the stub generation by generating them with PHP code. This is cross-platform and means we don't need to worry about ABI. We also don't need to embed information into the library. * cargo-php: Fix on unix OS * Fix clippy lint * Updated README * Re-add CI for Unix + PHP 8.0 * Fix building on thread-safe PHP * Tidy up build scripts * Use dynamic lookup on Linux, test with TS Windows * Define `ZTS` when compiling PHP ZTS * Combine Windows and Unix CI, fix linking for Win32TS * Fix exclusions in build CI * rust-toolchain -> rust * Set LLVM version * Only build docs.rs on Ubuntu PHP 8.1 * Fix build on Linux thread-safe * Update guide example
2022-03-18 04:36:51 +01:00
__zend_malloc,
tsrm_get_ls_cache,
executor_globals_offset,
zend_atomic_bool_store,
zend_interrupt_function,
zend_eval_string,
zend_file_handle,
zend_stream_init_filename,
php_execute_script,
zend_register_module_ex,
_zend_bailout
}