Commit 41db5fd6 authored by Kirill Smelkov's avatar Kirill Smelkov

.

parent 7a8cebf5
......@@ -249,8 +249,8 @@ func (b *ZBucket) PySetState(pystate interface{}) error {
// ---- register classes to ZODB ----
func bucketNew(pyobj *pyObject) PyObject { return &ZBucket{pyObject: pyobj} }
func btreeNew(pyobj *pyObject) PyObject { return &ZBTree{pyObject: pyobj} }
func bucketNew(pyobj *pyObject) IPyPersistent { return &ZBucket{pyObject: pyobj} }
func btreeNew(pyobj *pyObject) IPyPersistent { return &ZBTree{pyObject: pyobj} }
func init() {
registerPyClass("zodb.BTree.LOBucket", bucketNew)
......
......@@ -147,10 +147,10 @@ func (bf *ZBigFile) PySetState(pystate interface{}) (err error) {
// ----------------------------------------
func zblk0New(base *pyObject) PyObject { return &ZBlk0{pyObject: base} }
func zblk1New(base *pyObject) PyObject { return &ZBlk1{pyObject: base} }
func zdataNew(base *pyObject) PyObject { return &ZData{pyObject: base} }
func zbigfileNew(pyobj *pyObject) PyObject { return &ZBigFile{pyObject: pyobj} }
func zblk0New(base *pyObject) IPyPersistent { return &ZBlk0{pyObject: base} }
func zblk1New(base *pyObject) IPyPersistent { return &ZBlk1{pyObject: base} }
func zdataNew(base *pyObject) IPyPersistent { return &ZData{pyObject: base} }
func zbigfileNew(pyobj *pyObject) IPyPersistent { return &ZBigFile{pyObject: pyobj} }
func init() {
registerPyClass(zwendelin + ".ZBlk", zblk0New)
......
......@@ -24,18 +24,16 @@ import (
pickle "github.com/kisielk/og-rek"
)
// PyObject is the interface that every in-RAM object representing Python ZODB object implements.
//
// XXX rename -> PyPersistent?
type PyObject interface {
// IPyPersistent is the interface that every in-RAM object representing Python ZODB object implements.
type IPyPersistent interface {
IPersistent
PyClass() pickle.Class // python class of this object
// PyState() interface{} // object state. python passes this to pyclass.__new__().__setstate__()
// PyObject must be stateful 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
// IPyPersistent must be stateful for persistency to work
// XXX try to move out of IPyPersistent? Rationale: we do not want e.g. PySetState to
// be available to user who holds IPyPersistent interface: it is confusing to have
// both PActivate and PySetState at the same time.
PyStateful
}
......@@ -63,12 +61,12 @@ type PyStateful interface {
// ---- pyObject <-> object state exchange ----
// pyinstance returns .instance upcasted to PyObject.
// pyinstance returns .instance upcasted to IPyPersistent.
//
// this should be always safe because we always create pyObjects via
// newGhost which passes PyObject as instance to IPersistent.
func (pyobj *pyObject) pyinstance() PyObject {
return pyobj.instance.(PyObject)
// newGhost which passes IPyPersistent as instance to IPersistent.
func (pyobj *pyObject) pyinstance() IPyPersistent {
return pyobj.instance.(IPyPersistent)
}
func (pyobj *pyObject) SetState(state *mem.Buf) error {
......@@ -91,7 +89,7 @@ func (pyobj *pyObject) SetState(state *mem.Buf) error {
// ---- pyclass -> new ghost ----
// function representing new of a class.
type pyClassNewFunc func(base *pyObject) PyObject
type pyClassNewFunc func(base *pyObject) IPyPersistent
// path(pyclass) -> new(pyobj)
var pyClassTab = make(map[string]pyClassNewFunc)
......@@ -106,7 +104,7 @@ func registerPyClass(pyClassPath string, classNew pyClassNewFunc) {
}
// newGhost creates new ghost object corresponding to pyclass and oid.
func (conn *Connection) newGhost(pyclass pickle.Class, oid zodb.Oid) PyObject {
func (conn *Connection) newGhost(pyclass pickle.Class, oid zodb.Oid) IPyPersistent {
pyobj := &pyObject{
object: object{jar: conn, oid: oid, serial: 0, state: GHOST},
pyclass: pyclass,
......@@ -114,7 +112,7 @@ func (conn *Connection) newGhost(pyclass pickle.Class, oid zodb.Oid) PyObject {
// switch on pyclass and transform e.g. "zodb.BTree.Bucket" -> *ZBucket
classNew := pyClassTab[pyclass.Module + "." + pyclass.Name]
var instance PyObject
var instance IPyPersistent
if classNew != nil {
instance = classNew(pyobj)
} else {
......@@ -153,7 +151,7 @@ func (d *dummyPyInstance) PySetState(pystate interface{}) error {
//
// The object's data is not neccessarily loaded after Get returns. Use
// PActivate to make sure the object ifs fully loaded.
func (conn *Connection) Get(ctx context.Context, oid zodb.Oid) (PyObject, error) {
func (conn *Connection) Get(ctx context.Context, oid zodb.Oid) (IPyPersistent, error) {
conn.objmu.Lock() // XXX -> rlock
wobj := conn.objtab[oid]
var xobj interface{}
......@@ -164,7 +162,7 @@ func (conn *Connection) Get(ctx context.Context, oid zodb.Oid) (PyObject, error)
// object was already there in objtab.
if xobj != nil {
return xobj.(PyObject), nil
return xobj.(IPyPersistent), nil
}
// object is not there in objtab - raw load it, get its class -> get(pyclass, oid)
......@@ -207,14 +205,14 @@ func (e *wrongClassError) Error() string {
//
// Use-case: in ZODB references are (pyclass, oid), so new ghost is created
// without further loading anything.
func (conn *Connection) get(pyclass pickle.Class, oid zodb.Oid) (PyObject, error) {
func (conn *Connection) get(pyclass pickle.Class, oid zodb.Oid) (IPyPersistent, error) {
conn.objmu.Lock() // XXX -> rlock
wobj := conn.objtab[oid]
var pyobj PyObject
var pyobj IPyPersistent
checkClass := false
if wobj != nil {
if xobj := wobj.Get(); xobj != nil {
pyobj = xobj.(PyObject)
pyobj = xobj.(IPyPersistent)
}
}
if pyobj == nil {
......
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