Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
N
neo
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Labels
Merge Requests
2
Merge Requests
2
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Jobs
Commits
Open sidebar
Kirill Smelkov
neo
Commits
f5b30c35
Commit
f5b30c35
authored
Jul 27, 2018
by
Kirill Smelkov
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
.
parent
c047fa1f
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
21 additions
and
12 deletions
+21
-12
go/zodb/connection.go
go/zodb/connection.go
+12
-4
go/zodb/persistent.go
go/zodb/persistent.go
+4
-5
go/zodb/zodbpy.go
go/zodb/zodbpy.go
+5
-3
No files found.
go/zodb/connection.go
View file @
f5b30c35
...
...
@@ -149,6 +149,13 @@ func (conn *Connection) newGhost(class string, oid Oid) IPersistent {
var
class2Type
=
make
(
map
[
string
]
reflect
.
Type
)
// {} class -> type
var
type2Class
=
make
(
map
[
reflect
.
Type
]
string
)
// {} type -> class
// zclassOf returns ZODB class of a Go object.
//
// If ZODB class was not registered for obj's type, "" is returned.
func
zclassOf
(
obj
IPersistent
)
string
{
return
type2Class
[
reflect
.
TypeOf
(
obj
)]
}
// RegisterClass registers ZODB class to correspond to Go type.
//
// *type must implement IPersistent. XXX and either Stateful or PyStateful
...
...
@@ -169,6 +176,8 @@ func RegisterClass(class string, typ reflect.Type) {
// XXX check typ has IPersistent embedded
// XXX check *typ implements Stateful
// XXX check if class was already registered
// XXX check class != ""
class2Type
[
class
]
=
typ
type2Class
[
typ
]
=
class
...
...
@@ -186,14 +195,14 @@ func (conn *Connection) newGhost(class string, oid Oid) IPersistent {
xpobj
=
reflect
.
New
(
typ
)
}
base
:=
&
Persistent
{
class
:
class
,
jar
:
conn
,
oid
:
oid
,
serial
:
0
,
state
:
GHOST
}
base
:=
&
Persistent
{
jar
:
conn
,
oid
:
oid
,
serial
:
0
,
state
:
GHOST
}
xobj
:=
xpobj
.
Elem
()
// typ
xobjBase
:=
xobj
.
FieldByName
(
"IPersistent"
)
xobjBase
.
Set
(
reflect
.
ValueOf
(
base
))
obj
:=
xpobj
.
Interface
()
base
.
instance
=
obj
.
(
interface
{
IPersistent
;
Stateful
})
return
obj
.
(
IPersistent
)
return
base
.
instance
}
// Broken is used for classes that were not registered.
...
...
@@ -258,8 +267,7 @@ func (conn *Connection) get(class string, oid Oid) (IPersistent, error) {
conn
.
objmu
.
Unlock
()
if
checkClass
{
// XXX get obj class via reflection?
if
cls
:=
obj
.
zclass
();
class
!=
cls
{
if
cls
:=
zclassOf
(
obj
);
class
!=
cls
{
return
nil
,
&
OpError
{
URL
:
conn
.
stor
.
URL
(),
Op
:
fmt
.
Sprintf
(
"@%s: get"
,
conn
.
at
),
// XXX abuse
...
...
go/zodb/persistent.go
View file @
f5b30c35
...
...
@@ -31,7 +31,7 @@ import (
//
// XXX safe to access from multiple goroutines simultaneously.
type
IPersistent
interface
{
zclass
()
string
// ZODB class of this object. XXX remove from IPersistent?
//
zclass() string // ZODB class of this object. XXX remove from IPersistent?
PJar
()
*
Connection
// Connection this in-RAM object is part of.
POid
()
Oid
// object ID in the database.
...
...
@@ -119,8 +119,8 @@ const (
// Persistent is common base implementation for in-RAM representation of database objects.
type
Persistent
struct
{
// XXX kill here; move -> Broken
class
string
// zodb class of this object. XXX try not to store and retrieve via reflect?
//
// XXX kill here; move -> Broken
//
class string // zodb class of this object. XXX try not to store and retrieve via reflect?
jar
*
Connection
oid
Oid
...
...
@@ -129,12 +129,11 @@ type Persistent struct {
mu
sync
.
Mutex
state
ObjectState
refcnt
int32
// instance IPersistent // Persistent should be the base for the instance XXX -> Stateful
instance
interface
{
IPersistent
;
Stateful
}
// Persistent should be the base for the instance
loading
*
loadState
}
func
(
obj
*
Persistent
)
zclass
()
string
{
return
obj
.
class
}
//
func (obj *Persistent) zclass() string { return obj.class }
func
(
obj
*
Persistent
)
PJar
()
*
Connection
{
return
obj
.
jar
}
func
(
obj
*
Persistent
)
POid
()
Oid
{
return
obj
.
oid
}
func
(
obj
*
Persistent
)
PSerial
()
Tid
{
return
obj
.
serial
}
...
...
go/zodb/zodbpy.go
View file @
f5b30c35
...
...
@@ -77,13 +77,15 @@ func (pyobj *PyPersistent) SetState(state *mem.Buf) error {
}
class
:=
pyclassPath
(
pyclass
)
if
class
!=
pyobj
.
class
{
obj
:=
pyobj
.
pyinstance
()
if
objClass
:=
zclassOf
(
obj
);
class
!=
objClass
{
// complain that pyclass changed
// (both ref and object data use pyclass so it indeed can be different)
return
&
wrongClassError
{
want
:
pyobj
.
c
lass
,
have
:
class
}
// XXX + err ctx
return
&
wrongClassError
{
want
:
objC
lass
,
have
:
class
}
// XXX + err ctx
}
return
pyobj
.
pyinstance
()
.
PySetState
(
pystate
)
// XXX err ctx = ok?
return
obj
.
PySetState
(
pystate
)
// XXX err ctx = ok?
}
// TODO PyPersistent.GetState
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment