2003/09/20 05:03:47
[org.ibex.core.git] / src / org / xwt / plat / GCJ.cc
index b35c94f..3050a2b 100644 (file)
@@ -1,15 +1,43 @@
-#include <stdlib.h>
-#include <stdio.h>
+// Copyright 2002 Adam Megacz, see the COPYING file for licensing [LGPL]
+
+// Inclusions /////////////////////////////////////////////////////////
+
 #include <gcj/cni.h>
 #include <gcj/array.h>
-#include "jpeglib.h"
-#include <setjmp.h>
+extern "C" {
 
-#include <java/lang/RuntimeException.h>
+// hack for broken Solaris headers
+#define _WCHAR_T
+
+#include <stdlib.h>
+#include <stdio.h>
+#include <setjmp.h>
+#include "jpeglib.h"
+}
+#include <org/xwt/plat/GCJ.h>
 #include <java/io/InputStream.h>
+#include <java/io/ByteArrayInputStream.h>
+#include <java/lang/RuntimeException.h>
 #include <org/xwt/plat/GCJ.h>
 #include <org/xwt/plat/GCJ$JPEG.h>
 
+
+
+// builtin.xwar /////////////////////////////////////////////////////////
+
+extern unsigned char builtin_bytes[];
+extern int builtin_length;
+
+java::io::InputStream* org::xwt::plat::GCJ::_getBuiltinInputStream() {
+    jbyteArray ret = JvNewByteArray(builtin_length);
+    memcpy(elements(ret), builtin_bytes, builtin_length);
+    return new java::io::ByteArrayInputStream(ret);
+}
+
+
+
+// JPEG ////////////////////////////////////////////////////////////////
+
 #define INPUT_BUF_SIZE (1024 * 16)
 
 typedef struct {
@@ -97,4 +125,8 @@ void org::xwt::plat::GCJ$JPEG::nativeDecompress() {
     jpeg_destroy_decompress(&cinfo);
 }
 
-
+// C++ new/delete operators (JvMalloc never fails)
+void* operator new(size_t size) { return JvMalloc(size); }
+void* operator new[](size_t size) { return JvMalloc(size);}
+void operator delete(void *p) { JvFree(p); }
+void operator delete[](void *p) { JvFree(p); }