|
| 1 | +diff --git lib/resty/core/shdict.lua lib/resty/core/shdict.lua |
| 2 | +index dedf12c..7644b77 100644 |
| 3 | +--- lib/resty/core/shdict.lua |
| 4 | ++++ lib/resty/core/shdict.lua |
| 5 | +@@ -28,7 +28,6 @@ local type = type |
| 6 | + local error = error |
| 7 | + local getmetatable = getmetatable |
| 8 | + local FFI_DECLINED = base.FFI_DECLINED |
| 9 | +-local subsystem = ngx.config.subsystem |
| 10 | + |
| 11 | + |
| 12 | + local ngx_lua_ffi_shdict_get |
| 13 | +@@ -42,117 +41,56 @@ local ngx_lua_ffi_shdict_free_space |
| 14 | + local ngx_lua_ffi_shdict_udata_to_zone |
| 15 | + |
| 16 | + |
| 17 | +-if subsystem == 'http' then |
| 18 | +- ffi.cdef[[ |
| 19 | +-int ngx_http_lua_ffi_shdict_get(void *zone, const unsigned char *key, |
| 20 | ++ffi.cdef[[ |
| 21 | ++int ngx_meta_lua_ffi_shdict_get(void *zone, const unsigned char *key, |
| 22 | + size_t key_len, int *value_type, unsigned char **str_value_buf, |
| 23 | + size_t *str_value_len, double *num_value, int *user_flags, |
| 24 | + int get_stale, int *is_stale, char **errmsg); |
| 25 | + |
| 26 | +-int ngx_http_lua_ffi_shdict_incr(void *zone, const unsigned char *key, |
| 27 | ++int ngx_meta_lua_ffi_shdict_incr(void *zone, const unsigned char *key, |
| 28 | + size_t key_len, double *value, char **err, int has_init, |
| 29 | + double init, long init_ttl, int *forcible); |
| 30 | + |
| 31 | +-int ngx_http_lua_ffi_shdict_store(void *zone, int op, |
| 32 | ++int ngx_meta_lua_ffi_shdict_store(void *zone, int op, |
| 33 | + const unsigned char *key, size_t key_len, int value_type, |
| 34 | + const unsigned char *str_value_buf, size_t str_value_len, |
| 35 | + double num_value, long exptime, int user_flags, char **errmsg, |
| 36 | + int *forcible); |
| 37 | + |
| 38 | +-int ngx_http_lua_ffi_shdict_flush_all(void *zone); |
| 39 | ++int ngx_meta_lua_ffi_shdict_flush_all(void *zone); |
| 40 | + |
| 41 | +-long ngx_http_lua_ffi_shdict_get_ttl(void *zone, |
| 42 | ++long ngx_meta_lua_ffi_shdict_get_ttl(void *zone, |
| 43 | + const unsigned char *key, size_t key_len); |
| 44 | + |
| 45 | +-int ngx_http_lua_ffi_shdict_set_expire(void *zone, |
| 46 | ++int ngx_meta_lua_ffi_shdict_set_expire(void *zone, |
| 47 | + const unsigned char *key, size_t key_len, long exptime); |
| 48 | + |
| 49 | +-size_t ngx_http_lua_ffi_shdict_capacity(void *zone); |
| 50 | +- |
| 51 | +-void *ngx_http_lua_ffi_shdict_udata_to_zone(void *zone_udata); |
| 52 | +- ]] |
| 53 | +- |
| 54 | +- ngx_lua_ffi_shdict_get = C.ngx_http_lua_ffi_shdict_get |
| 55 | +- ngx_lua_ffi_shdict_incr = C.ngx_http_lua_ffi_shdict_incr |
| 56 | +- ngx_lua_ffi_shdict_store = C.ngx_http_lua_ffi_shdict_store |
| 57 | +- ngx_lua_ffi_shdict_flush_all = C.ngx_http_lua_ffi_shdict_flush_all |
| 58 | +- ngx_lua_ffi_shdict_get_ttl = C.ngx_http_lua_ffi_shdict_get_ttl |
| 59 | +- ngx_lua_ffi_shdict_set_expire = C.ngx_http_lua_ffi_shdict_set_expire |
| 60 | +- ngx_lua_ffi_shdict_capacity = C.ngx_http_lua_ffi_shdict_capacity |
| 61 | +- ngx_lua_ffi_shdict_udata_to_zone = |
| 62 | +- C.ngx_http_lua_ffi_shdict_udata_to_zone |
| 63 | +- |
| 64 | +- if not pcall(function () |
| 65 | +- return C.ngx_http_lua_ffi_shdict_free_space |
| 66 | +- end) |
| 67 | +- then |
| 68 | +- ffi.cdef[[ |
| 69 | +-size_t ngx_http_lua_ffi_shdict_free_space(void *zone); |
| 70 | +- ]] |
| 71 | +- end |
| 72 | +- |
| 73 | +- pcall(function () |
| 74 | +- ngx_lua_ffi_shdict_free_space = C.ngx_http_lua_ffi_shdict_free_space |
| 75 | +- end) |
| 76 | ++size_t ngx_meta_lua_ffi_shdict_capacity(void *zone); |
| 77 | + |
| 78 | +-elseif subsystem == 'stream' then |
| 79 | ++void *ngx_meta_lua_ffi_shdict_udata_to_zone(void *zone_udata); |
| 80 | ++]] |
| 81 | + |
| 82 | ++if not pcall(function () |
| 83 | ++ return C.ngx_meta_lua_ffi_shdict_free_space |
| 84 | ++end) |
| 85 | ++then |
| 86 | + ffi.cdef[[ |
| 87 | +-int ngx_stream_lua_ffi_shdict_get(void *zone, const unsigned char *key, |
| 88 | +- size_t key_len, int *value_type, unsigned char **str_value_buf, |
| 89 | +- size_t *str_value_len, double *num_value, int *user_flags, |
| 90 | +- int get_stale, int *is_stale, char **errmsg); |
| 91 | +- |
| 92 | +-int ngx_stream_lua_ffi_shdict_incr(void *zone, const unsigned char *key, |
| 93 | +- size_t key_len, double *value, char **err, int has_init, |
| 94 | +- double init, long init_ttl, int *forcible); |
| 95 | +- |
| 96 | +-int ngx_stream_lua_ffi_shdict_store(void *zone, int op, |
| 97 | +- const unsigned char *key, size_t key_len, int value_type, |
| 98 | +- const unsigned char *str_value_buf, size_t str_value_len, |
| 99 | +- double num_value, long exptime, int user_flags, char **errmsg, |
| 100 | +- int *forcible); |
| 101 | +- |
| 102 | +-int ngx_stream_lua_ffi_shdict_flush_all(void *zone); |
| 103 | +- |
| 104 | +-long ngx_stream_lua_ffi_shdict_get_ttl(void *zone, |
| 105 | +- const unsigned char *key, size_t key_len); |
| 106 | +- |
| 107 | +-int ngx_stream_lua_ffi_shdict_set_expire(void *zone, |
| 108 | +- const unsigned char *key, size_t key_len, long exptime); |
| 109 | +- |
| 110 | +-size_t ngx_stream_lua_ffi_shdict_capacity(void *zone); |
| 111 | +- |
| 112 | +-void *ngx_stream_lua_ffi_shdict_udata_to_zone(void *zone_udata); |
| 113 | ++size_t ngx_meta_lua_ffi_shdict_free_space(void *zone); |
| 114 | + ]] |
| 115 | +- |
| 116 | +- ngx_lua_ffi_shdict_get = C.ngx_stream_lua_ffi_shdict_get |
| 117 | +- ngx_lua_ffi_shdict_incr = C.ngx_stream_lua_ffi_shdict_incr |
| 118 | +- ngx_lua_ffi_shdict_store = C.ngx_stream_lua_ffi_shdict_store |
| 119 | +- ngx_lua_ffi_shdict_flush_all = C.ngx_stream_lua_ffi_shdict_flush_all |
| 120 | +- ngx_lua_ffi_shdict_get_ttl = C.ngx_stream_lua_ffi_shdict_get_ttl |
| 121 | +- ngx_lua_ffi_shdict_set_expire = C.ngx_stream_lua_ffi_shdict_set_expire |
| 122 | +- ngx_lua_ffi_shdict_capacity = C.ngx_stream_lua_ffi_shdict_capacity |
| 123 | +- ngx_lua_ffi_shdict_udata_to_zone = |
| 124 | +- C.ngx_stream_lua_ffi_shdict_udata_to_zone |
| 125 | +- |
| 126 | +- if not pcall(function () |
| 127 | +- return C.ngx_stream_lua_ffi_shdict_free_space |
| 128 | +- end) |
| 129 | +- then |
| 130 | +- ffi.cdef[[ |
| 131 | +-size_t ngx_stream_lua_ffi_shdict_free_space(void *zone); |
| 132 | +- ]] |
| 133 | +- end |
| 134 | +- |
| 135 | +- -- ngx_stream_lua is only compatible with NGINX >= 1.13.6, meaning it |
| 136 | +- -- cannot lack support for ngx_stream_lua_ffi_shdict_free_space. |
| 137 | +- ngx_lua_ffi_shdict_free_space = C.ngx_stream_lua_ffi_shdict_free_space |
| 138 | +- |
| 139 | +-else |
| 140 | +- error("unknown subsystem: " .. subsystem) |
| 141 | + end |
| 142 | + |
| 143 | ++pcall(function () |
| 144 | ++ ngx_lua_ffi_shdict_get = C.ngx_meta_lua_ffi_shdict_get |
| 145 | ++ ngx_lua_ffi_shdict_incr = C.ngx_meta_lua_ffi_shdict_incr |
| 146 | ++ ngx_lua_ffi_shdict_store = C.ngx_meta_lua_ffi_shdict_store |
| 147 | ++ ngx_lua_ffi_shdict_flush_all = C.ngx_meta_lua_ffi_shdict_flush_all |
| 148 | ++ ngx_lua_ffi_shdict_get_ttl = C.ngx_meta_lua_ffi_shdict_get_ttl |
| 149 | ++ ngx_lua_ffi_shdict_set_expire = C.ngx_meta_lua_ffi_shdict_set_expire |
| 150 | ++ ngx_lua_ffi_shdict_capacity = C.ngx_meta_lua_ffi_shdict_capacity |
| 151 | ++ ngx_lua_ffi_shdict_free_space = C.ngx_meta_lua_ffi_shdict_free_space |
| 152 | ++ ngx_lua_ffi_shdict_udata_to_zone = C.ngx_meta_lua_ffi_shdict_udata_to_zone |
| 153 | ++end) |
| 154 | ++ |
| 155 | + if not pcall(function () return C.free end) then |
| 156 | + ffi.cdef[[ |
| 157 | + void free(void *ptr); |
0 commit comments