Sha256: d90e2f05b385dbb858514b1f38c34ad1fab8cb759684a47c6f5131dea7fc176a
Contents?: true
Size: 1021 Bytes
Versions: 1
Compression:
Stored size: 1021 Bytes
Contents
module PyCall class PyError < StandardError def self.fetch ptrs = FFI::MemoryPointer.new(:pointer, 3) ptype = ptrs + 0 * ptrs.type_size pvalue = ptrs + 1 * ptrs.type_size ptraceback = ptrs + 2 * ptrs.type_size LibPython.PyErr_Fetch(ptype, pvalue, ptraceback) LibPython.PyErr_NormalizeException(ptype, pvalue, ptraceback) type = Conversions.to_ruby(ptype.read(:pointer)) value = Conversions.to_ruby(pvalue.read(:pointer)) traceback = Conversions.to_ruby(ptraceback.read(:pointer)) new(type, value, traceback) end def initialize(type, value, traceback) @type = type @value = value @traceback = traceback super("Error occurred in Python") end attr_reader :type, :value, :traceback def to_s "#{type}: #{value}".tap do |msg| unless traceback&.null? if (o = PyCall.format_traceback(traceback)) msg.concat("\n", *o) end end end end end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
pycall-0.1.0.alpha.20170311 | lib/pycall/pyerror.rb |