Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
157 changes: 157 additions & 0 deletions patch/1.19.9/lua-resty-core-shared_shdict.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,157 @@
diff --git lib/resty/core/shdict.lua lib/resty/core/shdict.lua
index dedf12c..7644b77 100644
--- lib/resty/core/shdict.lua
+++ lib/resty/core/shdict.lua
@@ -28,7 +28,6 @@ local type = type
local error = error
local getmetatable = getmetatable
local FFI_DECLINED = base.FFI_DECLINED
-local subsystem = ngx.config.subsystem


local ngx_lua_ffi_shdict_get
@@ -42,117 +41,56 @@ local ngx_lua_ffi_shdict_free_space
local ngx_lua_ffi_shdict_udata_to_zone


-if subsystem == 'http' then
- ffi.cdef[[
-int ngx_http_lua_ffi_shdict_get(void *zone, const unsigned char *key,
+ffi.cdef[[
+int ngx_meta_lua_ffi_shdict_get(void *zone, const unsigned char *key,
size_t key_len, int *value_type, unsigned char **str_value_buf,
size_t *str_value_len, double *num_value, int *user_flags,
int get_stale, int *is_stale, char **errmsg);

-int ngx_http_lua_ffi_shdict_incr(void *zone, const unsigned char *key,
+int ngx_meta_lua_ffi_shdict_incr(void *zone, const unsigned char *key,
size_t key_len, double *value, char **err, int has_init,
double init, long init_ttl, int *forcible);

-int ngx_http_lua_ffi_shdict_store(void *zone, int op,
+int ngx_meta_lua_ffi_shdict_store(void *zone, int op,
const unsigned char *key, size_t key_len, int value_type,
const unsigned char *str_value_buf, size_t str_value_len,
double num_value, long exptime, int user_flags, char **errmsg,
int *forcible);

-int ngx_http_lua_ffi_shdict_flush_all(void *zone);
+int ngx_meta_lua_ffi_shdict_flush_all(void *zone);

-long ngx_http_lua_ffi_shdict_get_ttl(void *zone,
+long ngx_meta_lua_ffi_shdict_get_ttl(void *zone,
const unsigned char *key, size_t key_len);

-int ngx_http_lua_ffi_shdict_set_expire(void *zone,
+int ngx_meta_lua_ffi_shdict_set_expire(void *zone,
const unsigned char *key, size_t key_len, long exptime);

-size_t ngx_http_lua_ffi_shdict_capacity(void *zone);
-
-void *ngx_http_lua_ffi_shdict_udata_to_zone(void *zone_udata);
- ]]
-
- ngx_lua_ffi_shdict_get = C.ngx_http_lua_ffi_shdict_get
- ngx_lua_ffi_shdict_incr = C.ngx_http_lua_ffi_shdict_incr
- ngx_lua_ffi_shdict_store = C.ngx_http_lua_ffi_shdict_store
- ngx_lua_ffi_shdict_flush_all = C.ngx_http_lua_ffi_shdict_flush_all
- ngx_lua_ffi_shdict_get_ttl = C.ngx_http_lua_ffi_shdict_get_ttl
- ngx_lua_ffi_shdict_set_expire = C.ngx_http_lua_ffi_shdict_set_expire
- ngx_lua_ffi_shdict_capacity = C.ngx_http_lua_ffi_shdict_capacity
- ngx_lua_ffi_shdict_udata_to_zone =
- C.ngx_http_lua_ffi_shdict_udata_to_zone
-
- if not pcall(function ()
- return C.ngx_http_lua_ffi_shdict_free_space
- end)
- then
- ffi.cdef[[
-size_t ngx_http_lua_ffi_shdict_free_space(void *zone);
- ]]
- end
-
- pcall(function ()
- ngx_lua_ffi_shdict_free_space = C.ngx_http_lua_ffi_shdict_free_space
- end)
+size_t ngx_meta_lua_ffi_shdict_capacity(void *zone);

-elseif subsystem == 'stream' then
+void *ngx_meta_lua_ffi_shdict_udata_to_zone(void *zone_udata);
+]]

+if not pcall(function ()
+ return C.ngx_meta_lua_ffi_shdict_free_space
+end)
+then
ffi.cdef[[
-int ngx_stream_lua_ffi_shdict_get(void *zone, const unsigned char *key,
- size_t key_len, int *value_type, unsigned char **str_value_buf,
- size_t *str_value_len, double *num_value, int *user_flags,
- int get_stale, int *is_stale, char **errmsg);
-
-int ngx_stream_lua_ffi_shdict_incr(void *zone, const unsigned char *key,
- size_t key_len, double *value, char **err, int has_init,
- double init, long init_ttl, int *forcible);
-
-int ngx_stream_lua_ffi_shdict_store(void *zone, int op,
- const unsigned char *key, size_t key_len, int value_type,
- const unsigned char *str_value_buf, size_t str_value_len,
- double num_value, long exptime, int user_flags, char **errmsg,
- int *forcible);
-
-int ngx_stream_lua_ffi_shdict_flush_all(void *zone);
-
-long ngx_stream_lua_ffi_shdict_get_ttl(void *zone,
- const unsigned char *key, size_t key_len);
-
-int ngx_stream_lua_ffi_shdict_set_expire(void *zone,
- const unsigned char *key, size_t key_len, long exptime);
-
-size_t ngx_stream_lua_ffi_shdict_capacity(void *zone);
-
-void *ngx_stream_lua_ffi_shdict_udata_to_zone(void *zone_udata);
+size_t ngx_meta_lua_ffi_shdict_free_space(void *zone);
]]
-
- ngx_lua_ffi_shdict_get = C.ngx_stream_lua_ffi_shdict_get
- ngx_lua_ffi_shdict_incr = C.ngx_stream_lua_ffi_shdict_incr
- ngx_lua_ffi_shdict_store = C.ngx_stream_lua_ffi_shdict_store
- ngx_lua_ffi_shdict_flush_all = C.ngx_stream_lua_ffi_shdict_flush_all
- ngx_lua_ffi_shdict_get_ttl = C.ngx_stream_lua_ffi_shdict_get_ttl
- ngx_lua_ffi_shdict_set_expire = C.ngx_stream_lua_ffi_shdict_set_expire
- ngx_lua_ffi_shdict_capacity = C.ngx_stream_lua_ffi_shdict_capacity
- ngx_lua_ffi_shdict_udata_to_zone =
- C.ngx_stream_lua_ffi_shdict_udata_to_zone
-
- if not pcall(function ()
- return C.ngx_stream_lua_ffi_shdict_free_space
- end)
- then
- ffi.cdef[[
-size_t ngx_stream_lua_ffi_shdict_free_space(void *zone);
- ]]
- end
-
- -- ngx_stream_lua is only compatible with NGINX >= 1.13.6, meaning it
- -- cannot lack support for ngx_stream_lua_ffi_shdict_free_space.
- ngx_lua_ffi_shdict_free_space = C.ngx_stream_lua_ffi_shdict_free_space
-
-else
- error("unknown subsystem: " .. subsystem)
end

+pcall(function ()
+ ngx_lua_ffi_shdict_get = C.ngx_meta_lua_ffi_shdict_get
+ ngx_lua_ffi_shdict_incr = C.ngx_meta_lua_ffi_shdict_incr
+ ngx_lua_ffi_shdict_store = C.ngx_meta_lua_ffi_shdict_store
+ ngx_lua_ffi_shdict_flush_all = C.ngx_meta_lua_ffi_shdict_flush_all
+ ngx_lua_ffi_shdict_get_ttl = C.ngx_meta_lua_ffi_shdict_get_ttl
+ ngx_lua_ffi_shdict_set_expire = C.ngx_meta_lua_ffi_shdict_set_expire
+ ngx_lua_ffi_shdict_capacity = C.ngx_meta_lua_ffi_shdict_capacity
+ ngx_lua_ffi_shdict_free_space = C.ngx_meta_lua_ffi_shdict_free_space
+ ngx_lua_ffi_shdict_udata_to_zone = C.ngx_meta_lua_ffi_shdict_udata_to_zone
+end)
+
if not pcall(function () return C.free end) then
ffi.cdef[[
void free(void *ptr);
Loading