Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion pixie/ffi-infer.pxi
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,8 @@ return 0;
(defmethod edn-to-ctype :pointer
[{:keys [of-type] :as ptr} in-struct?]
(cond
(and (= of-type {:signed? true :size 1 :type :int})
(and (= (:size of-type) 1)
(= (:type of-type) :int)
(not in-struct?)) 'pixie.stdlib/CCharP
(= (:type of-type) :function) (callback-type of-type in-struct?)
:else 'pixie.stdlib/CVoidP))
Expand Down
19 changes: 14 additions & 5 deletions pixie/vm/libs/ffi.py
Original file line number Diff line number Diff line change
Expand Up @@ -394,8 +394,9 @@ def ffi_set_value(self, ptr, val):
vpnt = rffi.cast(rffi.VOIDPP, ptr)
vpnt[0] = rffi.cast(rffi.VOIDP, val.raw_data())
else:
print val
affirm(False, u"Cannot encode this type")
frm_name = rt.name(rt.str(val.type()))
to_name = rt.name(rt.str(self))
affirm(False, u"Cannot encode " + frm_name + u" as " + to_name)


def ffi_size(self):
Expand Down Expand Up @@ -445,7 +446,13 @@ def ffi_get_value(self, ptr):

def ffi_set_value(self, ptr, val):
pnt = rffi.cast(rffi.VOIDPP, ptr)
if isinstance(val, Buffer):
if isinstance(val, String):
pnt = rffi.cast(rffi.CCHARPP, ptr)
utf8 = unicode_to_utf8(rt.name(val))
raw = rffi.str2charp(utf8)
pnt[0] = raw
return CCharPToken(raw)
elif isinstance(val, Buffer):
pnt[0] = val.buffer()
elif isinstance(val, VoidP):
pnt[0] = val.raw_data()
Expand All @@ -454,8 +461,10 @@ def ffi_set_value(self, ptr, val):
elif isinstance(val, CStruct):
pnt[0] = rffi.cast(rffi.VOIDP, val.raw_data())
else:
print val
affirm(False, u"Cannot encode this type")
frm_name = rt.name(rt.str(val.type()))
to_name = rt.name(rt.str(self))
affirm(False, u"Cannot encode " + frm_name + u" as " + to_name)


def ffi_size(self):
return rffi.sizeof(rffi.VOIDP)
Expand Down
10 changes: 10 additions & 0 deletions pixie/vm/object.py
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,16 @@ def runtime_error(msg):
import pixie.vm.rt as rt
raise WrappedException(RuntimeException(rt.wrap(msg)))

def safe_invoke(f, args):
try:
f.invoke(args)
except Exception as ex:
if isinstance(ex, WrappedException):
print "UNSAFE EXCEPTION", ex._ex.__repr__()
else:
print "UNSAFE EXCEPTION", ex
return None

class ErrorInfo(Object):
_type = Type(u"pixie.stdlib.ErrorInfo")
def type(self):
Expand Down
4 changes: 2 additions & 2 deletions pixie/vm/threads.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from pixie.vm.object import Object, Type
from pixie.vm.object import Object, Type, safe_invoke
from pixie.vm.primitives import true
import rpython.rlib.rthread as rthread
from pixie.vm.primitives import nil
Expand Down Expand Up @@ -42,7 +42,7 @@ def bootstrap():
rthread.gc_thread_start()
fn = bootstrapper.fn()
bootstrapper.release()
fn.invoke([])
safe_invoke(fn, [])
rthread.gc_thread_die()

bootstrapper = Bootstrapper()
Expand Down