Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Z
ZODB
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
Kirill Smelkov
ZODB
Commits
adf4a294
Commit
adf4a294
authored
Feb 20, 2004
by
Jeremy Hylton
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Reformat recent code for consistency with rest of file.
parent
ac99a73f
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
181 additions
and
230 deletions
+181
-230
trunk/src/persistent/cPersistence.c
trunk/src/persistent/cPersistence.c
+181
-230
No files found.
trunk/src/persistent/cPersistence.c
View file @
adf4a294
...
...
@@ -14,7 +14,7 @@
static
char
cPersistence_doc_string
[]
=
"Defines Persistent mixin class for persistent objects.
\n
"
"
\n
"
"$Id: cPersistence.c,v 1.7
7 2004/02/19 18:13:35
jeremy Exp $
\n
"
;
"$Id: cPersistence.c,v 1.7
8 2004/02/20 17:20:16
jeremy Exp $
\n
"
;
#include "cPersistence.h"
#include "structmember.h"
...
...
@@ -31,6 +31,9 @@ static PyObject *py_keys, *py_setstate, *py___dict__, *py_timeTime;
static
PyObject
*
py__p_changed
,
*
py__p_deactivate
;
static
PyObject
*
py___getattr__
,
*
py___setattr__
,
*
py___delattr__
;
static
PyObject
*
py___getstate__
;
static
PyObject
*
py___slotnames__
,
*
copy_reg_slotnames
,
*
__newobj__
;
static
PyObject
*
py___getnewargs__
,
*
py___getstate__
;
static
int
init_strings
(
void
)
...
...
@@ -48,6 +51,9 @@ init_strings(void)
INIT_STRING
(
__setattr__
);
INIT_STRING
(
__delattr__
);
INIT_STRING
(
__getstate__
);
INIT_STRING
(
__slotnames__
);
INIT_STRING
(
__getnewargs__
);
INIT_STRING
(
__getstate__
);
#undef INIT_STRING
return
0
;
}
...
...
@@ -232,104 +238,61 @@ Per__p_invalidate(cPersistentObject *self)
}
/* It's a dang shame we can't inherit __get/setstate__ from object :( */
static
PyObject
*
str__slotnames__
,
*
copy_reg_slotnames
,
*
__newobj__
;
static
PyObject
*
str__getnewargs__
,
*
str__getstate__
;
static
int
pickle_setup
(
void
)
{
PyObject
*
copy_reg
;
int
r
=
-
1
;
#define DEFINE_STRING(S) \
if(! (str ## S = PyString_FromString(# S))) return -1
DEFINE_STRING
(
__slotnames__
);
DEFINE_STRING
(
__getnewargs__
);
DEFINE_STRING
(
__getstate__
);
#undef DEFINE_STRING
copy_reg
=
PyImport_ImportModule
(
"copy_reg"
);
if
(
copy_reg
==
NULL
)
return
-
1
;
copy_reg_slotnames
=
PyObject_GetAttrString
(
copy_reg
,
"_slotnames"
);
if
(
copy_reg_slotnames
==
NULL
)
goto
end
;
__newobj__
=
PyObject_GetAttrString
(
copy_reg
,
"__newobj__"
);
if
(
__newobj__
==
NULL
)
goto
end
;
r
=
0
;
end:
Py_DECREF
(
copy_reg
);
return
r
;
}
static
PyObject
*
pickle_slotnames
(
PyTypeObject
*
cls
)
{
PyObject
*
slotnames
;
PyObject
*
slotnames
;
slotnames
=
PyDict_GetItem
(
cls
->
tp_dict
,
str__slotnames__
);
if
(
slotnames
!=
NULL
)
{
Py_INCREF
(
slotnames
);
return
slotnames
;
slotnames
=
PyDict_GetItem
(
cls
->
tp_dict
,
py___slotnames__
);
if
(
slotnames
)
{
Py_INCREF
(
slotnames
);
return
slotnames
;
}
slotnames
=
PyObject_CallFunctionObjArgs
(
copy_reg_slotnames
,
(
PyObject
*
)
cls
,
NULL
);
if
(
slotnames
!=
NULL
&&
slotnames
!=
Py_None
&&
!
PyList_Check
(
slotnames
))
{
PyErr_SetString
(
PyExc_TypeError
,
"copy_reg._slotnames didn't return a list or None"
);
Py_DECREF
(
slotnames
);
slotnames
=
NULL
;
slotnames
=
PyObject_CallFunctionObjArgs
(
copy_reg_slotnames
,
(
PyObject
*
)
cls
,
NULL
);
if
(
slotnames
&&
!
(
slotnames
==
Py_None
||
PyList_Check
(
slotnames
)))
{
PyErr_SetString
(
PyExc_TypeError
,
"copy_reg._slotnames didn't return a list or None"
);
Py_DECREF
(
slotnames
);
return
NULL
;
}
return
slotnames
;
return
slotnames
;
}
static
PyObject
*
pickle_copy_dict
(
PyObject
*
state
)
{
PyObject
*
copy
,
*
key
,
*
value
;
char
*
ckey
;
int
pos
=
0
;
PyObject
*
copy
,
*
key
,
*
value
;
char
*
ckey
;
int
pos
=
0
;
copy
=
PyDict_New
();
if
(
copy
==
NULL
)
return
NULL
;
if
(
state
==
NULL
)
return
copy
;
copy
=
PyDict_New
();
if
(
!
copy
)
return
NULL
;
while
(
PyDict_Next
(
state
,
&
pos
,
&
key
,
&
value
))
{
if
(
key
&&
PyString_Check
(
key
))
{
ckey
=
PyString_AS_STRING
(
key
);
if
(
*
ckey
==
'_'
&&
(
ckey
[
1
]
==
'v'
||
ckey
[
1
]
==
'p'
)
&&
ckey
[
2
]
==
'_'
)
/* skip volatile and persistent */
continue
;
if
(
!
state
)
return
copy
;
while
(
PyDict_Next
(
state
,
&
pos
,
&
key
,
&
value
))
{
if
(
key
&&
PyString_Check
(
key
))
{
ckey
=
PyString_AS_STRING
(
key
);
if
(
*
ckey
==
'_'
&&
(
ckey
[
1
]
==
'v'
||
ckey
[
1
]
==
'p'
)
&&
ckey
[
2
]
==
'_'
)
/* skip volatile and persistent */
continue
;
}
if
(
PyObject_SetItem
(
copy
,
key
,
value
)
<
0
)
goto
err
;
if
(
PyObject_SetItem
(
copy
,
key
,
value
)
<
0
)
goto
err
;
}
return
copy
;
return
copy
;
err:
Py_DECREF
(
copy
);
return
NULL
;
Py_DECREF
(
copy
);
return
NULL
;
}
...
...
@@ -352,163 +315,140 @@ static char pickle___getstate__doc[] =
static
PyObject
*
pickle___getstate__
(
PyObject
*
self
)
{
PyObject
*
slotnames
=
NULL
,
*
slots
=
NULL
,
*
state
=
NULL
;
PyObject
**
dictp
;
int
n
=
0
;
PyObject
*
slotnames
=
NULL
,
*
slots
=
NULL
,
*
state
=
NULL
;
PyObject
**
dictp
;
int
n
=
0
;
slotnames
=
pickle_slotnames
(
self
->
ob_type
);
if
(
slotnames
==
NULL
)
return
NULL
;
slotnames
=
pickle_slotnames
(
self
->
ob_type
);
if
(
!
slotnames
)
return
NULL
;
dictp
=
_PyObject_GetDictPtr
(
self
);
if
(
dictp
)
state
=
pickle_copy_dict
(
*
dictp
);
else
{
state
=
Py_None
;
Py_INCREF
(
state
);
dictp
=
_PyObject_GetDictPtr
(
self
);
if
(
dictp
)
state
=
pickle_copy_dict
(
*
dictp
);
else
{
state
=
Py_None
;
Py_INCREF
(
state
);
}
if
(
slotnames
!=
Py_None
)
{
int
i
;
slots
=
PyDict_New
();
if
(
slots
==
NULL
)
goto
end
;
for
(
i
=
0
;
i
<
PyList_GET_SIZE
(
slotnames
);
i
++
)
{
PyObject
*
name
,
*
value
;
char
*
cname
;
name
=
PyList_GET_ITEM
(
slotnames
,
i
);
if
(
PyString_Check
(
name
))
{
cname
=
PyString_AS_STRING
(
name
);
if
(
*
cname
==
'_'
&&
(
cname
[
1
]
==
'v'
||
cname
[
1
]
==
'p'
)
&&
cname
[
2
]
==
'_'
)
/* skip volatile and persistent */
continue
;
if
(
slotnames
!=
Py_None
)
{
int
i
;
slots
=
PyDict_New
();
if
(
!
slots
)
goto
end
;
for
(
i
=
0
;
i
<
PyList_GET_SIZE
(
slotnames
);
i
++
)
{
PyObject
*
name
,
*
value
;
char
*
cname
;
name
=
PyList_GET_ITEM
(
slotnames
,
i
);
if
(
PyString_Check
(
name
))
{
cname
=
PyString_AS_STRING
(
name
);
if
(
*
cname
==
'_'
&&
(
cname
[
1
]
==
'v'
||
cname
[
1
]
==
'p'
)
&&
cname
[
2
]
==
'_'
)
/* skip volatile and persistent */
continue
;
}
/* XXX will this go through our getattr hook? */
value
=
PyObject_GetAttr
(
self
,
name
);
if
(
value
==
NULL
)
PyErr_Clear
();
else
{
int
err
=
PyDict_SetItem
(
slots
,
name
,
value
);
Py_DECREF
(
value
);
if
(
err
<
0
)
goto
end
;
n
++
;
/* XXX will this go through our getattr hook? */
value
=
PyObject_GetAttr
(
self
,
name
);
if
(
value
==
NULL
)
PyErr_Clear
();
else
{
int
err
=
PyDict_SetItem
(
slots
,
name
,
value
);
Py_DECREF
(
value
);
if
(
err
<
0
)
goto
end
;
n
++
;
}
}
}
if
(
n
)
state
=
Py_BuildValue
(
"(NO)"
,
state
,
slots
);
if
(
n
)
state
=
Py_BuildValue
(
"(NO)"
,
state
,
slots
);
end:
Py_XDECREF
(
slotnames
);
Py_XDECREF
(
slots
);
Py_XDECREF
(
slotnames
);
Py_XDECREF
(
slots
);
return
state
;
return
state
;
}
static
int
pickle_setattrs_from_dict
(
PyObject
*
self
,
PyObject
*
dict
)
{
PyObject
*
key
,
*
value
;
int
pos
=
0
;
PyObject
*
key
,
*
value
;
int
pos
=
0
;
if
(
!
PyDict_Check
(
dict
))
{
PyErr_SetString
(
PyExc_TypeError
,
"Expected dictionary"
);
return
-
1
;
if
(
!
PyDict_Check
(
dict
))
{
PyErr_SetString
(
PyExc_TypeError
,
"Expected dictionary"
);
return
-
1
;
}
while
(
PyDict_Next
(
dict
,
&
pos
,
&
key
,
&
value
))
{
if
(
PyObject_SetAttr
(
self
,
key
,
value
)
<
0
)
return
-
1
;
while
(
PyDict_Next
(
dict
,
&
pos
,
&
key
,
&
value
))
{
if
(
PyObject_SetAttr
(
self
,
key
,
value
)
<
0
)
return
-
1
;
}
return
0
;
return
0
;
}
static
char
pickle___setstate__doc
[]
=
"Set the object serialization state
\n
"
"
\n
"
"The state should be in one of 3 forms:
\n
"
"
\n
"
"- None
\n
"
"
\n
"
" Ignored
\n
"
"
\n
"
"- A dictionary
\n
"
"
\n
"
"Set the object serialization state
\n\n
"
"The state should be in one of 3 forms:
\n\n
"
"- None
\n\n
"
" Ignored
\n\n
"
"- A dictionary
\n\n
"
" In this case, the object's instance dictionary will be cleared and
\n
"
" updated with the new state.
\n
"
"
\n
"
"- A two-tuple with a string as the first element.
\n
"
"
\n
"
" updated with the new state.
\n\n
"
"- A two-tuple with a string as the first element.
\n\n
"
" In this case, the method named by the string in the first element will be
\n
"
" called with the second element.
\n
"
"
\n
"
" This form supports migration of data formats.
\n
"
"
\n
"
" called with the second element.
\n\n
"
" This form supports migration of data formats.
\n\n
"
"- A two-tuple with None or a Dictionary as the first element and
\n
"
" with a dictionary as the second element.
\n
"
"
\n
"
" with a dictionary as the second element.
\n\n
"
" If the first element is not None, then the object's instance dictionary
\n
"
" will be cleared and updated with the value.
\n
"
"
\n
"
" will be cleared and updated with the value.
\n\n
"
" The items in the second element will be assigned as attributes.
\n
"
;
static
PyObject
*
pickle___setstate__
(
PyObject
*
self
,
PyObject
*
state
)
{
PyObject
*
slots
=
NULL
;
PyObject
*
slots
=
NULL
;
if
(
PyTuple_Check
(
state
))
{
if
(
!
PyArg_ParseTuple
(
state
,
"OO"
,
&
state
,
&
slots
))
return
NULL
;
if
(
PyTuple_Check
(
state
))
{
if
(
!
PyArg_ParseTuple
(
state
,
"OO:__setstate__"
,
&
state
,
&
slots
))
return
NULL
;
}
if
(
state
!=
Py_None
)
{
PyObject
**
dict
;
dict
=
_PyObject_GetDictPtr
(
self
);
if
(
dict
)
{
if
(
*
dict
==
NULL
)
{
*
dict
=
PyDict_New
();
if
(
*
dict
==
NULL
)
return
NULL
;
if
(
state
!=
Py_None
)
{
PyObject
**
dict
;
dict
=
_PyObject_GetDictPtr
(
self
);
if
(
dict
)
{
if
(
!*
dict
)
{
*
dict
=
PyDict_New
();
if
(
!*
dict
)
return
NULL
;
}
}
if
(
*
dict
!=
NULL
)
{
PyDict_Clear
(
*
dict
);
if
(
PyDict_Update
(
*
dict
,
state
)
<
0
)
return
NULL
;
if
(
*
dict
)
{
PyDict_Clear
(
*
dict
);
if
(
PyDict_Update
(
*
dict
,
state
)
<
0
)
return
NULL
;
}
else
if
(
pickle_setattrs_from_dict
(
self
,
state
)
<
0
)
return
NULL
;
else
if
(
pickle_setattrs_from_dict
(
self
,
state
)
<
0
)
return
NULL
;
}
if
(
slots
!=
NULL
&&
pickle_setattrs_from_dict
(
self
,
slots
)
<
0
)
return
NULL
;
if
(
slots
&&
pickle_setattrs_from_dict
(
self
,
slots
)
<
0
)
return
NULL
;
Py_INCREF
(
Py_None
);
return
Py_None
;
Py_INCREF
(
Py_None
);
return
Py_None
;
}
static
char
pickle___reduce__doc
[]
=
...
...
@@ -518,52 +458,49 @@ static char pickle___reduce__doc[] =
static
PyObject
*
pickle___reduce__
(
PyObject
*
self
)
{
PyObject
*
args
=
NULL
,
*
bargs
=
NULL
,
*
state
=
NULL
,
*
getnewargs
=
NULL
;
int
l
,
i
;
getnewargs
=
PyObject_GetAttr
(
self
,
str
__getnewargs__
);
if
(
getnewargs
!=
NULL
)
{
bargs
=
PyObject_CallFunctionObjArgs
(
getnewargs
,
NULL
);
Py_DECREF
(
getnewargs
);
if
(
bargs
==
NULL
)
return
NULL
;
l
=
PyTuple_Size
(
bargs
);
if
(
l
<
0
)
goto
end
;
}
else
{
PyErr_Clear
();
l
=
0
;
}
PyObject
*
args
=
NULL
,
*
bargs
=
NULL
,
*
state
=
NULL
,
*
getnewargs
=
NULL
;
int
l
,
i
;
getnewargs
=
PyObject_GetAttr
(
self
,
py_
__getnewargs__
);
if
(
getnewargs
)
{
bargs
=
PyObject_CallFunctionObjArgs
(
getnewargs
,
NULL
);
Py_DECREF
(
getnewargs
);
if
(
!
bargs
)
return
NULL
;
l
=
PyTuple_Size
(
bargs
);
if
(
l
<
0
)
goto
end
;
}
else
{
PyErr_Clear
();
l
=
0
;
}
args
=
PyTuple_New
(
l
+
1
);
if
(
args
==
NULL
)
goto
end
;
args
=
PyTuple_New
(
l
+
1
);
if
(
args
==
NULL
)
goto
end
;
Py_INCREF
(
self
->
ob_type
);
PyTuple_SET_ITEM
(
args
,
0
,
(
PyObject
*
)(
self
->
ob_type
));
for
(
i
=
0
;
i
<
l
;
i
++
)
{
Py_INCREF
(
PyTuple_GET_ITEM
(
bargs
,
i
));
PyTuple_SET_ITEM
(
args
,
i
+
1
,
PyTuple_GET_ITEM
(
bargs
,
i
));
Py_INCREF
(
self
->
ob_type
);
PyTuple_SET_ITEM
(
args
,
0
,
(
PyObject
*
)(
self
->
ob_type
));
for
(
i
=
0
;
i
<
l
;
i
++
)
{
Py_INCREF
(
PyTuple_GET_ITEM
(
bargs
,
i
));
PyTuple_SET_ITEM
(
args
,
i
+
1
,
PyTuple_GET_ITEM
(
bargs
,
i
));
}
state
=
PyObject_CallMethodObjArgs
(
self
,
str
__getstate__
,
NULL
);
if
(
state
==
NULL
)
goto
end
;
state
=
PyObject_CallMethodObjArgs
(
self
,
py_
__getstate__
,
NULL
);
if
(
!
state
)
goto
end
;
state
=
Py_BuildValue
(
"(OON)"
,
__newobj__
,
args
,
state
);
state
=
Py_BuildValue
(
"(OON)"
,
__newobj__
,
args
,
state
);
end:
Py_XDECREF
(
bargs
);
Py_XDECREF
(
args
);
Py_XDECREF
(
bargs
);
Py_XDECREF
(
args
);
return
state
;
return
state
;
}
/* Return the object's state, a dict or None.
If the object has no dict, it's state is None.
...
...
@@ -1176,9 +1113,7 @@ void
initcPersistence
(
void
)
{
PyObject
*
m
,
*
s
;
if
(
pickle_setup
()
<
0
)
return
;
PyObject
*
copy_reg
;
if
(
init_strings
()
<
0
)
return
;
...
...
@@ -1216,7 +1151,23 @@ initcPersistence(void)
if
(
!
py_simple_new
)
return
;
if
(
TimeStamp
==
NULL
)
{
copy_reg
=
PyImport_ImportModule
(
"copy_reg"
);
if
(
!
copy_reg
)
return
;
copy_reg_slotnames
=
PyObject_GetAttrString
(
copy_reg
,
"_slotnames"
);
if
(
!
copy_reg_slotnames
)
{
Py_DECREF
(
copy_reg
);
return
;
}
__newobj__
=
PyObject_GetAttrString
(
copy_reg
,
"__newobj__"
);
if
(
!
__newobj__
)
{
Py_DECREF
(
copy_reg
);
return
;
}
if
(
!
TimeStamp
)
{
m
=
PyImport_ImportModule
(
"persistent.TimeStamp"
);
if
(
!
m
)
return
;
...
...
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