Skip to content

Reuse allocation of ks_asm#3

Open
tesuji wants to merge 1 commit intoImpalabs:masterfrom
tesuji:reuse-alloc
Open

Reuse allocation of ks_asm#3
tesuji wants to merge 1 commit intoImpalabs:masterfrom
tesuji:reuse-alloc

Conversation

@tesuji
Copy link

@tesuji tesuji commented Sep 19, 2024

Basically this:

-    pub fn asm(&self, insns: String, address: u64) -> Result<KeystoneOutput> {
+    pub fn asm(&self, insns: &CStr, address: u64) -> Result<KeystoneOutput> {
// and
 pub struct KeystoneOutput {
-    /// Size of the array storing the encoded instructions.
-    pub size: u32,
     /// Number of instructions that were successfully encoded.
-    pub stat_count: u32,
-    /// Array of encoded instructions.
-    pub bytes: Vec<u8>,
+    pub stat_count: size_t,
+    /// Size of the array storing the encoded instructions.
+    size: size_t,
+    /// A pointer of allocated encoded instructions.
+    ptr: *mut u8,
+}
+impl Drop for KeystoneOutput {
+    fn drop(&mut self) {
+        unsafe {
+            ffi::ks_free(self.ptr);
+        }
+    }
+}

From keystone-engine/keystone#589 but it stalled

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant