Commits

squeaky  committed df7af94

11 erros

  • Participants
  • Parent commits 0cc929b
  • Branches jython2

Comments (0)

Files changed (3)

File pystacia/api/compat.py

 # This module is part of Pystacia and is released under
 # the MIT License: http://www.opensource.org/licenses/mit-license.php
 
-from ctypes import c_char_p, c_void_p, c_size_t, c_double, c_uint, c_int, byref
+from ctypes import c_char_p, c_size_t, c_double, c_uint, c_int, byref
 
 from pystacia.compat import jython
 
 
 if jython:
     from ctypes import c_ssize_t
-    from pystacia.api.jnatypes import POINTER, find_library, string_at, CDLL
+    from pystacia.api.jnatypes import c_void_p, POINTER, find_library, string_at, CDLL
 else:
-    from ctypes import POINTER, string_at, CDLL #@UnusedImport
+    from ctypes import c_void_p, POINTER, string_at, CDLL #@UnusedImport
     from ctypes.util import find_library  # @UnusedImport
     c_void = None
 

File pystacia/api/func.py

         result = int(result)
     elif c_method.restype == enum:
         result = result.value
-    elif c_method.restype == MagickBoolean and not result.value:
+    elif c_method.restype == MagickBoolean and not result:
         exc_type = ExceptionType()
 
         if c_method.argtypes[0] == MagickWand_p:

File pystacia/api/jnatypes.py

                  Double: ptr.DoubleByReference}
 
 
-class wrappable(object):
-    def __init__(self, j_object=None):
-            self.value = self._j_object = j_object
+class c_void_p(object):
+    _wrap = True
+    _unwrap = True
+    _jffi_type = ctypes.c_ulong._jffi_type
 
+    def __init__(self, value):
+        self.value = value
 
-@memoized
+    def __long__(self):
+        return self.value
+
+
+class c_char_p_p(object):
+    _wrap = True
+    _jffi_type = ctypes.c_void_p._jffi_type
+
+    def __init__(self, value):
+        self.value = Pointer(value)
+
+    def __getitem__(self, idx):
+        return string_at(self.value.getPointer(idx * Pointer.SIZE))
+
+
 def POINTER(type):  # @ReservedAssignment
-    class pointer(wrappable):
-        _j_type = Pointer
-        _to = type
+#    class pointer(wrappable):
+#        _j_type = Pointer
+#        _to = type
+#
+#        def __getitem__(self, idx):
+#            deref = self._j_object.getPointer(idx * Pointer.SIZE)
+#
+#            if issubclass(self._to, wrappable):
+#                deref = self._to(deref)
+#
+#            if hasattr(deref, '_after'):
+#                deref = deref._after()
+#
+#            return deref
+    if type == ctypes.c_char_p:
+        return c_char_p_p
+    else:
+        return ctypes.POINTER(type)
 
-        def __getitem__(self, idx):
-            deref = self._j_object.getPointer(idx * Pointer.SIZE)
 
-            if issubclass(self._to, wrappable):
-                deref = self._to(deref)
+#class c_char(object):
+#    pass
 
-            if hasattr(deref, '_after'):
-                deref = deref._after()
 
-            return deref
+#c_char_p = POINTER(c_char)
+#c_char_p._after = lambda o: str(o._j_object.getString(0))
 
-    return pointer
 
-
-class c_void(object):
-    _j_type = Void
-
-
-class c_char(object):
-    pass
-
-c_void_p = POINTER(c_void)
-
-
-c_char_p = POINTER(c_char)
-c_char_p._after = lambda o: str(o._j_object.getString(0))
-
-
-class c_int(wrappable):
-    _j_type = Integer
-
-
-class c_uint(wrappable):
-    _j_type = Integer
-
-
-_after_size = lambda o: o._j_object.toNative()
-
-
-class c_size_t(wrappable):
-    _j_type = NativeLong
-    _after = _after_size
-
-
-class c_ssize_t(wrappable):
-    _j_type = NativeLong
-    _after = _after_size
-
-
-class c_double(object):
-    _j_type = Double
-
-
-class Reference(object):
-    def __init__(self, o):
-        self._object = o
-        self._j_object = __ref_mapping[o.__class__._j_type]()
-
-    def sync(self):
-        value = self._j_object.getValue()
-        if isinstance(value, NativeLong):
-            value = value.toNative()
-        self._object.value = value
-
-
-def byref(o):
-    return Reference(o)
+#class c_int(wrappable):
+#    _j_type = Integer
+#
+#
+#class c_uint(wrappable):
+#    _j_type = Integer
+#
+#
+#_after_size = lambda o: o._j_object.toNative()
+#
+#
+#class c_size_t(wrappable):
+#    _j_type = NativeLong
+#    _after = _after_size
+#
+#
+#class c_ssize_t(wrappable):
+#    _j_type = NativeLong
+#    _after = _after_size
+#
+#
+#class c_double(object):
+#    _j_type = Double
+#
+#
+#class Reference(object):
+#    def __init__(self, o):
+#        self._object = o
+#        self._j_object = __ref_mapping[o.__class__._j_type]()
+#
+#    def sync(self):
+#        value = self._j_object.getValue()
+#        if isinstance(value, NativeLong):
+#            value = value.toNative()
+#        self._object.value = value
+#
+#
+#def byref(o):
+#    return Reference(o)
 
 
 def string_at(p, length=None):
+    if isinstance(p, c_void_p):
+        p = Pointer(p.value)
+
     if length:
-        return p._j_object.getByteArray(0, length).tostring()
+        return p.getByteArray(0, length).tostring()
 
-    return str(p._j_object.getString(0))
+    return p.getString(0).encode('utf-8')
 
 
 #        args_ = []
         self.__dict__['_func'] = func
 
     def __call__(self, *args):
-        return self._func(*args)
+        func = self._func
+
+        result = func(*args)
+
+        if hasattr(func.restype, '_wrap'):
+            result = func.restype(result)
+
+        return result
 
     def __getattr__(self, name):
         return getattr(self._func, name)