Skip to content

Commit

Permalink
Fix crasher in prim_file:internal_name2native
Browse files Browse the repository at this point in the history
This BIF needs a redo

1. Figure out how it is supposed to work
2. Make it so.

It seems that this should be pretty much like
iolist_to_binary, except it also needs to 
encode the file name according to a local
os-specific encoding.
  • Loading branch information
krestenkrab committed Jun 5, 2012
1 parent 2e16819 commit 0978e4a
Showing 1 changed file with 35 additions and 1 deletion.
36 changes: 35 additions & 1 deletion src/main/java/erjang/m/prim_file/Native.java
@@ -1,15 +1,20 @@
package erjang.m.prim_file; package erjang.m.prim_file;


import java.io.IOException;
import java.nio.charset.Charset;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;


import erjang.BIF; import erjang.BIF;
import erjang.CharCollector;
import erjang.EBinary; import erjang.EBinary;
import erjang.ENative; import erjang.ENative;
import erjang.EObject; import erjang.EObject;
import erjang.ERT; import erjang.ERT;
import erjang.ESeq; import erjang.ESeq;
import erjang.ESmall;
import erjang.EString; import erjang.EString;
import erjang.driver.IO;


public class Native extends ENative public class Native extends ENative
{ {
Expand All @@ -29,12 +34,41 @@ else if (arg.testBinary() != null) {
return new EBinary(outbytes); return new EBinary(outbytes);
} }
else { else {
/*
try {
StringBuilder output = new StringBuilder();
CharCollector out = new CharCollector(IO.ISO_LATIN_1, output);
arg.collectCharList(out);
out.addInteger(0);
out.end();
return new EBinary(output.toString().getBytes(IO.ISO_LATIN_1));
} catch (Exception e) {
throw ERT.badarg();
}
*/
ESeq input = arg.testSeq(); ESeq input = arg.testSeq();
List<Byte> bytes = new ArrayList<Byte>(); List<Byte> bytes = new ArrayList<Byte>();
byte[] out; byte[] out;


ESeq all = input;

while (!input.isNil()) { while (!input.isNil()) {
Integer el = input.head().testSmall().intValue(); EObject first = input.head();
ESmall small = first.testSmall();
if (small == null) {
EBinary bin = first.testBinary();
if (bin == null) {
// it doesn't look like an iolist to me...
throw ERT.badarg();
} else {
for (int i = 0; i < bin.byteSize(); i++) {
bytes.add(bin.byteAt(i));
}
input = input.tail();
continue;
}
}
Integer el = small.intValue();
bytes.add(el.byteValue()); bytes.add(el.byteValue());
input = input.tail(); input = input.tail();
} }
Expand Down

0 comments on commit 0978e4a

Please sign in to comment.