Commit 873b5e4b authored by Kirill Smelkov's avatar Kirill Smelkov

.

parent 22ac840f
......@@ -79,6 +79,11 @@ type Object interface {
// application must care to make sure it does not access the
// object data simultaneously.
PInvalidate()
// Object must be stateful for persistency to work
// XXX try to move out of Object?
Stateful
}
// ObjectState describes state of in-RAM object.
......@@ -100,7 +105,7 @@ type object struct {
mu sync.Mutex
state ObjectState
refcnt int32
instance Stateful
instance Object
loading *loadState
}
......
......@@ -31,10 +31,11 @@ type PyObject interface {
PyClass() pickle.Class // python class of this object
// PyState() interface{} // object state. python passes this to pyclass.__new__().__setstate__()
// XXX want to hide from PyObject. Rationale: we do not want e.g. PySetState to
// PyObject must be statefule for persistency to work
// XXX try to move out of PyObject? Rationale: we do not want e.g. PySetState to
// be available to user who holds PyObject interface: it is confusing to have
// both PActivate and PySetState at the same time.
// PyStateful
PyStateful
}
// pyObject is common base implementation for in-RAM representation of ZODB Python objects.
......@@ -62,6 +63,14 @@ type PyStateful interface {
// ---- pyObject <-> object state exchange ----
// pyinstance returns .instance upcasted to PyObject.
//
// this should be always safe because we always create pyObjects via
// newGhost which passes PyObject as instance to Object.
func (pyobj *pyObject) pyinstance() PyObject {
return pyobj.instance.(PyObject)
}
func (pyobj *pyObject) SetState(state *mem.Buf) error {
pyclass, pystate, err := zodb.PyData(state.Data).Decode()
if err != nil {
......@@ -74,22 +83,24 @@ func (pyobj *pyObject) SetState(state *mem.Buf) error {
return &wrongClassError{want: pyobj.pyclass, have: pyclass} // XXX + err ctx
}
return pyobj.instance.PySetState(pystate) // XXX err ctx = ok?
return pyobj.pyinstance().PySetState(pystate) // XXX err ctx = ok?
}
// TODO pyObject.GetState
// ---- pyclass -> new ghost ----
type pyClassNewFunc func(base *pyObject) PyObject
// path(pyclass) -> new(pyobj)
var classTab = make(map[string]func(base *pyObject)PyObject)
var pyClassTab = make(map[string]pyClassNewFunc)
// registerPyClass registers python class to be transformed to Go instance
// created via classNew.
//
// must be called from global init().
func registerPyClass(pyClassPath string, classNew func(base *pyObject)PyObject) {
classTab[pyClassPath] = classNew
func registerPyClass(pyClassPath string, classNew pyClassNewFunc) {
pyClassTab[pyClassPath] = classNew
}
// newGhost creates new ghost object corresponding to pyclass and oid.
......@@ -100,7 +111,7 @@ func (conn *Connection) newGhost(pyclass pickle.Class, oid zodb.Oid) PyObject {
}
// switch on pyclass and transform e.g. "zodb.BTree.Bucket" -> *ZBucket
classNew := classTab[pyclass.Module + "." + pyclass.Name]
classNew := pyClassTab[pyclass.Module + "." + pyclass.Name]
var instance PyObject
if classNew != nil {
instance = classNew(pyobj)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment