Clean up addition cython code
diff --git a/bindings/python/Makefile b/bindings/python/Makefile
index 0da867f..bff1eaa 100644
--- a/bindings/python/Makefile
+++ b/bindings/python/Makefile
@@ -12,7 +12,6 @@
# NOTE: Newer cython can be installed by: sudo pip install --upgrade cython
install_cython:
# Copy code from capstone/ to pyx/
- cp capstone/ccapstone.* pyx/
cp capstone/__init__.py pyx/__init__.py
cp capstone/capstone.py pyx/capstone.pyx
cp capstone/arm.py pyx/arm.pyx
diff --git a/bindings/python/capstone/capstone.py b/bindings/python/capstone/capstone.py
index a1921fb..1b4016f 100644
--- a/bindings/python/capstone/capstone.py
+++ b/bindings/python/capstone/capstone.py
@@ -396,12 +396,11 @@
raise CsError(status)
try:
- from ccapstone import CCs
+ import ccapstone
# rewire disasm to use the faster version
- self.ccs = CCs(self)
- self.disasm = self.ccs.disasm
+ self.disasm = ccapstone.Cs(self).disasm
except:
- self.ccs = None
+ pass
if arch == CS_ARCH_X86:
# Intel syntax is default for X86
diff --git a/bindings/python/capstone/ccapstone.pxd b/bindings/python/pyx/ccapstone.pxd
similarity index 100%
rename from bindings/python/capstone/ccapstone.pxd
rename to bindings/python/pyx/ccapstone.pxd
diff --git a/bindings/python/capstone/ccapstone.pyx b/bindings/python/pyx/ccapstone.pyx
similarity index 89%
rename from bindings/python/capstone/ccapstone.pyx
rename to bindings/python/pyx/ccapstone.pyx
index 741a33a..48a4124 100644
--- a/bindings/python/capstone/ccapstone.pyx
+++ b/bindings/python/pyx/ccapstone.pyx
@@ -1,8 +1,6 @@
-cimport ccapstone as cc
-import ctypes
-from capstone import *
-import capstone
-from capstone import arm, x86, mips, ppc, arm64
+cimport pyx.ccapstone as cc
+import capstone, ctypes
+from capstone import arm, x86, mips, ppc, arm64, CsError
class CsDetail:
@@ -31,7 +29,7 @@
(self.bc, self.bh, self.update_cr0, self.operands) = \
ppc.get_arch_info(detail.arch.ppc)
-cdef class CCsInsn(object):
+cdef class CsInsn(object):
cdef cc.cs_insn _raw
cdef cc.csh _csh
@@ -42,6 +40,8 @@
def __getattr__(self, name):
_detail = self._detail
+ if not _detail:
+ raise CsError(capstone.CS_ERR_DETAIL)
return getattr(_detail, name)
@property
@@ -78,7 +78,7 @@
detail = self._detail
return detail.regs_read[:detail.regs_read_count]
- raise CsError(CS_ERR_DETAIL)
+ raise CsError(capstone.CS_ERR_DETAIL)
@property
def regs_write(self):
@@ -86,7 +86,7 @@
detail = self._detail
return detail.regs_write[:detail.regs_write_count]
- raise CsError(CS_ERR_DETAIL)
+ raise CsError(capstone.CS_ERR_DETAIL)
@property
def groups(self):
@@ -94,7 +94,7 @@
detail = self._detail
return detail.groups[:detail.groups_count]
- raise CsError(CS_ERR_DETAIL)
+ raise CsError(capstone.CS_ERR_DETAIL)
# get the last error code
def errno(self):
@@ -137,7 +137,7 @@
if c == position:
return op
-cdef class CCs:
+cdef class Cs:
cdef cc.csh csh
cdef object _cs
@@ -146,9 +146,6 @@
self.csh = <cc.csh> _cs.csh.value
self._cs = _cs
- def getcsh(self):
- return ctypes.c_size_t(<size_t>self.csh)
-
def disasm(self, code, addr, count=0):
cdef cc.cs_insn *allinsn
cdef res = cc.cs_disasm_ex(self.csh, code, len(code), addr, count, &allinsn)
@@ -157,9 +154,9 @@
for i from 0 <= i < res:
if detail:
- dummy = CCsInsn(CsDetail(arch, <size_t>allinsn[i].detail))
+ dummy = CsInsn(CsDetail(arch, <size_t>allinsn[i].detail))
else:
- dummy = CCsInsn(None)
+ dummy = CsInsn(None)
dummy._raw = allinsn[i]
dummy._csh = self.csh
yield dummy