@@ -60,12 +60,12 @@ static IOFileUD *io_tofile(lua_State *L)
60
60
return iof ;
61
61
}
62
62
63
- static FILE * io_stdfile (lua_State * L , ptrdiff_t id )
63
+ static IOFileUD * io_stdfile (lua_State * L , ptrdiff_t id )
64
64
{
65
65
IOFileUD * iof = IOSTDF_IOF (L , id );
66
66
if (iof -> fp == NULL )
67
67
lj_err_caller (L , LJ_ERR_IOSTDCL );
68
- return iof -> fp ;
68
+ return iof ;
69
69
}
70
70
71
71
static IOFileUD * io_file_new (lua_State * L )
@@ -187,8 +187,9 @@ static int io_file_readlen(lua_State *L, FILE *fp, MSize m)
187
187
}
188
188
}
189
189
190
- static int io_file_read (lua_State * L , FILE * fp , int start )
190
+ static int io_file_read (lua_State * L , IOFileUD * iof , int start )
191
191
{
192
+ FILE * fp = iof -> fp ;
192
193
int ok , n , nargs = (int )(L -> top - L -> base ) - start ;
193
194
clearerr (fp );
194
195
if (nargs == 0 ) {
@@ -224,8 +225,9 @@ static int io_file_read(lua_State *L, FILE *fp, int start)
224
225
return n - start ;
225
226
}
226
227
227
- static int io_file_write (lua_State * L , FILE * fp , int start )
228
+ static int io_file_write (lua_State * L , IOFileUD * iof , int start )
228
229
{
230
+ FILE * fp = iof -> fp ;
229
231
cTValue * tv ;
230
232
int status = 1 ;
231
233
for (tv = L -> base + start ; tv < L -> top ; tv ++ ) {
@@ -257,7 +259,7 @@ static int io_file_iter(lua_State *L)
257
259
memcpy (L -> top , & fn -> c .upvalue [1 ], n * sizeof (TValue ));
258
260
L -> top += n ;
259
261
}
260
- n = io_file_read (L , iof -> fp , 0 );
262
+ n = io_file_read (L , iof , 0 );
261
263
if (ferror (iof -> fp ))
262
264
lj_err_callermsg (L , strVdata (L -> top - 2 ));
263
265
if (tvisnil (L -> base ) && (iof -> type & IOFILE_FLAG_CLOSE )) {
@@ -283,18 +285,18 @@ static int io_file_lines(lua_State *L)
283
285
LJLIB_CF (io_method_close )
284
286
{
285
287
IOFileUD * iof = L -> base < L -> top ? io_tofile (L ) :
286
- IOSTDF_IOF (L , GCROOT_IO_OUTPUT );
288
+ io_stdfile (L , GCROOT_IO_OUTPUT );
287
289
return io_file_close (L , iof );
288
290
}
289
291
290
292
LJLIB_CF (io_method_read )
291
293
{
292
- return io_file_read (L , io_tofile (L )-> fp , 1 );
294
+ return io_file_read (L , io_tofile (L ), 1 );
293
295
}
294
296
295
297
LJLIB_CF (io_method_write ) LJLIB_REC (io_write 0 )
296
298
{
297
- return io_file_write (L , io_tofile (L )-> fp , 1 );
299
+ return io_file_write (L , io_tofile (L ), 1 );
298
300
}
299
301
300
302
LJLIB_CF (io_method_flush ) LJLIB_REC (io_flush 0 )
@@ -456,7 +458,7 @@ LJLIB_CF(io_write) LJLIB_REC(io_write GCROOT_IO_OUTPUT)
456
458
457
459
LJLIB_CF (io_flush ) LJLIB_REC (io_flush GCROOT_IO_OUTPUT )
458
460
{
459
- return luaL_fileresult (L , fflush (io_stdfile (L , GCROOT_IO_OUTPUT )) == 0 , NULL );
461
+ return luaL_fileresult (L , fflush (io_stdfile (L , GCROOT_IO_OUTPUT )-> fp ) == 0 , NULL );
460
462
}
461
463
462
464
static int io_std_getset (lua_State * L , ptrdiff_t id , const char * mode )
0 commit comments