Drop custom PtrCursor (#569)

* Drop custom PtrCursor

* Drop unused crate

* Fixup

---------

Co-authored-by: GG Bond <whatever@tagkong.com>
This commit is contained in:
Vladimir DostoyevskiyandGG Bond authored and GitHub committed 2023-12-31 05:51:14 +00:00
1 parent 28afebefb1
commit fbb030ec8e
2 files changed
+7 -28

No files matched your search

-1
View File
@@ -14,7 +14,6 @@ quick-xml = { default-features = false, version = "0.31" }
tl = "0.7"
log = "0.4"
android_logger = { default-features = false, version = "0.13" }
apply = "0.3"
once_cell = { default-features = false, version = "1.19" }
serde_json = "1.0"
serde = { version = "1.0", features = ["derive"] }
+7 -27
View File
@@ -1,7 +1,6 @@
mod parser;
extern crate android_logger;
extern crate apply;
extern crate jni;
extern crate jni_fn;
extern crate log;
@@ -18,9 +17,9 @@ use jni::JNIEnv;
use log::LevelFilter;
use serde::Serialize;
use std::ffi::c_void;
use std::io::Write;
use std::io::Cursor;
use std::panic::{catch_unwind, UnwindSafe};
use std::ptr::slice_from_raw_parts;
use std::ptr::{slice_from_raw_parts, slice_from_raw_parts_mut};
use std::str::from_utf8_unchecked;
use tl::{Bytes, Node, NodeHandle, Parser, VDom};
@@ -35,28 +34,6 @@ macro_rules! regex {
const EHGT_PREFIX: &str = "https://ehgt.org/";
const EX_PREFIX: &str = "https://s.exhentai.org/";
struct PtrCursor {
ptr: *mut u8,
pos: i32,
}
impl Write for PtrCursor {
fn write(&mut self, buf: &[u8]) -> std::io::Result<usize> {
let len = buf.len();
unsafe {
self.ptr.copy_from(buf.as_ptr(), len);
self.ptr = self.ptr.add(len);
self.pos += len as i32;
}
Ok(len)
}
fn flush(&mut self) -> std::io::Result<()> {
// Nothing
Ok(())
}
}
fn check_html(str: &str) {
if !str.contains('<') {
panic!("{}", str)
@@ -110,9 +87,12 @@ where
// Nothing to marshal
None => 0,
Some(value) => {
let mut cursor = PtrCursor { ptr, pos: 0 };
let mut cursor = unsafe {
let slice = slice_from_raw_parts_mut(ptr, 0x80000);
Cursor::new(&mut *slice)
};
serde_json::to_writer(&mut cursor, &value).unwrap();
cursor.pos
cursor.position() as i32
}
}
};