Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitc274774

Browse files
committed
Merge branch 'master' into speedup-Fraction-fromstr/72902
2 parents4acffeb +c3a1da5 commitc274774

10 files changed

+248
-49
lines changed

‎Lib/test/test_fractions.py

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -501,22 +501,23 @@ def check_invalid(s):
501501
deftest_limit_int(self):
502502
maxdigits=5000
503503
withadjust_int_max_str_digits(maxdigits):
504+
msg='Exceeds the limit'
504505
val='1'*maxdigits
505506
num= (10**maxdigits-1)//9
506507
self.assertEqual((num,1),_components(F(val)))
507-
self.assertRaises(ValueError,F,val+'1')
508+
self.assertRaisesRegex(ValueError,msg,F,val+'1')
508509
self.assertEqual((num,2),_components(F(val+'/2')))
509-
self.assertRaises(ValueError,F,val+'1/2')
510+
self.assertRaisesRegex(ValueError,msg,F,val+'1/2')
510511
self.assertEqual((1,num),_components(F('1/'+val)))
511-
self.assertRaises(ValueError,F,'1/1'+val)
512+
self.assertRaisesRegex(ValueError,msg,F,'1/1'+val)
512513
self.assertEqual(((10**(maxdigits+1)-1)//9,10**maxdigits),
513514
_components(F('1.'+val)))
514-
self.assertRaises(ValueError,F,'1.1'+val)
515+
self.assertRaisesRegex(ValueError,msg,F,'1.1'+val)
515516
self.assertEqual((num,10**maxdigits),_components(F('.'+val)))
516-
self.assertRaises(ValueError,F,'.1'+val)
517-
self.assertRaises(ValueError,F,'1.1e1'+val)
517+
self.assertRaisesRegex(ValueError,msg,F,'.1'+val)
518+
self.assertRaisesRegex(ValueError,msg,F,'1.1e1'+val)
518519
self.assertEqual((11,10),_components(F('1.1e'+'0'*maxdigits)))
519-
self.assertRaises(ValueError,F,'1.1e'+'0'* (maxdigits+1))
520+
self.assertRaisesRegex(ValueError,msg,F,'1.1e'+'0'* (maxdigits+1))
520521

521522
deftestImmutable(self):
522523
r=F(7,3)

‎Lib/test/test_genericalias.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@
6161
fromtkinterimportEvent
6262
exceptImportError:
6363
Event=None
64+
fromstring.templatelibimportTemplate,Interpolation
6465

6566
fromtypingimportTypeVar
6667
T=TypeVar('T')
@@ -139,7 +140,10 @@ class BaseTest(unittest.TestCase):
139140
DictReader,DictWriter,
140141
array,
141142
staticmethod,
142-
classmethod]
143+
classmethod,
144+
Template,
145+
Interpolation,
146+
]
143147
ifctypesisnotNone:
144148
generic_types.extend((ctypes.Array,ctypes.LibraryLoader,ctypes.py_object))
145149
ifValueProxyisnotNone:
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
Fix libc thread safety issues with:mod:`dbm` by performing stateful
2+
operations in critical sections.
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
Make:class:`!string.templatelib.Template` and
2+
:class:`!string.templatelib.Interpolation` generic.

‎Modules/_dbmmodule.c

Lines changed: 66 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@ typedef struct {
6969
#include"clinic/_dbmmodule.c.h"
7070

7171
#definecheck_dbmobject_open(v,err) \
72+
_Py_CRITICAL_SECTION_ASSERT_OBJECT_LOCKED((v)) \
7273
if ((v)->di_dbm == NULL) { \
7374
PyErr_SetString(err, "DBM object has already been closed"); \
7475
return NULL; \
@@ -116,7 +117,7 @@ dbm_dealloc(PyObject *self)
116117
}
117118

118119
staticPy_ssize_t
119-
dbm_length(PyObject*self)
120+
dbm_length_lock_held(PyObject*self)
120121
{
121122
dbmobject*dp=dbmobject_CAST(self);
122123
_dbm_state*state=PyType_GetModuleState(Py_TYPE(dp));
@@ -138,8 +139,18 @@ dbm_length(PyObject *self)
138139
returndp->di_size;
139140
}
140141

142+
staticPy_ssize_t
143+
dbm_length(PyObject*self)
144+
{
145+
Py_ssize_tresult;
146+
Py_BEGIN_CRITICAL_SECTION(self);
147+
result=dbm_length_lock_held(self);
148+
Py_END_CRITICAL_SECTION();
149+
returnresult;
150+
}
151+
141152
staticint
142-
dbm_bool(PyObject*self)
153+
dbm_bool_lock_held(PyObject*self)
143154
{
144155
dbmobject*dp=dbmobject_CAST(self);
145156
_dbm_state*state=PyType_GetModuleState(Py_TYPE(dp));
@@ -170,8 +181,18 @@ dbm_bool(PyObject *self)
170181
return1;
171182
}
172183

184+
staticint
185+
dbm_bool(PyObject*self)
186+
{
187+
intresult;
188+
Py_BEGIN_CRITICAL_SECTION(self);
189+
result=dbm_bool_lock_held(self);
190+
Py_END_CRITICAL_SECTION();
191+
returnresult;
192+
}
193+
173194
staticPyObject*
174-
dbm_subscript(PyObject*self,PyObject*key)
195+
dbm_subscript_lock_held(PyObject*self,PyObject*key)
175196
{
176197
datumdrec,krec;
177198
Py_ssize_ttmp_size;
@@ -197,8 +218,18 @@ dbm_subscript(PyObject *self, PyObject *key)
197218
returnPyBytes_FromStringAndSize(drec.dptr,drec.dsize);
198219
}
199220

221+
staticPyObject*
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+
returnresult;
229+
}
230+
200231
staticint
201-
dbm_ass_sub(PyObject*self,PyObject*v,PyObject*w)
232+
dbm_ass_sub_lock_held(PyObject*self,PyObject*v,PyObject*w)
202233
{
203234
datumkrec,drec;
204235
Py_ssize_ttmp_size;
@@ -252,15 +283,26 @@ dbm_ass_sub(PyObject *self, PyObject *v, PyObject *w)
252283
return0;
253284
}
254285

