@@ -69,6 +69,7 @@ typedef struct {
69
69
#include "clinic/_dbmmodule.c.h"
70
70
71
71
#define check_dbmobject_open (v ,err ) \
72
+ _Py_CRITICAL_SECTION_ASSERT_OBJECT_LOCKED((v)) \
72
73
if ((v)->di_dbm == NULL) { \
73
74
PyErr_SetString(err, "DBM object has already been closed"); \
74
75
return NULL; \
@@ -116,7 +117,7 @@ dbm_dealloc(PyObject *self)
116
117
}
117
118
118
119
static Py_ssize_t
119
- dbm_length (PyObject * self )
120
+ dbm_length_lock_held (PyObject * self )
120
121
{
121
122
dbmobject * dp = dbmobject_CAST (self );
122
123
_dbm_state * state = PyType_GetModuleState (Py_TYPE (dp ));
@@ -138,8 +139,18 @@ dbm_length(PyObject *self)
138
139
return dp -> di_size ;
139
140
}
140
141
142
+ static Py_ssize_t
143
+ dbm_length (PyObject * self )
144
+ {
145
+ Py_ssize_t result ;
146
+ Py_BEGIN_CRITICAL_SECTION (self );
147
+ result = dbm_length_lock_held (self );
148
+ Py_END_CRITICAL_SECTION ();
149
+ return result ;
150
+ }
151
+
141
152
static int
142
- dbm_bool (PyObject * self )
153
+ dbm_bool_lock_held (PyObject * self )
143
154
{
144
155
dbmobject * dp = dbmobject_CAST (self );
145
156
_dbm_state * state = PyType_GetModuleState (Py_TYPE (dp ));
@@ -170,8 +181,18 @@ dbm_bool(PyObject *self)
170
181
return 1 ;
171
182
}
172
183
184
+ static int
185
+ dbm_bool (PyObject * self )
186
+ {
187
+ int result ;
188
+ Py_BEGIN_CRITICAL_SECTION (self );
189
+ result = dbm_bool_lock_held (self );
190
+ Py_END_CRITICAL_SECTION ();
191
+ return result ;
192
+ }
193
+
173
194
static PyObject *
174
- dbm_subscript (PyObject * self ,PyObject * key )
195
+ dbm_subscript_lock_held (PyObject * self ,PyObject * key )
175
196
{
176
197
datum drec ,krec ;
177
198
Py_ssize_t tmp_size ;
@@ -197,8 +218,18 @@ dbm_subscript(PyObject *self, PyObject *key)
197
218
return PyBytes_FromStringAndSize (drec .dptr ,drec .dsize );
198
219
}
199
220
221
+ static PyObject *
222
+ dbm_subscript (PyObject * self ,PyObject * key )
223
+ {
224
+ PyObject * result ;
225
+ Py_BEGIN_CRITICAL_SECTION (self );
226
+ result = dbm_subscript_lock_held (self ,key );
227
+ Py_END_CRITICAL_SECTION ();
228
+ return result ;
229
+ }
230
+
200
231
static int
201
- dbm_ass_sub (PyObject * self ,PyObject * v ,PyObject * w )
232
+ dbm_ass_sub_lock_held (PyObject * self ,PyObject * v ,PyObject * w )
202
233
{
203
234
datum krec ,drec ;
204
235
Py_ssize_t tmp_size ;
@@ -252,15 +283,26 @@ dbm_ass_sub(PyObject *self, PyObject *v, PyObject *w)
252
283
return 0 ;
253
284
}
254
285
286
+ static int
287
+ dbm_ass_sub (PyObject * self ,PyObject * v ,PyObject * w )
288
+ {
289
+ int result ;
290
+ Py_BEGIN_CRITICAL_SECTION (self );
291
+ result = dbm_ass_sub_lock_held (self ,v ,w );
292
+ Py_END_CRITICAL_SECTION ();
293
+ return result ;
294
+ }
295
+
255
296
/*[clinic input]
297
+ @critical_section
256
298
_dbm.dbm.close
257
299
258
300
Close the database.
259
301
[clinic start generated code]*/
260
302
261
303
static PyObject *
262
304
_dbm_dbm_close_impl (dbmobject * self )
263
- /*[clinic end generated code: output=c8dc5b6709600b86 input=046db72377d51be8 ]*/
305
+ /*[clinic end generated code: output=c8dc5b6709600b86 input=4a94f79facbc28ca ]*/
264
306
{
265
307
if (self -> di_dbm ) {
266
308
dbm_close (self -> di_dbm );
@@ -270,6 +312,7 @@ _dbm_dbm_close_impl(dbmobject *self)
270
312
}
271
313
272
314
/*[clinic input]
315
+ @critical_section
273
316
_dbm.dbm.keys
274
317
275
318
cls: defining_class
@@ -279,7 +322,7 @@ Return a list of all keys in the database.
279
322
280
323
static PyObject *
281
324
_dbm_dbm_keys_impl (dbmobject * self ,PyTypeObject * cls )
282
- /*[clinic end generated code: output=f2a593b3038e5996 input=d3706a28fc051097 ]*/
325
+ /*[clinic end generated code: output=f2a593b3038e5996 input=6ddefeadf2a80156 ]*/
283
326
{
284
327
PyObject * v ,* item ;
285
328
datum key ;
@@ -310,7 +353,7 @@ _dbm_dbm_keys_impl(dbmobject *self, PyTypeObject *cls)
310
353
}
311
354
312
355
static int
313
- dbm_contains (PyObject * self ,PyObject * arg )
356
+ dbm_contains_lock_held (PyObject * self ,PyObject * arg )
314
357
{
315
358
dbmobject * dp = dbmobject_CAST (self );
316
359
datum key ,val ;
@@ -343,7 +386,18 @@ dbm_contains(PyObject *self, PyObject *arg)
343
386
return val .dptr != NULL ;
344
387
}
345
388
389
+ static int
390
+ dbm_contains (PyObject * self ,PyObject * arg )
391
+ {
392
+ int result ;
393
+ Py_BEGIN_CRITICAL_SECTION (self );
394
+ result = dbm_contains_lock_held (self ,arg );
395
+ Py_END_CRITICAL_SECTION ();
396
+ return result ;
397
+ }
398
+
346
399
/*[clinic input]
400
+ @critical_section
347
401
_dbm.dbm.get
348
402
cls: defining_class
349
403
key: str(accept={str, robuffer}, zeroes=True)
@@ -356,7 +410,7 @@ Return the value for key if present, otherwise default.
356
410
static PyObject *
357
411
_dbm_dbm_get_impl (dbmobject * self ,PyTypeObject * cls ,const char * key ,
358
412
Py_ssize_t key_length ,PyObject * default_value )
359
- /*[clinic end generated code: output=b4e55f8b6d482bc4 input=66b993b8349fa8c1 ]*/
413
+ /*[clinic end generated code: output=b4e55f8b6d482bc4 input=1d88a22bb5e55202 ]*/
360
414
{
361
415
datum dbm_key ,val ;
362
416
_dbm_state * state = PyType_GetModuleState (cls );
@@ -373,6 +427,7 @@ _dbm_dbm_get_impl(dbmobject *self, PyTypeObject *cls, const char *key,
373
427
}
374
428
375
429
/*[clinic input]
430
+ @critical_section
376
431
_dbm.dbm.setdefault
377
432
cls: defining_class
378
433
key: str(accept={str, robuffer}, zeroes=True)
@@ -387,7 +442,7 @@ If key is not in the database, it is inserted with default as the value.
387
442
static PyObject *
388
443
_dbm_dbm_setdefault_impl (dbmobject * self ,PyTypeObject * cls ,const char * key ,
389
444
Py_ssize_t key_length ,PyObject * default_value )
390
- /*[clinic end generated code: output=9c2f6ea6d0fb576c input=126a3ff15c5f8232 ]*/
445
+ /*[clinic end generated code: output=9c2f6ea6d0fb576c input=c01510ef7571e13b ]*/
391
446
{
392
447
datum dbm_key ,val ;
393
448
Py_ssize_t tmp_size ;
@@ -427,6 +482,7 @@ _dbm_dbm_setdefault_impl(dbmobject *self, PyTypeObject *cls, const char *key,
427
482
}
428
483
429
484
/*[clinic input]
485
+ @critical_section
430
486
_dbm.dbm.clear
431
487
cls: defining_class
432
488
/
@@ -436,7 +492,7 @@ Remove all items from the database.
436
492
437
493
static PyObject *
438
494
_dbm_dbm_clear_impl (dbmobject * self ,PyTypeObject * cls )
439
- /*[clinic end generated code: output=8d126b9e1d01a434 input=43aa6ca1acb7f5f5 ]*/
495
+ /*[clinic end generated code: output=8d126b9e1d01a434 input=a1aa5d99adfb9656 ]*/
440
496
{
441
497
_dbm_state * state = PyType_GetModuleState (cls );
442
498
assert (state != NULL );