-
Notifications
You must be signed in to change notification settings - Fork 0
/
bug_20171012.txt
579 lines (499 loc) · 17.4 KB
/
bug_20171012.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
(1) return os.date()
reslen = CLib.strftime(new CLib.CharPtr(buff), buff.chars.length, cc, stm); //string kkk = buff.ToString();
->
reslen = CLib.strftime(buff, buff.chars.length, cc, stm); //string kkk = buff.ToString();
public static uint strftime(CharPtr s, uint maxsize, CharPtr format, DateTimeProxy t)
{
-----> s = new CLib.CharPtr(s); //FIXME:
int sIndex = s.index;
(2) java implementation of strftime not complete
(3) add LUA_ENABLE_LUAC environment var
-----> string LUA_ENABLE_LUAC = System.Environment.GetEnvironmentVariable("LUA_ENABLE_LUAC");
...
-----> if (LUA_ENABLE_LUAC != null && LUA_ENABLE_LUAC.Length > 0)
{
(4) not bug
Thread [main] (Suspended (exception ArrayIndexOutOfBoundsException))
CLib$CharPtr.get(int) line: 269
CLib.strlen(CLib$CharPtr) line: 603
LuaIOLib.read_line(LuaState$lua_State, StreamProxy) line: 284
LuaIOLib.g_read(LuaState$lua_State, StreamProxy, int) line: 322
LuaIOLib.io_read(LuaState$lua_State) line: 369
LuaIOLib.access$7(LuaState$lua_State) line: 368
LuaIOLib$LuaIOLib_delegate.exec(LuaState$lua_State) line: 550
LuaDo.luaD_precall(LuaState$lua_State, LuaObject$TValue, int) line: 426
LuaVM.luaV_execute(LuaState$lua_State, int) line: 855
LuaDo.luaD_call(LuaState$lua_State, LuaObject$TValue, int) line: 502
LuaAPI.f_call(LuaState$lua_State, Object) line: 832
LuaAPI.access$0(LuaState$lua_State, Object) line: 830
LuaAPI$f_call_delegate.exec(LuaState$lua_State, Object) line: 837
LuaDo.luaD_rawrunprotected(LuaState$lua_State, LuaDo$Pfunc, Object) line: 162
LuaDo.luaD_pcall(LuaState$lua_State, LuaDo$Pfunc, Object, int, int) line: 603
LuaAPI.lua_pcall(LuaState$lua_State, int, int, int) line: 858
LuaProgram.docall(LuaState$lua_State, int, int) line: 89
LuaProgram.handle_script(LuaState$lua_State, String[], int) line: 242
LuaProgram.pmain(LuaState$lua_State) line: 412
LuaProgram.access$1(LuaState$lua_State) line: 376
LuaProgram$pmain_delegate.exec(LuaState$lua_State) line: 434
LuaDo.luaD_precall(LuaState$lua_State, LuaObject$TValue, int) line: 426
LuaDo.luaD_call(LuaState$lua_State, LuaObject$TValue, int) line: 501
LuaAPI.f_Ccall(LuaState$lua_State, Object) line: 882
LuaAPI.access$1(LuaState$lua_State, Object) line: 873
LuaAPI$f_Ccall_delegate.exec(LuaState$lua_State, Object) line: 887
LuaDo.luaD_rawrunprotected(LuaState$lua_State, LuaDo$Pfunc, Object) line: 162
LuaDo.luaD_pcall(LuaState$lua_State, LuaDo$Pfunc, Object, int, int) line: 603
LuaAPI.lua_cpcall(LuaState$lua_State, Lua$lua_CFunction, Object) line: 897
LuaProgram.MainLua(String[]) line: 464
Program.main(String[]) line: 35
public static int strlen(CharPtr str) {
int index = 0;
index will be larger than str.chars.Length----> while (str.get(index) != '\0') {
index++;
}
return index;
}
(5)
public final int ReadByte() {
if (type == TYPE_STDIN) {
try {
return System.in.read();
} catch (IOException e) {
e.printStackTrace();
}
return 0;
} else if (type == TYPE_FILE) {
if (this._file != null) {
try {
return this._file.read();
} catch (IOException e) {
e.printStackTrace();
}
}
----> return -1;
} else {
return 0;
}
}
public static CharPtr fgets(CharPtr str, StreamProxy stream) {
int index = 0;
try {
while (true) {
str.set(index, (char)stream.ReadByte());
changed---->{{
if (str.get(index) == '\r' || str.get(index) == '\n') {
if (str.get(index) == '\r') {
index--; //ignore
} else if (str.get(index) == '\n') {
if (index >= str.chars.length)
break;
index++;
str.set(index, '\0');
break;
}
}
---->}}
+ ----> if (str.get(index) == '\uffff') { //Ctrl+Z
+ ----> return null;
+ ----> }
if (index >= str.chars.length) {
break;
}
------------------------------
????
\uffff ? \xffff ?
------------------------------
(6) args = new String[] {"-ltest/trace-calls", "test/bisect.lua"}; //throw error
public static class CallInfo implements LuaObject.ArrayElement {
++ ---------->
public static boolean isEqual(CallInfo ci1, CallInfo ci2) //FIXME:add
{
ClassType.Assert(ci1.values == ci2.values);
return ci1.index == ci2.index;
}
private static void traversestack(LuaState.global_State g, LuaState.lua_State l) {
LuaObject.TValue[] o = new LuaObject.TValue[1]; //StkId
o[0] = new LuaObject.TValue();
LuaObject.TValue lim; //StkId
LuaState.CallInfo[] ci = new LuaState.CallInfo[1];
ci[0] = new LuaState.CallInfo();
markvalue(g, LuaState.gt(l));
lim = l.top;
for (ci[0] = l.base_ci[0]; LuaState.CallInfo.lessEqual(ci[0], l.ci); LuaState.CallInfo.inc(ci)) { //ref
LuaLimits.lua_assert(LuaObject.TValue.lessEqual(ci[0].top, l.stack_last));
if (LuaObject.TValue.lessThan(lim, ci[0].top)) {
lim = ci[0].top;
}
----------> //--------------
//FIXME: added, for stopping LuaState.CallInfo.inc(ci) java.lang.ArrayIndexOutOfBoundsException
if (LuaState.CallInfo.isEqual(ci[0], l.ci)) {
break;
}
//--------------
}
for (o[0] = l.stack[0]; LuaObject.TValue.lessThan(o[0], l.top); LuaObject.TValue.inc(o)) { //ref - StkId
markvalue(g, o[0]);
}
for (; LuaObject.TValue.lessEqual(o[0], lim); LuaObject.TValue.inc(o)) { //ref - StkId
LuaObject.setnilvalue(o[0]);
}
checkstacksizes(l, lim);
}
(7) C# StreamProxy no TYPE_* compare
(8) Java Tools.sprintf not implemented well
???I don't know why %08X convert to %08lX
public static String sprintf(String Format, Object... Parameters) {
boolean hasFloat = false;
if (Format.equals(LuaConf.LUA_NUMBER_FMT) && Parameters.length == 1) {
if ((Double)Parameters[0] == ((Double)Parameters[0]).longValue()) {
Format = "%s";
Parameters[0] = ((Double)Parameters[0]).longValue();
} else {
Format = "%s";
hasFloat = true;
}
} else if (Format.equals("%ld")) {
Format = "%d";
---------> } else if (Format.contains("l")) {
---------> Format = Format.replace("l", ""); //FIXME:???, string.format("%08X ",offset)->%08lX
}
} else if (Format.contains("l")) {
//FIXME:???, string.format("%08X ",offset) changed to %08lX
//see addintlen, LuaConf.LUA_INTFRMLEN
-----------> Format = Format.replace(LuaConf.LUA_INTFRMLEN, "");
}
(9)
C#: Stream.Read return 0 if EOF
public int Read(byte[] buffer, int offset, int count)
{
if (this.isOK && this.file != null)
{
---------> return this.file.Read(buffer, offset, count);
}
else
{
return 0;
}
}
Java: RandomAccessFile.read and InputStream.read return -1 if EOF
public final int Read(byte[] buffer, int offset, int count) {
if (type == TYPE_FILE) {
if (this._file != null) {
try {
int result = this._file.read(buffer, offset, count);
---------> return result < 0 ? 0 : result;
} catch (IOException e) {
e.printStackTrace();
}
}
} else if (this.type == TYPE_STDIN) {
try {
int result = System.in.read(buffer, offset, count);
---------> return result < 0 ? 0 : result;
} catch (IOException e) {
e.printStackTrace();
}
}
return 0;
}
(10) string.byte(c)
public static int str_byte(LuaState.lua_State L) {
int[] l = new int[1]; //uint
CLib.CharPtr s = LuaAuxLib.luaL_checklstring(L, 1, l); //out
int posi = posrelat(LuaAuxLib.luaL_optinteger(L, 2, 1), l[0]); //ptrdiff_t - Int32
int pose = posrelat(LuaAuxLib.luaL_optinteger(L, 3, posi), l[0]); //ptrdiff_t - Int32
int n, i;
if (posi <= 0) {
posi = 1;
}
if ((int)pose > l[0]) { //uint
pose = (int)l[0];
}
if (posi > pose) {
return 0; // empty interval; return no values
}
n = (int)(pose - posi + 1);
if (posi + n <= pose) { // overflow?
LuaAuxLib.luaL_error(L, CLib.CharPtr.toCharPtr("string slice too long"));
}
LuaAuxLib.luaL_checkstack(L, n, CLib.CharPtr.toCharPtr("string slice too long"));
for (i = 0; i < n; i++) {
(byte)(xxxx)->(int)(xxx & 0xff) ----------> LuaAPI.lua_pushinteger(L, (int)(s.get(posi + i - 1) & 0xff));
}
return n;
}
(11) windows c version seem eat \r if use pipe redirect input
public final int Read(byte[] buffer, int offset, int count) {
if (type == TYPE_FILE) {
if (this._file != null) {
try {
int result = this._file.read(buffer, offset, count);
return result < 0 ? 0 : result;
} catch (IOException e) {
e.printStackTrace();
}
}
} else if (this.type == TYPE_STDIN) {
//don't use System.in.read(), windows seem eat \r if use pipe redirect input
// int size = 0;
// try {
// for (int i = offset; i < offset + count; ++i) {
// int result = System.in.read();
// if (result < 0) {
// break;
// }
// buffer[offset + i] = (byte)result;
// size++;
// }
// }
// catch (IOException e) {
// e.printStackTrace();
// }
// return size;
try {
int result = System.in.read(buffer, offset, count);
return result < 0 ? 0 : result;
} catch (IOException e) {
e.printStackTrace();
}
(12) RandomAccessFile not very same as fopen()
java.lang.IllegalArgumentException: Illegal mode "wb" must be one of "r", "rw", "rws", or "rwd"
java.lang.IllegalArgumentException: Illegal mode "wb" must be one of "r", "rw", "rws", or "rwd"
at java.io.RandomAccessFile.<init>(RandomAccessFile.java:197)
at java.io.RandomAccessFile.<init>(RandomAccessFile.java:98)
at kurumi.StreamProxy.<init>(StreamProxy.java:21)
at kurumi.CLib.fopen(CLib.java:764)
at kurumi.LuaIOLib.io_open(LuaIOLib.java:154)
at kurumi.LuaIOLib.access$4(LuaIOLib.java:150)
at kurumi.LuaIOLib$LuaIOLib_delegate.exec(LuaIOLib.java:541)
at kurumi.LuaDo.luaD_precall(LuaDo.java:426)
at kurumi.LuaVM.luaV_execute(LuaVM.java:855)
at kurumi.LuaDo.luaD_call(LuaDo.java:502)
at kurumi.LuaAPI.f_call(LuaAPI.java:832)
at kurumi.LuaAPI.access$0(LuaAPI.java:830)
at kurumi.LuaAPI$f_call_delegate.exec(LuaAPI.java:837)
at kurumi.LuaDo.luaD_rawrunprotected(LuaDo.java:162)
at kurumi.LuaDo.luaD_pcall(LuaDo.java:603)
at kurumi.LuaAPI.lua_pcall(LuaAPI.java:858)
at kurumi.LuaProgram.docall(LuaProgram.java:89)
at kurumi.LuaProgram.handle_script(LuaProgram.java:242)
at kurumi.LuaProgram.pmain(LuaProgram.java:412)
at kurumi.LuaProgram.access$1(LuaProgram.java:376)
at kurumi.LuaProgram$pmain_delegate.exec(LuaProgram.java:434)
at kurumi.LuaDo.luaD_precall(LuaDo.java:426)
at kurumi.LuaDo.luaD_call(LuaDo.java:501)
at kurumi.LuaAPI.f_Ccall(LuaAPI.java:882)
at kurumi.LuaAPI.access$1(LuaAPI.java:873)
at kurumi.LuaAPI$f_Ccall_delegate.exec(LuaAPI.java:887)
at kurumi.LuaDo.luaD_rawrunprotected(LuaDo.java:162)
at kurumi.LuaDo.luaD_pcall(LuaDo.java:603)
at kurumi.LuaAPI.lua_cpcall(LuaAPI.java:897)
at kurumi.LuaProgram.MainLua(LuaProgram.java:464)
at kurumi.Program.main(Program.java:35)
public static StreamProxy fopen(CharPtr filename, CharPtr mode) {
String str = filename.toString();
String modeStr = "";
for (int i = 0; mode.get(i) != '\0'; i++) {
modeStr += mode.get(i);
}
try {
StreamProxy result = new StreamProxy(str, modeStr);
if (result.isOK) {
return result;
}
else {
return null;
}
}
catch (java.lang.Exception e) {
---------------> e.printStackTrace();
return null;
}
}
public StreamProxy(String path, String modeStr) {
this.isOK = false;
try {
if (modeStr != null) {
---------> modeStr = modeStr.replace("b", "");
}
this._file = new RandomAccessFile(path, modeStr);
this.isOK = true;
} catch (FileNotFoundException e) {
e.printStackTrace();
}
this.type = TYPE_FILE;
}
(13) ObjToBytes2(b) -> ObjToBytes2(b, t, size)
@@ -139,11 +139,11 @@ public class LuaStrLib {
private static int writer(LuaState.lua_State L, Object b, int size, Object B, ClassType t) { //uint
//FIXME:b always is CharPtr
//if (b.GetType() != typeof(CharPtr))
if (t.GetTypeID() == ClassType.TYPE_CHARPTR) {
- byte[] bytes = t.ObjToBytes2(b);
+ byte[] bytes = t.ObjToBytes2(b, t, size);
char[] chars = new char[bytes.length];
for (int i = 0; i < bytes.length; i++) {
chars[i] = (char)bytes[i];
}
b = new CLib.CharPtr(chars);
public static void DumpMem(Object b, DumpState D, ClassType t) {
- byte[] bytes = t.ObjToBytes(b);
+ byte[] bytes = t.ObjToBytes(b, t, 0);
char[] ch = new char[bytes.length];
for (int i = 0; i < bytes.length; i++) {
ch[i] = (char)bytes[i];
}
CLib.CharPtr str = CLib.CharPtr.toCharPtr(ch);
//only byValue type
- public final byte[] ObjToBytes(Object b) {
+ public final byte[] ObjToBytes(Object b, ClassType t, int size) {
if (DONNOT_USE_REIMPLEMENT) {
return ObjToBytes_csharp(b);
}
else {
//TODO:not implemented
+ //return null;
+ if (b instanceof CLib.CharPtr && size > 0) {
+ CLib.CharPtr ptr = (CLib.CharPtr)b;
+ char[] chars = ptr.chars;
+ byte[] result = new byte[size];
+ for (int i = 0; i < chars.length && i < size; i++) {
+ result[i] = (byte)(chars[i] & 0xff);
+ }
+ return result;
+ }
return null;
//LuaDump.DumpMem not work
//LuaStrLib.writer not work
}
}
//TODO:need reimplementation
- public final byte[] ObjToBytes2(Object b) {
+ public final byte[] ObjToBytes2(Object b, ClassType t, int size) {
if (DONNOT_USE_REIMPLEMENT) {
return ObjToBytes2_csharp(b);
}
else {
- return ObjToBytes(b);
+ return ObjToBytes(b, t, size);
}
}
//TODO:need reimplementation
public final Object bytesToObj(byte[] bytes) {
(14) luac.lua
public static void luaU_header(CLib.CharPtr h) {
h = new CLib.CharPtr(h);
int x = 1;
CLib.memcpy(h, CLib.CharPtr.toCharPtr(Lua.LUA_SIGNATURE), Lua.LUA_SIGNATURE.length());
h = h.add(Lua.LUA_SIGNATURE.length());
h.set(0, (char)LUAC_VERSION);
h.inc();
h.set(0, (char)LUAC_FORMAT);
h.inc();
//*h++=(char)*(char*)&x; /* endianness */
--------> h.set(0, (char)x); // endianness //endianness (1=little endian)
h.inc();
h.set(0, (char)ClassType.SizeOfInt());
h.inc();
//FIXME:
---------> h.set(0, (char)ClassType.SizeOfInt()); //size of size_t
//sizeof(long/*uint*/)
h.inc();
---------> h.set(0, (char)ClassType.SizeOfInt()); //size of Instruction
//sizeof(long/*UInt32*//*Instruction*/));
h.inc();
h.set(0, (char)ClassType.SizeOfDouble());
//sizeof(Double/*lua_Number*/)
h.inc();
//(h++)[0] = ((lua_Number)0.5 == 0) ? 0 : 1; /* is lua_Number integral? */
h.set(0, (char)0); // always 0 on this build
}
-------->%02X
public static int fwrite(CharPtr ptr, int size, int num, StreamProxy stream) {
int num_bytes = num * size;
byte[] bytes = new byte[num_bytes];
for (int i = 0; i < num_bytes; i++) {
bytes[i] = (byte)(ptr.get(i) & 0xff);
-------->// System.out.print(String.format("%02X,", bytes[i]));
// if (i % 16 == 15) {
// System.out.println();
// }
}
private static int writer(LuaState.lua_State L, Object b, int size, Object B, ClassType t) { //uint
//FIXME:b always is CharPtr
//if (b.GetType() != typeof(CharPtr))
if (t.GetTypeID() == ClassType.TYPE_CHARPTR) {
byte[] bytes = t.ObjToBytes2(b, t, size);
char[] chars = new char[bytes.length];
for (int i = 0; i < bytes.length; i++) {
chars[i] = (char)bytes[i];
-------->// System.out.print(String.format("%02X", (byte)(chars[i] & 0xff)));
}
// System.out.println();
b = new CLib.CharPtr(chars);
}
LuaAuxLib.luaL_addlstring((LuaAuxLib.luaL_Buffer)B, (CLib.CharPtr)b, size);
return 0;
}
//only byValue type
public final byte[] ObjToBytes(Object b, ClassType t, int size) {
if (DONNOT_USE_REIMPLEMENT) {
return ObjToBytes_csharp(b);
}
else {
//TODO:not implemented
//return null;
if (t.type == TYPE_CHARPTR && size >= 0) {
CLib.CharPtr ptr = (CLib.CharPtr)b;
char[] chars = ptr.chars;
byte[] result = new byte[size];
for (int i = 0; i < chars.length && i < size; i++) {
result[i] = (byte)(chars[i] & 0xff);
}
return result;
} else if (t.type == TYPE_INT) {
int a = ((Integer)b).intValue();
return new byte[] {
(byte) (a & 0xFF),
(byte) ((a >> 8) & 0xFF),
(byte) ((a >> 16) & 0xFF),
(byte) ((a >> 24) & 0xFF),
};
} else if (t.type == TYPE_CHAR) {
char a = ((Character)b).charValue();
return new byte[] {
(byte) (a & 0xFF)
};
} else if (t.type == TYPE_LONG) {
long data = ((Long)b).longValue();
byte[] bytes = new byte[4];
bytes[0] = (byte) (data & 0xff);
bytes[1] = (byte) ((data >> 8) & 0xff);
bytes[2] = (byte) ((data >> 16) & 0xff);
bytes[3] = (byte) ((data >> 24) & 0xff);
for code array 32bit---------------->// bytes[4] = (byte) ((data >> 32) & 0xff);
// bytes[5] = (byte) ((data >> 40) & 0xff);
// bytes[6] = (byte) ((data >> 48) & 0xff);
// bytes[7] = (byte) ((data >> 56) & 0xff);
//debug code array dump
// for (int i = 0; i < 4; ++i) {
// System.out.print(String.format("%02X, ", bytes[i]));
// }
// System.out.println();
return bytes;
public final void Write(byte[] buffer, int offset, int count) {
if (this.type == TYPE_STDOUT) {
System.out.print(new String(buffer, offset, count));
} else if (this.type == TYPE_STDERR) {
System.err.print(new String(buffer, offset, count));
} else if (this.type == TYPE_FILE) {
if (this._file != null) {
try {
-----------> this._file.write(buffer, offset, count); //FIXME:don't use writeBytes(String s)
} catch (IOException e) {
e.printStackTrace();
}
}
} else {
//FIXME:TODO
}
}