286+
staticint
287+
dbm_ass_sub(PyObject*self,PyObject*v,PyObject*w)
288+
{
289+
intresult;
290+
Py_BEGIN_CRITICAL_SECTION(self);
291+
result=dbm_ass_sub_lock_held(self,v,w);
292+
Py_END_CRITICAL_SECTION();
293+
returnresult;
294+
}
295+
255296
/*[clinic input]
297+
@critical_section
256298
_dbm.dbm.close
257299
258300
Close the database.
259301
[clinic start generated code]*/
260302

261303
staticPyObject*
262304
_dbm_dbm_close_impl(dbmobject*self)
263-
/*[clinic end generated code: output=c8dc5b6709600b86 input=046db72377d51be8]*/
305+
/*[clinic end generated code: output=c8dc5b6709600b86 input=4a94f79facbc28ca]*/
264306
{
265307
if (self->di_dbm) {
266308
dbm_close(self->di_dbm);
@@ -270,6 +312,7 @@ _dbm_dbm_close_impl(dbmobject *self)
270312
}
271313

272314
/*[clinic input]
315+
@critical_section
273316
_dbm.dbm.keys
274317
275318
cls: defining_class
@@ -279,7 +322,7 @@ Return a list of all keys in the database.
279322

280323
staticPyObject*
281324
_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]*/
283326
{
284327
PyObject*v,*item;
285328
datumkey;
@@ -310,7 +353,7 @@ _dbm_dbm_keys_impl(dbmobject *self, PyTypeObject *cls)
310353
}
311354

312355
staticint
313-
dbm_contains(PyObject*self,PyObject*arg)
356+
dbm_contains_lock_held(PyObject*self,PyObject*arg)
314357
{
315358
dbmobject*dp=dbmobject_CAST(self);
316359
datumkey,val;
@@ -343,7 +386,18 @@ dbm_contains(PyObject *self, PyObject *arg)
343386
returnval.dptr!=NULL;
344387
}
345388

389+
staticint
390+
dbm_contains(PyObject*self,PyObject*arg)
391+
{
392+
intresult;
393+
Py_BEGIN_CRITICAL_SECTION(self);
394+
result=dbm_contains_lock_held(self,arg);
395+
Py_END_CRITICAL_SECTION();
396+
returnresult;
397+
}
398+
346399
/*[clinic input]
400+
@critical_section
347401
_dbm.dbm.get
348402
cls: defining_class
349403
key: str(accept={str, robuffer}, zeroes=True)
@@ -356,7 +410,7 @@ Return the value for key if present, otherwise default.
356410
staticPyObject*
357411
_dbm_dbm_get_impl(dbmobject*self,PyTypeObject*cls,constchar*key,
358412
Py_ssize_tkey_length,PyObject*default_value)
359-
/*[clinic end generated code: output=b4e55f8b6d482bc4 input=66b993b8349fa8c1]*/
413+
/*[clinic end generated code: output=b4e55f8b6d482bc4 input=1d88a22bb5e55202]*/
360414
{
361415
datumdbm_key,val;
362416
_dbm_state*state=PyType_GetModuleState(cls);
@@ -373,6 +427,7 @@ _dbm_dbm_get_impl(dbmobject *self, PyTypeObject *cls, const char *key,
373427
}
374428

375429
/*[clinic input]
430+
@critical_section
376431
_dbm.dbm.setdefault
377432
cls: defining_class
378433
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.
387442
staticPyObject*
388443
_dbm_dbm_setdefault_impl(dbmobject*self,PyTypeObject*cls,constchar*key,
389444
Py_ssize_tkey_length,PyObject*default_value)
390-
/*[clinic end generated code: output=9c2f6ea6d0fb576c input=126a3ff15c5f8232]*/
445+
/*[clinic end generated code: output=9c2f6ea6d0fb576c input=c01510ef7571e13b]*/
391446
{
392447
datumdbm_key,val;
393448
Py_ssize_ttmp_size;
@@ -427,6 +482,7 @@ _dbm_dbm_setdefault_impl(dbmobject *self, PyTypeObject *cls, const char *key,
427482
}
428483

429484
/*[clinic input]
485+
@critical_section
430486
_dbm.dbm.clear
431487
cls: defining_class
432488
/
@@ -436,7 +492,7 @@ Remove all items from the database.
436492

437493
staticPyObject*
438494
_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]*/
440496
{
441497
_dbm_state*state=PyType_GetModuleState(cls);
442498
assert(state!=NULL);

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp