tychota / pyv8

Automatically exported from code.google.com/p/pyv8
0 stars 0 forks source link

class instance not derived from object returned as Global causes segfault #8

Closed GoogleCodeExporter closed 8 years ago

GoogleCodeExporter commented 8 years ago
class FileWrapper(object):
                 ^^^^^^^^ remove this to get a segfault
    def __init__(self, fname, mode):
        self.f = open(fname, mode)

    def seek(self, seekto=None):
        if seekto is None:
            return self.f.seek()
        return self.f.seek(seekto)

    def close(self):
        return self.f.close()

    def write(self, bytes):
        return self.f.write(bytes)

    def read(self, bytes=None):
        if bytes is None:
            return self.f.read()
        return self.f.read(bytes)

# Create a python class to be used in the context
class Global(PyV8.JSClass):
    def pyv8_open(self, fname, mode):
        return FileWrapper(fname, mode)

Original issue reported on code.google.com by luke.lei...@gmail.com on 18 Sep 2009 at 5:00

GoogleCodeExporter commented 8 years ago
http://code.google.com/p/pyv8/source/detail?r=144

The root cause is pyv8 use PyNumber_Check to automatic convert python number, 
but the function will return true for any classic style object. So, I just use 
PyFloat_CheckExact instead of it.

Original comment by flier...@gmail.com on 19 Sep 2009 at 3:47

GoogleCodeExporter commented 8 years ago

Original comment by flier...@gmail.com on 19 Sep 2009 at 3:48