PageRenderTime 48ms CodeModel.GetById 23ms RepoModel.GetById 0ms app.codeStats 0ms

/pypy/module/_rawffi/buffer.py

https://bitbucket.org/pypy/pypy/
Python | 27 lines | 18 code | 8 blank | 1 comment | 0 complexity | ec2233fdb3c2aada08ab0f2709c33172 MD5 | raw file
Possible License(s): AGPL-3.0, BSD-3-Clause, Apache-2.0
  1. from rpython.rlib.buffer import Buffer
  2. from rpython.rtyper.lltypesystem import rffi
  3. # XXX not the most efficient implementation
  4. class RawFFIBuffer(Buffer):
  5. _immutable_ = True
  6. def __init__(self, datainstance):
  7. self.datainstance = datainstance
  8. self.readonly = False
  9. def getlength(self):
  10. return self.datainstance.getrawsize()
  11. def getitem(self, index):
  12. ll_buffer = self.datainstance.ll_buffer
  13. return ll_buffer[index]
  14. def setitem(self, index, char):
  15. ll_buffer = self.datainstance.ll_buffer
  16. ll_buffer[index] = char
  17. def get_raw_address(self):
  18. ll_buffer = self.datainstance.ll_buffer
  19. return rffi.cast(rffi.CCHARP, ll_buffer)