Skip to content

Commit

Permalink
Reformat code
Browse files Browse the repository at this point in the history
Signed-off-by: Dusan Malusev <dusan@dusanmalusev.dev>
  • Loading branch information
CodeLieutenant committed Jan 1, 2024
1 parent 3877bab commit dc1fd18
Show file tree
Hide file tree
Showing 23 changed files with 923 additions and 712 deletions.
24 changes: 5 additions & 19 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ env:
CARGO_TERM_COLOR: always
RUST_BACKTRACE: "1"
RUSTFLAGS: "-D warnings"
LLVM_CONFIG_PATH: llvm-config-10
LLVM_CONFIG_PATH: llvm-config-14

jobs:
required:
Expand All @@ -41,15 +41,8 @@ jobs:
fail-fast: false
matrix:
os:
- ubuntu-20.04
- macos-11
- ubuntu-22.04
php-version:
- "7.0"
- "7.1"
- "7.2"
- "7.3"
- "7.4"
- "8.0"
- "8.1"
- "8.2"
- "8.3"
Expand All @@ -60,27 +53,20 @@ jobs:
uses: actions/checkout@v2

- name: Install libclang
if: matrix.os == 'ubuntu-20.04'
run: sudo apt-get install -y llvm-10-dev libclang-10-dev
run: sudo apt-get install -y llvm-dev libclang-dev clang

- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: ${{ matrix.php-version }}
tools: php-config
tools: php-config,composer,composer-prefetcher

- name: Setup php-fpm for Linux
if: matrix.os == 'ubuntu-20.04'
- name: Setup php-fpm
run: |
sudo apt-get install -y php${{ matrix.php-version }}-fpm
sudo rm -f /usr/sbin/php-fpm
sudo ln -s /usr/sbin/php-fpm${{ matrix.php-version }} /usr/sbin/php-fpm
- name: Setup php-fpm for Macos
if: matrix.os == 'macos-11'
run: |
brew install php@${{ matrix.php-version }}
- name: PHP version
run: |
php --version
Expand Down
2 changes: 1 addition & 1 deletion phper-alloc/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
#[macro_use]
mod macros;

