Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
cpython
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
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
cpython
Commits
36dd4d3e
Commit
36dd4d3e
authored
Aug 19, 2006
by
Guido van Rossum
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
And the gdbm module's test now passes again.
parent
d308c02f
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
33 additions
and
13 deletions
+33
-13
Modules/gdbmmodule.c
Modules/gdbmmodule.c
+33
-13
No files found.
Modules/gdbmmodule.c
View file @
36dd4d3e
...
...
@@ -241,21 +241,41 @@ dbm_keys(register dbmobject *dp, PyObject *unused)
return
v
;
}
PyDoc_STRVAR
(
dbm_contains__doc__
,
"__contains__(key) -> bool
\n
\
Find out whether or not the database contains a given key."
);
static
PyObject
*
dbm_contains
(
register
dbmobject
*
dp
,
PyObject
*
args
)
static
int
dbm_contains
(
PyObject
*
self
,
PyObject
*
arg
)
{
dbmobject
*
dp
=
(
dbmobject
*
)
self
;
datum
key
;
if
(
!
PyArg_ParseTuple
(
args
,
"s#:contains"
,
&
key
.
dptr
,
&
key
.
dsize
))
return
NULL
;
check_dbmobject_open
(
dp
);
return
PyInt_FromLong
((
long
)
gdbm_exists
(
dp
->
di_dbm
,
key
));
if
((
dp
)
->
di_dbm
==
NULL
)
{
PyErr_SetString
(
DbmError
,
"GDBM object has already been closed"
);
return
-
1
;
}
if
(
!
PyString_Check
(
arg
))
{
PyErr_Format
(
PyExc_TypeError
,
"gdbm key must be string, not %.100s"
,
arg
->
ob_type
->
tp_name
);
return
-
1
;
}
key
.
dptr
=
PyString_AS_STRING
(
arg
);
key
.
dsize
=
PyString_GET_SIZE
(
arg
);
return
gdbm_exists
(
dp
->
di_dbm
,
key
);
}
static
PySequenceMethods
dbm_as_sequence
=
{
0
,
/* sq_length */
0
,
/* sq_concat */
0
,
/* sq_repeat */
0
,
/* sq_item */
0
,
/* sq_slice */
0
,
/* sq_ass_item */
0
,
/* sq_ass_slice */
dbm_contains
,
/* sq_contains */
0
,
/* sq_inplace_concat */
0
,
/* sq_inplace_repeat */
};
PyDoc_STRVAR
(
dbm_firstkey__doc__
,
"firstkey() -> key
\n
\
It's possible to loop over every key in the database using this method
\n
\
...
...
@@ -355,7 +375,6 @@ dbm_sync(register dbmobject *dp, PyObject *unused)
static
PyMethodDef
dbm_methods
[]
=
{
{
"close"
,
(
PyCFunction
)
dbm_close
,
METH_NOARGS
,
dbm_close__doc__
},
{
"keys"
,
(
PyCFunction
)
dbm_keys
,
METH_NOARGS
,
dbm_keys__doc__
},
{
"__contains__"
,(
PyCFunction
)
dbm_contains
,
METH_VARARGS
,
dbm_contains__doc__
},
{
"firstkey"
,
(
PyCFunction
)
dbm_firstkey
,
METH_NOARGS
,
dbm_firstkey__doc__
},
{
"nextkey"
,
(
PyCFunction
)
dbm_nextkey
,
METH_VARARGS
,
dbm_nextkey__doc__
},
{
"reorganize"
,(
PyCFunction
)
dbm_reorganize
,
METH_NOARGS
,
dbm_reorganize__doc__
},
...
...
@@ -382,7 +401,7 @@ static PyTypeObject Dbmtype = {
0
,
/*tp_compare*/
0
,
/*tp_repr*/
0
,
/*tp_as_number*/
0
,
/*tp_as_sequence*/
&
dbm_as_sequence
,
/*tp_as_sequence*/
&
dbm_as_mapping
,
/*tp_as_mapping*/
0
,
/*tp_hash*/
0
,
/*tp_call*/
...
...
@@ -498,7 +517,8 @@ PyMODINIT_FUNC
initgdbm
(
void
)
{
PyObject
*
m
,
*
d
,
*
s
;
Dbmtype
.
ob_type
=
&
PyType_Type
;
if
(
PyType_Ready
(
&
Dbmtype
)
<
0
)
return
;
m
=
Py_InitModule4
(
"gdbm"
,
dbmmodule_methods
,
gdbmmodule__doc__
,
(
PyObject
*
)
NULL
,
PYTHON_API_VERSION
);
...
...
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