aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorMike Pall <mike>2012-09-28 17:54:18 +0200
committerMike Pall <mike>2012-09-28 17:54:18 +0200
commit7a6bb9a20836107cd715a818072cbbd1c8eac516 (patch)
treef23c482d298e49a929b66474d2850d8bbc3d12f2 /src
parent26841296ab9e5f6d5df1a720e185334d5e84936b (diff)
downloadluajit-7a6bb9a20836107cd715a818072cbbd1c8eac516.tar.gz
luajit-7a6bb9a20836107cd715a818072cbbd1c8eac516.tar.bz2
luajit-7a6bb9a20836107cd715a818072cbbd1c8eac516.zip
From Lua 5.2: Return file object for io.write() and file:write().
Needs -DLUAJIT_ENABLE_LUA52COMPAT.
Diffstat (limited to 'src')
-rw-r--r--src/lib_io.c6
-rw-r--r--src/lj_ffrecord.c9
2 files changed, 11 insertions, 4 deletions
diff --git a/src/lib_io.c b/src/lib_io.c
index 142bfae5..e0762297 100644
--- a/src/lib_io.c
+++ b/src/lib_io.c
@@ -244,6 +244,12 @@ static int io_file_write(lua_State *L, FILE *fp, int start)
244 lj_err_argt(L, (int)(tv - L->base) + 1, LUA_TSTRING); 244 lj_err_argt(L, (int)(tv - L->base) + 1, LUA_TSTRING);
245 } 245 }
246 } 246 }
247 if (LJ_52 && status) {
248 L->top = L->base+1;
249 if (start == 0)
250 setudataV(L, L->base, IOSTDF_UD(L, GCROOT_IO_OUTPUT));
251 return 1;
252 }
247 return luaL_fileresult(L, status, NULL); 253 return luaL_fileresult(L, status, NULL);
248} 254}
249 255
diff --git a/src/lj_ffrecord.c b/src/lj_ffrecord.c
index 39c3140f..b9e0d8f9 100644
--- a/src/lj_ffrecord.c
+++ b/src/lj_ffrecord.c
@@ -781,7 +781,7 @@ static void LJ_FASTCALL recff_table_insert(jit_State *J, RecordFFData *rd)
781/* Get FILE* for I/O function. Any I/O error aborts recording, so there's 781/* Get FILE* for I/O function. Any I/O error aborts recording, so there's
782** no need to encode the alternate cases for any of the guards. 782** no need to encode the alternate cases for any of the guards.
783*/ 783*/
784static TRef recff_io_fp(jit_State *J, uint32_t id) 784static TRef recff_io_fp(jit_State *J, TRef *udp, int32_t id)
785{ 785{
786 TRef tr, ud, fp; 786 TRef tr, ud, fp;
787 if (id) { /* io.func() */ 787 if (id) { /* io.func() */
@@ -794,6 +794,7 @@ static TRef recff_io_fp(jit_State *J, uint32_t id)
794 tr = emitir(IRT(IR_FLOAD, IRT_U8), ud, IRFL_UDATA_UDTYPE); 794 tr = emitir(IRT(IR_FLOAD, IRT_U8), ud, IRFL_UDATA_UDTYPE);
795 emitir(IRTGI(IR_EQ), tr, lj_ir_kint(J, UDTYPE_IO_FILE)); 795 emitir(IRTGI(IR_EQ), tr, lj_ir_kint(J, UDTYPE_IO_FILE));
796 } 796 }
797 *udp = ud;
797 fp = emitir(IRT(IR_FLOAD, IRT_PTR), ud, IRFL_UDATA_FILE); 798 fp = emitir(IRT(IR_FLOAD, IRT_PTR), ud, IRFL_UDATA_FILE);
798 emitir(IRTG(IR_NE, IRT_PTR), fp, lj_ir_knull(J, IRT_PTR)); 799 emitir(IRTG(IR_NE, IRT_PTR), fp, lj_ir_knull(J, IRT_PTR));
799 return fp; 800 return fp;
@@ -801,7 +802,7 @@ static TRef recff_io_fp(jit_State *J, uint32_t id)
801 802
802static void LJ_FASTCALL recff_io_write(jit_State *J, RecordFFData *rd) 803static void LJ_FASTCALL recff_io_write(jit_State *J, RecordFFData *rd)
803{ 804{
804 TRef fp = recff_io_fp(J, rd->data); 805 TRef ud, fp = recff_io_fp(J, &ud, rd->data);
805 TRef zero = lj_ir_kint(J, 0); 806 TRef zero = lj_ir_kint(J, 0);
806 TRef one = lj_ir_kint(J, 1); 807 TRef one = lj_ir_kint(J, 1);
807 ptrdiff_t i = rd->data == 0 ? 1 : 0; 808 ptrdiff_t i = rd->data == 0 ? 1 : 0;
@@ -820,12 +821,12 @@ static void LJ_FASTCALL recff_io_write(jit_State *J, RecordFFData *rd)
820 emitir(IRTGI(IR_EQ), tr, len); 821 emitir(IRTGI(IR_EQ), tr, len);
821 } 822 }
822 } 823 }
823 J->base[0] = TREF_TRUE; 824 J->base[0] = LJ_52 ? ud : TREF_TRUE;
824} 825}
825 826
826static void LJ_FASTCALL recff_io_flush(jit_State *J, RecordFFData *rd) 827static void LJ_FASTCALL recff_io_flush(jit_State *J, RecordFFData *rd)
827{ 828{
828 TRef fp = recff_io_fp(J, rd->data); 829 TRef ud, fp = recff_io_fp(J, &ud, rd->data);
829 TRef tr = lj_ir_call(J, IRCALL_fflush, fp); 830 TRef tr = lj_ir_call(J, IRCALL_fflush, fp);
830 if (results_wanted(J) != 0) /* Check result only if not ignored. */ 831 if (results_wanted(J) != 0) /* Check result only if not ignored. */
831 emitir(IRTGI(IR_EQ), tr, lj_ir_kint(J, 0)); 832 emitir(IRTGI(IR_EQ), tr, lj_ir_kint(J, 0));