use phper_sys::*;
use phper_sys::{phper_efree, phper_emalloc};
use std::{
borrow::Borrow,
mem::{size_of, ManuallyDrop},
Expand Down
72 changes: 43 additions & 29 deletions phper-sys/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,18 @@ use bindgen::Builder;
use std::{env, ffi::OsStr, fmt::Debug, path::PathBuf, process::Command};

fn main() {
println!("cargo:rerun-if-changed=php_wrapper.c");
println!("cargo:rerun-if-env-changed=PHP_CONFIG");
let current_dir = std::env::current_dir().unwrap();

let c_files = std::fs::read_dir(current_dir.join("c"))
.unwrap()
.map(|file| file.unwrap())
.map(|file| file.path().to_string_lossy().to_string())
.collect::<Vec<_>>();

c_files
.iter()
.for_each(|file| println!("cargo:rerun-if-changed={}", file));

let out_path = PathBuf::from(env::var("OUT_DIR").unwrap());
let php_config = env::var("PHP_CONFIG").unwrap_or_else(|_| "php-config".to_string());
Expand All @@ -23,36 +33,40 @@ fn main() {

// Generate libphpwrapper.a.

println!("cargo:warning={:?}", includes);
println!("cargo:warning={:?}", c_files);
let mut builder = cc::Build::new();
for include in &includes {
builder.flag(include);
}
builder.file("php_wrapper.c").compile("phpwrapper");

// Generate bindgen file.
let include_dirs = includes
.iter()
.map(|include| &include[2..])
.collect::<Vec<_>>();
includes.iter().for_each(|include| {
builder.flag(include);
});

for dir in include_dirs.iter() {
println!("cargo:include={}", dir);
}
builder
.cpp(false)
.debug(false)
.files(&c_files)
.extra_warnings(true)
.include("include")
.flag("-falign-functions")
.flag("-flto=auto")
.flag("-std=c2x") // Replace with -std=c23 after CLANG 18
.flag("-pedantic")
.force_frame_pointer(false)
.opt_level(3)
.warnings(true)
.use_plt(false)
.static_flag(true)
.pic(true)
.compile("phpwrapper");

let mut builder = Builder::default()
.header("php_wrapper.c")
.allowlist_file("php_wrapper\\.c")
.header("include/phper.h")
.allowlist_file("include/phper.h")
// .allowlist_recursively(true)
// Block the `zend_ini_parse_quantity` because it's document causes the doc test to fail.
.blocklist_function("zend_ini_parse_quantity")
.clang_args(&includes)
.clang_args(&[
"-falign-functions",
"-flto=auto",
"-std=c17",
"-pedantic",
"-Wextra",
])
.derive_hash(true)
.clang_args(&includes)
.derive_copy(true)
.derive_eq(true)
.derive_ord(true)
Expand All @@ -62,17 +76,17 @@ fn main() {

// iterate over the php include directories, and update the builder
// to only create bindings from the header files in those directories
for dir in include_dirs.iter() {
for dir in includes.iter().map(|include| &include[2..]) {
println!("cargo:include={}", dir);
let p = PathBuf::from(dir).join(".*\\.h");
builder = builder.allowlist_file(p.display().to_string());
}

let generated_path = out_path.join("php_bindings.rs");
let bindings = builder.generate().expect("Unable to generate bindings");

builder
.generate()
.expect("Unable to generate bindings")
.write_to_file(generated_path)
// print!("cargo:warning={}", bindings.to_string());
bindings
.write_to_file(out_path.join("php_bindings.rs"))
.expect("Unable to write output file");
}

Expand Down
9 changes: 9 additions & 0 deletions phper-sys/c/php_alloc.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#include <phper.h>

ZEND_FASTCALL void *phper_emalloc(size_t size) {
return emalloc(size);
}

ZEND_FASTCALL void phper_efree(void *ptr) {
efree(ptr);
}
93 changes: 93 additions & 0 deletions phper-sys/c/php_array.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
#include <phper.h>

ZEND_FASTCALL zval *phper_zend_hash_str_update(HashTable *ht, const char *key,
size_t len, zval *pData) {
return zend_hash_str_update(ht, key, len, pData);
}

ZEND_FASTCALL zval *phper_zend_hash_index_update(HashTable *ht, zend_ulong h,
zval *pData) {
return zend_hash_index_update(ht, h, pData);
}

ZEND_FASTCALL zval *phper_zend_hash_next_index_insert(HashTable *ht,
zval *pData) {
return zend_hash_next_index_insert(ht, pData);
}

ZEND_FASTCALL void phper_array_init(zval *arg) {
array_init(arg);
}

ZEND_FASTCALL void *phper_zend_hash_str_find_ptr(const HashTable *ht,
const char *str, size_t len) {
return zend_hash_str_find_ptr(ht, str, len);
}

ZEND_FASTCALL bool phper_zend_hash_str_exists(const HashTable *ht,
const char *str, size_t len) {
return zend_hash_str_exists(ht, str, len) != 0;
}

ZEND_FASTCALL bool phper_zend_hash_index_exists(const HashTable *ht,
zend_ulong h) {
return zend_hash_index_exists(ht, h) != 0;
}

ZEND_FASTCALL zend_array *phper_zend_new_array(uint32_t size) {
return zend_new_array(size);
}

ZEND_FASTCALL zend_array *phper_zend_array_dup(zend_array *source) {
return zend_array_dup(source);
}

ZEND_FASTCALL zval *phper_zend_hash_index_find(const HashTable *ht,
zend_ulong h) {
return zend_hash_index_find(ht, h);
}

ZEND_FASTCALL bool phper_zend_hash_index_del(HashTable *ht, zend_ulong h) {
return zend_hash_index_del(ht, h) == SUCCESS;
}

ZEND_FASTCALL zval *phper_zend_symtable_str_update(HashTable *ht,
const char *str, size_t len,
zval *pData) {
return zend_symtable_str_update(ht, str, len, pData);
}

ZEND_FASTCALL bool phper_zend_symtable_str_del(HashTable *ht, const char *str,
size_t len) {
return zend_symtable_str_del(ht, str, len) == SUCCESS;
}

ZEND_FASTCALL zval *phper_zend_symtable_str_find(HashTable *ht, const char *str,
size_t len) {
return zend_symtable_str_find(ht, str, len);
}

ZEND_FASTCALL bool phper_zend_symtable_str_exists(HashTable *ht,
const char *str, size_t len) {
return zend_symtable_str_exists(ht, str, len) != 0;
}

ZEND_FASTCALL zval *phper_zend_str_update(HashTable *ht, const char *str,
size_t len, zval *pData) {
return zend_hash_str_update(ht, str, len, pData);
}

ZEND_FASTCALL bool phper_zend_str_del(HashTable *ht, const char *str,
size_t len) {
return zend_hash_str_del(ht, str, len) == SUCCESS;
}

ZEND_FASTCALL zval *phper_zend_str_find(HashTable *ht, const char *str,
size_t len) {
return zend_hash_str_find(ht, str, len);
}

ZEND_FASTCALL bool phper_zend_str_exists(HashTable *ht, const char *str,
size_t len) {
return zend_hash_str_exists(ht, str, len) != 0;
}
97 changes: 97 additions & 0 deletions phper-sys/c/php_smart_string.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
#include <phper.h>
#include <zend_smart_str.h>

ZEND_FASTCALL void phper_smart_str_alloc(smart_str *str, size_t len,
bool persistent) {
smart_str_alloc(str, len, persistent);
}

ZEND_FASTCALL void phper_smart_str_extend_ex(smart_str *dest, size_t len,
bool persistent) {
smart_str_extend_ex(dest, len, persistent);
}

ZEND_FASTCALL void phper_smart_str_erealloc(smart_str *str, size_t len) {
smart_str_erealloc(str, len);
}

ZEND_FASTCALL void phper_smart_str_realloc(smart_str *str, size_t len) {
smart_str_realloc(str, len);
}

ZEND_FASTCALL void phper_smart_str_free_ex(smart_str *str, bool persistent) {
smart_str_free_ex(str, persistent);
}

ZEND_FASTCALL void phper_smart_str_append_escaped(smart_str *str, const char *s,
size_t l) {
smart_str_append_escaped(str, s, l);
}

ZEND_FASTCALL void phper_smart_str_append_double(smart_str *str, double num,
int precision,
bool zero_fraction) {
smart_str_append_double(str, num, precision, zero_fraction);
}

ZEND_FASTCALL void phper_smart_str_append_escaped_truncated(
smart_str *str, const zend_string *value, size_t length) {
smart_str_append_escaped_truncated(str, value, length);
}

ZEND_FASTCALL void phper_smart_str_append_scalar(smart_str *str,
const zval *value,
size_t truncate) {
smart_str_append_scalar(str, value, truncate);
}

ZEND_FASTCALL void phper_smart_str_0(smart_str *str) {
smart_str_0(str);
}

ZEND_FASTCALL size_t phper_smart_str_get_len(const smart_str *str) {
return smart_str_get_len((smart_str *)str);
}

ZEND_FASTCALL zend_string *phper_smart_str_extract(smart_str *str) {
return smart_str_extract(str);
}

ZEND_FASTCALL void phper_smart_str_appendc_ex(smart_str *dest, char ch,
bool persistent) {
smart_str_appendc_ex(dest, ch, persistent);
}

ZEND_FASTCALL void phper_smart_str_appendl_ex(smart_str *dest, const char *str,
size_t len, bool persistent) {
smart_str_appendl_ex(dest, str, len, persistent);
}

ZEND_FASTCALL void phper_smart_str_append_ex(smart_str *dest,
const zend_string *src,
bool persistent) {
smart_str_append_ex(dest, src, persistent);
}

ZEND_FASTCALL void phper_smart_str_append_smart_str_ex(smart_str *dest,
const smart_str *src,
bool persistent) {
smart_str_append_smart_str_ex(dest, src, persistent);
}

ZEND_FASTCALL void phper_smart_str_append_long_ex(smart_str *dest,
zend_long num,
bool persistent) {
smart_str_append_long_ex(dest, num, persistent);
}

ZEND_FASTCALL void phper_smart_str_append_unsigned_ex(smart_str *dest,
zend_ulong num,
bool persistent) {
smart_str_append_unsigned_ex(dest, num, persistent);
}

ZEND_FASTCALL void phper_smart_str_setl(smart_str *dest, const char *src,
size_t len) {
smart_str_setl(dest, src, len);
}
Loading

0 comments on commit dc1fd18

Please sign in to comment.