all repos — mgba @ f5312fef786ec0dcad9646fe272bbefd52daa5ff

mGBA Game Boy Advance Emulator

Python: VFS fixes
Jeffrey Pfau jeffrey@endrift.com
Fri, 14 Oct 2016 17:50:47 -0700
commit

f5312fef786ec0dcad9646fe272bbefd52daa5ff

parent

511261b0ffbac7af94d5c33c17f255b74003da5c

2 files changed, 23 insertions(+), 19 deletions(-)

jump to
M src/platform/python/mgba/core.pysrc/platform/python/mgba/core.py

@@ -12,7 +12,7 @@ return None

return Core(core) def findVF(vf): - core = lib.mCoreFindVF(vf.handle()) + core = lib.mCoreFindVF(vf.handle) if core == ffi.NULL: return None return Core(core)

@@ -50,10 +50,10 @@ def loadFile(self, path):

return bool(lib.mCoreLoadFile(self._core, path.encode('UTF-8'))) def isROM(self, vf): - return bool(self._core.isROM(vf.handle())) + return bool(self._core.isROM(vf.handle)) def loadROM(self, vf): - return bool(self._core.loadROM(self._core, vf.handle())) + return bool(self._core.loadROM(self._core, vf.handle)) def autoloadSave(self): return bool(lib.mCoreAutoloadSave(self._core))
M src/platform/python/mgba/vfs.pysrc/platform/python/mgba/vfs.py

@@ -1,3 +1,8 @@

+# Copyright (c) 2013-2016 Jeffrey Pfau +# +# This Source Code Form is subject to the terms of the Mozilla Public +# License, v. 2.0. If a copy of the MPL was not distributed with this +# file, You can obtain one at http://mozilla.org/MPL/2.0/. from _pylib import ffi, lib import mmap import os

@@ -18,13 +23,15 @@ @ffi.def_extern()

def _vfpRead(vf, buffer, size): vfp = ffi.cast("struct VFilePy*", vf) pybuf = ffi.buffer(buffer, size) - return ffi.from_handle(vfp.fileobj).readinto(pybuf) + ffi.from_handle(vfp.fileobj).readinto(pybuf) + return size @ffi.def_extern() def _vfpWrite(vf, buffer, size): vfp = ffi.cast("struct VFilePy*", vf) pybuf = ffi.buffer(buffer, size) - return ffi.from_handle(vfp.fileobj).write(pybuf) + ffi.from_handle(vfp.fileobj).write(pybuf) + return size @ffi.def_extern() def _vfpMap(vf, size, flags):

@@ -90,37 +97,34 @@ return VFile(lib.VFileOpen(path.encode("UTF-8"), flags))

class VFile: def __init__(self, vf): - self._vf = vf - - def handle(self): - return self._vf + self.handle = vf def close(self): - return self._vf.close(self._vf) + return self.handle.close(self.handle) def seek(self, offset, whence): - return self._vf.seek(self._vf, offset, whence) + return self.handle.seek(self.handle, offset, whence) def read(self, buffer, size): - return self._vf.read(self._vf, buffer, size) + return self.handle.read(self.handle, buffer, size) def readline(self, buffer, size): - return self._vf.readline(self._vf, buffer, size) + return self.handle.readline(self.handle, buffer, size) def write(self, buffer, size): - return self._vf.write(self._vf, buffer, size) + return self.handle.write(self.handle, buffer, size) def map(self, size, flags): - return self._vf.map(self._vf, size, flags) + return self.handle.map(self.handle, size, flags) def unmap(self, memory, size): - self._vf.unmap(self._vf, memory, size) + self.handle.unmap(self.handle, memory, size) def truncate(self, size): - self._vf.truncate(self._vf, size) + self.handle.truncate(self.handle, size) def size(self): - return self._vf.size(self._vf) + return self.handle.size(self.handle) def sync(self, buffer, size): - return self._vf.sync(self._vf, buffer, size) + return self.handle.sync(self.handle, buffer, size)