Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
N
neoppod
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Levin Zimmermann
neoppod
Commits
4e115473
Commit
4e115473
authored
Aug 08, 2018
by
Kirill Smelkov
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
.
parent
85a829ac
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
19 additions
and
21 deletions
+19
-21
go/zodb/persistent.go
go/zodb/persistent.go
+19
-21
No files found.
go/zodb/persistent.go
View file @
4e115473
...
...
@@ -58,15 +58,15 @@ import (
type
Persistent
struct
{
// ZODB class of this object.
// XXX it could be deduced via typeTab[reflect.TypeOf(.instance)]
zclass
*
zclass
zclass
*
zclass
jar
*
Connection
oid
Oid
serial
Tid
// also protected by mu
jar
*
Connection
oid
Oid
serial
Tid
// also protected by mu
mu
sync
.
Mutex
state
ObjectState
refcnt
int32
mu
sync
.
Mutex
state
ObjectState
refcnt
int32
// Persistent is the base for the instance.
// instance, via its state type, is additionally Ghostable and (Stateful | PyStateful).
...
...
@@ -74,8 +74,8 @@ type Persistent struct {
loading
*
loadState
}
func
(
obj
*
Persistent
)
PJar
()
*
Connection
{
return
obj
.
jar
}
func
(
obj
*
Persistent
)
POid
()
Oid
{
return
obj
.
oid
}
func
(
obj
*
Persistent
)
PJar
()
*
Connection
{
return
obj
.
jar
}
func
(
obj
*
Persistent
)
POid
()
Oid
{
return
obj
.
oid
}
func
(
obj
*
Persistent
)
PSerial
()
Tid
{
obj
.
mu
.
Lock
()
...
...
@@ -92,7 +92,7 @@ type loadState struct {
// error from the load.
// if there was no error, loaded data goes to object state.
err
error
err
error
}
// Ghostable is the interface describing in-RAM object who can release its in-RAM state.
...
...
@@ -165,11 +165,11 @@ func (obj *Persistent) PActivate(ctx context.Context) (err error) {
if
l
,
s
:=
obj
.
loading
,
obj
.
state
;
!
(
l
==
loading
&&
s
==
GHOST
)
{
obj
.
mu
.
Unlock
()
panic
(
obj
.
badf
(
"activate: after load: object state unexpected: "
+
panic
(
obj
.
badf
(
"activate: after load: object state unexpected: "
+
"%v (want %v); .loading = %p (want %p)"
,
s
,
GHOST
,
l
,
loading
))
}
obj
.
serial
=
serial
obj
.
serial
=
serial
// try to pass loaded state to object
if
err
==
nil
{
...
...
@@ -251,7 +251,6 @@ func (obj *Persistent) PInvalidate() {
obj
.
loading
=
nil
}
// istate returns .instance casted to corresponding stateType.
//
// returns: Ghostable + (Stateful | PyStateful).
...
...
@@ -262,7 +261,7 @@ func (obj *Persistent) istate() Ghostable {
// badf returns formatted error prefixed with obj's class and oid.
func
(
obj
*
Persistent
)
badf
(
format
string
,
argv
...
interface
{})
error
{
return
fmt
.
Errorf
(
"%s(%s): "
+
format
,
return
fmt
.
Errorf
(
"%s(%s): "
+
format
,
append
([]
interface
{}{
obj
.
zclass
.
class
,
obj
.
oid
},
argv
...
))
}
...
...
@@ -296,7 +295,6 @@ var rGhostable = reflect.TypeOf((*Ghostable)(nil)).Elem() // typeof(Ghostabl
var
rStateful
=
reflect
.
TypeOf
((
*
Stateful
)(
nil
))
.
Elem
()
// typeof(Stateful)
var
rPyStateful
=
reflect
.
TypeOf
((
*
PyStateful
)(
nil
))
.
Elem
()
// typeof(PyStateful)
// RegisterClass registers ZODB class to correspond to Go type.
//
// Only registered classes can be saved to database, and are converted to
...
...
@@ -370,7 +368,7 @@ func NewPersistent(typ reflect.Type, jar *Connection) IPersistent {
}
xpobj
:=
reflect
.
New
(
zc
.
typ
)
return
persistentInit
(
xpobj
,
zc
,
jar
,
InvalidOid
,
InvalidTid
,
UPTODATE
/*XXX ok?*/
)
return
persistentInit
(
xpobj
,
zc
,
jar
,
InvalidOid
,
InvalidTid
,
UPTODATE
/*XXX ok?*/
)
}
// newGhost creates new ghost object corresponding to class, oid and jar.
...
...
@@ -396,7 +394,7 @@ func newGhost(class string, oid Oid, jar *Connection) IPersistent {
// persistentInit inits Persistent embedded into an object and returns .instance .
func
persistentInit
(
xpobj
reflect
.
Value
,
zc
*
zclass
,
jar
*
Connection
,
oid
Oid
,
serial
Tid
,
state
ObjectState
)
IPersistent
{
xobj
:=
xpobj
.
Elem
()
// typ
xobj
:=
xpobj
.
Elem
()
// typ
pbase
:=
xobj
.
FieldByName
(
"Persistent"
)
.
Addr
()
.
Interface
()
.
(
*
Persistent
)
pbase
.
zclass
=
zc
pbase
.
jar
=
jar
...
...
@@ -434,7 +432,7 @@ func (b *brokenState) DropState() {
b
.
state
=
nil
}
func
(
b
*
brokenState
)
SetState
(
state
*
mem
.
Buf
)
error
{
func
(
b
*
brokenState
)
SetState
(
state
*
mem
.
Buf
)
error
{
b
.
state
.
XRelease
()
state
.
Incref
()
b
.
state
=
state
...
...
@@ -443,7 +441,7 @@ func (b *brokenState) SetState(state *mem.Buf) error {
// brokenZClass is used for Persistent.zclass for Broken objects.
var
brokenZClass
=
&
zclass
{
class
:
""
,
typ
:
reflect
.
TypeOf
(
Broken
{}),
stateType
:
reflect
.
TypeOf
(
brokenState
{}),
class
:
""
,
typ
:
reflect
.
TypeOf
(
Broken
{}),
stateType
:
reflect
.
TypeOf
(
brokenState
{}),
}
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