Skip to content

Commit

Permalink
merge(*) host properties FFI getter/setter
Browse files Browse the repository at this point in the history
- Properties
  - Rename to project patterns (e.g. `_handler_pt`, `host_props`) and "host property getter/setter" from within the FFI. Since the feature can only be used through the FFI, proxy_wasm_properties know it as "FFI host props getter/setter".
  - Guard feature to OpenResty builds.
  - Share the request pointer between getter/setter.
  - Use `crc32` for rbtree hashes like all other rbtrees in codebase (and move `hash_str` to HTTP-only builds)
  - Various optimizations and readability improvements (e.g. assertions for readers).
- FFI
  - **Breaking change**: rename `proxy_wasm.set_property_(s|g)etter()` to `proxy_wasm.set_host_properties_(s|g)etter()` -> less confusing since `set_property_getter` feels like setting a single property getter handler (and doesn't mention "host properties), while all other parts of the code refer to host properties in plural form. It's "host properties" or "host_props" for code  abbreviations.  In fact speaking about this API, I would even be in favor of merging the setter/getter functions into a single FFI call: `set_host_properties_handlers`, as I do not see the benefit of splitting the operation in two different calls, it feels unnecessarily bloated or "copy-pasted" for easy-mirroring.
  - Re-organize proxy_wasm.lua.
  - Fix FFI definitions signatures (`int`).
  - `store_c_value` without `retrieve` in setter (for the reader).
  - Avoid double-logging getter/setter callback errors.
  - Allow logging in callbacks (with `set_r` patch from Hisham).
  - Obtain callback errors in the FFI `proxy_wasm.get/set_property()` err return value, this error has no stacktrace hence contains some format with the property key.
- Hostcalls
  - Produce a trap on callback errors.
- Tests
  - Trim all test cases to bare-minimum.
  - Switch multiple log checks to `--- grep_error_log`.
  - Test logging in callbacks.
  - Test yielding behavior in callbacks.
  - Test errors through FFI + filters in both getters/setters.
  - Rename and reorder properties tests consistently between 03-proxy-wasm and 04-openresty.
  • Loading branch information
thibaultcha committed Nov 26, 2023
1 parent 712e8e3 commit ef291f3
Show file tree
Hide file tree
Showing 16 changed files with 978 additions and 658 deletions.
8 changes: 4 additions & 4 deletions lib/resty/wasmx.lua
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,13 @@ ffi.cdef [[
ngx_str_t *config;
} ngx_wasm_filter_t;

typedef intptr_t ngx_int_t;
typedef unsigned char u_char;
typedef intptr_t ngx_int_t;
typedef struct ngx_wavm_t ngx_wasm_vm_t;
typedef struct ngx_wasm_ops_plan_t ngx_wasm_plan_t;

typedef ngx_int_t (*ngx_wasm_host_prop_fn_t)(void *data, ngx_str_t *key,
ngx_str_t *value);
typedef ngx_int_t (*ngx_proxy_wasm_properties_ffi_handler_pt)(void *data,
ngx_str_t *key, ngx_str_t *value, ngx_str_t *err);

ngx_wasm_vm_t *ngx_wasm_ffi_main_vm();
]]
Expand Down Expand Up @@ -52,7 +52,7 @@ function _M.get_err_ptr()
local errbuf = get_string_buf(ERR_BUF_SIZE)
local errlen = get_size_ptr()

errlen[0] = ERR_BUF_SIZE
errlen[0] = 0

return errbuf, errlen
end
Expand Down
Loading

0 comments on commit ef291f3

Please sign in to comment.