Permalink
Browse files

merged jinglong's "bytecode" branch into "master".

  • Loading branch information...
2 parents 1c6280f + b09b8ee commit 5fa0dbc1fded016389dfde1ec1e624927b95c6a2 @agentzh agentzh committed Jun 14, 2012
Showing with 63 additions and 8 deletions.
  1. +33 −8 src/ngx_http_lua_clfactory.c
  2. +30 −0 t/081-bytecode.t
@@ -209,17 +209,28 @@
*/
/* bytecode for luajit */
-#define LJ_LIF_CODE \
+#define LJ_LIF_CODE_STRIPPED \
"\x14\x03\x00\x01\x00\x01\x00\x03" \
"\x31\x00\x00\x00\x30\x00\x00\x80\x48\x00\x02\x00" \
"\x00\x00"
-#define LJ_BIF_CODE \
+#define LJ_BIF_CODE_STRIPPED \
"\x14\x03\x00\x01\x00\x01\x00\x03" \
"\x00\x00\x00\x31\x80\x00\x00\x30\x00\x02\x00\x48" \
"\x00\x00"
-#define LJ_CODE_LEN 22
+#define LJ_LIF_CODE \
+ "\x15\x03\x00\x01\x00\x01\x00\x03\x00" \
+ "\x31\x00\x00\x00\x30\x00\x00\x80\x48\x00\x02\x00" \
+ "\x00\x00"
+#define LJ_BIF_CODE \
+ "\x15\x03\x00\x01\x00\x01\x00\x03\x00" \
+ "\x00\x00\x00\x31\x80\x00\x00\x30\x00\x02\x00\x48" \
+ "\x00\x00"
+
+#define LJ_CODE_LEN 23
+#define LJ_CODE_LEN_STRIPPED 22
#define LJ_HEADERSIZE 5
#define LJ_BCDUMP_F_BE 0x01
+#define LJ_BCDUMP_F_STRIP 0x02
#define LJ_BCDUMP_VERSION 1
#define LJ_SIGNATURE "\x1b\x4c\x4a"
@@ -270,7 +281,7 @@ ngx_http_lua_clfactory_bytecode_prepare(lua_State *L, clfactory_file_ctx_t *lf,
int fname_index)
{
int x = 1, size_of_int, size_of_size_t, little_endian,
- size_of_inst, version;
+ size_of_inst, version, stripped;
size_t size, bytecode_len;
const char *filename, *emsg, *serr, *bytecode;
ngx_file_info_t fi;
@@ -311,12 +322,27 @@ ngx_http_lua_clfactory_bytecode_prepare(lua_State *L, clfactory_file_ctx_t *lf,
lf->begin_code_len = LJ_HEADERSIZE;
little_endian = !((*(lf->begin_code.str + 4)) & LJ_BCDUMP_F_BE);
+ stripped = (*(lf->begin_code.str + 4)) & LJ_BCDUMP_F_STRIP;
- if (little_endian) {
- lf->end_code.ptr = LJ_LIF_CODE;
+ if (stripped) {
+ if (little_endian) {
+ lf->end_code.ptr = LJ_LIF_CODE_STRIPPED;
+
+ } else {
+ lf->end_code.ptr = LJ_BIF_CODE_STRIPPED;
+ }
+
+ lf->end_code_len = LJ_CODE_LEN_STRIPPED;
} else {
- lf->end_code.ptr = LJ_BIF_CODE;
+ if (little_endian) {
+ lf->end_code.ptr = LJ_LIF_CODE;
+
+ } else {
+ lf->end_code.ptr = LJ_BIF_CODE;
+ }
+
+ lf->end_code_len = LJ_CODE_LEN;
}
if (ngx_fd_info(fileno(lf->f), &fi) == NGX_FILE_ERROR) {
@@ -326,7 +352,6 @@ ngx_http_lua_clfactory_bytecode_prepare(lua_State *L, clfactory_file_ctx_t *lf,
}
lf->rest_len = ngx_file_size(&fi) - LJ_HEADERSIZE;
- lf->end_code_len = LJ_CODE_LEN;
#if defined(DDEBUG) && (DDEBUG)
{
View
@@ -197,3 +197,33 @@ ok
--- response_body
error
+
+
+=== TEST 6: stripped(lua) & no stripped(luajit)
+--- config
+ root html;
+ location /save_call {
+ content_by_lua '
+ ngx.req.read_body();
+ local b = ngx.req.get_body_data();
+ f = io.open(ngx.var.realpath_root.."/test.lua", "w");
+ -- luajit bytecode: sub(149,-1), lua bytecode: sub(1,147)
+ if package.loaded["jit"] then
+ f:write(string.sub(b, 119));
+ else
+ f:write(string.sub(b, 1, 117));
+ end
+ f:close(); res = ngx.location.capture("/call");
+ ngx.print(res.body)
+ ';
+ }
+ location /call {
+ content_by_lua_file $realpath_root/test.lua;
+ }
+--- request eval
+"POST /save_call
+\x1b\x4c\x75\x61\x51\x00\x01\x04\x08\x04\x08\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02\x02\x05\x00\x00\x00\x05\x00\x00\x00\x06\x40\x40\x00\x41\x80\x00\x00\x1c\x40\x00\x01\x1e\x00\x80\x00\x03\x00\x00\x00\x04\x04\x00\x00\x00\x00\x00\x00\x00\x6e\x67\x78\x00\x04\x04\x00\x00\x00\x00\x00\x00\x00\x73\x61\x79\x00\x04\x06\x00\x00\x00\x00\x00\x00\x00\x68\x65\x6c\x6c\x6f\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00
+\x1b\x4c\x4a\x01\x00\x09\x40\x74\x65\x73\x74\x2e\x6c\x75\x61\x32\x02\x00\x02\x00\x03\x00\x05\x06\x00\x02\x34\x00\x00\x00\x37\x00\x01\x00\x25\x01\x02\x00\x3e\x00\x02\x01\x47\x00\x01\x00\x0a\x68\x65\x6c\x6c\x6f\x08\x73\x61\x79\x08\x6e\x67\x78\x01\x01\x01\x01\x01\x00\x00"
+--- response_body
+hello
+

0 comments on commit 5fa0dbc

Please sign in to comment.