Skip to content
This repository has been archived by the owner on Sep 30, 2020. It is now read-only.

WIP: implement stream in cwrap (Scheduled for 2.2) #1362

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open

WIP: implement stream in cwrap (Scheduled for 2.2) #1362

wants to merge 5 commits into from

Conversation

pgdr
Copy link
Contributor

@pgdr pgdr commented Dec 13, 2016

No description provided.

TYPE_NAME = "stream"

_fopen = LibcPrototype("void* fopen(char*, char*)")
_fread = LibcPrototype("int fread(void*, int, int, stream)")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These int values should be size_t.

@joakim-hove
Copy link
Contributor

Now - this is ambitious; but would of course be extremely cool if it worked out!

while True:
ch = self.read(1)
out += ch
if ch == '\n':
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess Python has some platform dependent newline encoding somewhere.

raise IOError('File "%s" is closed.' % self._fname)

def read(self, size=-1):
self._ass_open()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hahahaha!

self._mode = mode
self._fname = fname

self.closed = False # A closed file cannot be used for further I/O
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't this be prefixed with _and then have a read only property for closed?


def _bytemode(self):
return 'b' in self._mode
def _textmode(self):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some space please.

return self._fwrite(np_arr.ctypes.data, 1, len(np_arr), self)

def close(self):
print('%s.close()' % self)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Debug?

return 'b' not in self._mode

def _writable(self):
for m in 'wa+':
Copy link
Contributor

@jepebe jepebe Dec 14, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

return any(m in self._mode for m in 'rw+')

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

return any(m in self._mode for m in 'wa+')

@pgdr pgdr changed the title WIP/POC: implement stream in cwrap WIP: implement stream in cwrap (Scheduled for 2.2) Dec 14, 2016
@pgdr pgdr added this to the Ert 2.2 milestone Dec 14, 2016
@joakim-hove
Copy link
Contributor

@pgdr
Copy link
Contributor Author

pgdr commented Jan 30, 2017

Thanks, yes, this implementation needs to be thoroughly discussed. Will the example you linked to have the seek synchronized? One of the main issues is the problem of synchronizing the stream positions, and it doesn't seem like that example handles that.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants