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

Commit8a9a6b4

Browse files
authored
[3.7]bpo-9566: Fix compiler warnings on Windows (GH-12920)
*bpo-9566: Fix compiler warnings in gcmodule.c (GH-11010)Change PyDTrace_GC_DONE() argument type from int to Py_ssize_t.(cherry picked from commitedad38e)*bpo-30465: Fix C downcast warning on Windows in ast.c (#6593)ast.c: fstring_fix_node_location() downcasts a pointer difference toa C int. Replace int with Py_ssize_t to fix the compiler warning.(cherry picked from commitfb7e799)*bpo-9566: Fix compiler warnings in peephole.c (GH-10652)(cherry picked from commit028f0ef)*bpo-27645, sqlite: Fix integer overflow on sleep (#6594)Use the _PyTime_t type and round away from zero (ROUND_UP,_PyTime_ROUND_TIMEOUT) the sleep duration, when converting a Pythonobject to seconds and then to milliseconds. Raise an OverflowError incase of overflow.Previously the (int)double conversion rounded towards zero(ROUND_DOWN).(cherry picked from commitca40501)
1 parent9344d74 commit8a9a6b4

File tree

4 files changed

+69
-27
lines changed

4 files changed

+69
-27
lines changed

‎Include/pydtrace.h‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ static inline void PyDTrace_LINE(const char *arg0, const char *arg1, int arg2) {
2929
staticinlinevoidPyDTrace_FUNCTION_ENTRY(constchar*arg0,constchar*arg1,intarg2) {}
3030
staticinlinevoidPyDTrace_FUNCTION_RETURN(constchar*arg0,constchar*arg1,intarg2) {}
3131
staticinlinevoidPyDTrace_GC_START(intarg0) {}
32-
staticinlinevoidPyDTrace_GC_DONE(intarg0) {}
32+
staticinlinevoidPyDTrace_GC_DONE(Py_ssize_targ0) {}
3333
staticinlinevoidPyDTrace_INSTANCE_NEW_START(intarg0) {}
3434
staticinlinevoidPyDTrace_INSTANCE_NEW_DONE(intarg0) {}
3535
staticinlinevoidPyDTrace_INSTANCE_DELETE_START(intarg0) {}

‎Modules/_sqlite/connection.c‎

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1462,17 +1462,33 @@ pysqlite_connection_backup(pysqlite_Connection *self, PyObject *args, PyObject *
14621462
constchar*name="main";
14631463
intrc;
14641464
intcallback_error=0;
1465-
doublesleep_secs=0.250;
1465+
PyObject*sleep_obj=NULL;
1466+
intsleep_ms=250;
14661467
sqlite3*bck_conn;
14671468
sqlite3_backup*bck_handle;
14681469
staticchar*keywords[]= {"target","pages","progress","name","sleep",NULL};
14691470

1470-
if (!PyArg_ParseTupleAndKeywords(args,kwds,"O!|$iOsd:backup",keywords,
1471+
if (!PyArg_ParseTupleAndKeywords(args,kwds,"O!|$iOsO:backup",keywords,
14711472
&pysqlite_ConnectionType,&target,
1472-
&pages,&progress,&name,&sleep_secs)) {
1473+
&pages,&progress,&name,&sleep_obj)) {
14731474
returnNULL;
14741475
}
14751476

1477+
if (sleep_obj!=NULL) {
1478+
_PyTime_tsleep_secs;
1479+
if (_PyTime_FromSecondsObject(&sleep_secs,sleep_obj,
1480+
_PyTime_ROUND_TIMEOUT)) {
1481+
returnNULL;
1482+
}
1483+
_PyTime_tms=_PyTime_AsMilliseconds(sleep_secs,
1484+
_PyTime_ROUND_TIMEOUT);
1485+
if (ms<INT_MIN||ms>INT_MAX) {
1486+
PyErr_SetString(PyExc_OverflowError,"sleep is too large");
1487+
returnNULL;
1488+
}
1489+
sleep_ms= (int)ms;
1490+
}
1491+
14761492
if (!pysqlite_check_connection((pysqlite_Connection*)target)) {
14771493
returnNULL;
14781494
}
@@ -1532,7 +1548,7 @@ pysqlite_connection_backup(pysqlite_Connection *self, PyObject *args, PyObject *
15321548
the engine could not make any progress */
15331549
if (rc==SQLITE_BUSY||rc==SQLITE_LOCKED) {
15341550
Py_BEGIN_ALLOW_THREADS
1535-
sqlite3_sleep(sleep_secs*1000.0);
1551+
sqlite3_sleep(sleep_ms);
15361552
Py_END_ALLOW_THREADS
15371553
}
15381554
}while (rc==SQLITE_OK||rc==SQLITE_BUSY||rc==SQLITE_LOCKED);

‎Python/ast.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4282,7 +4282,7 @@ fstring_fix_node_location(const node *parent, node *n, char *expr_str)
42824282
break;
42834283
start--;
42844284
}
4285-
cols+=substr-start;
4285+
cols+=(int)(substr-start);
42864286
/* Fix lineno in mulitline strings. */
42874287
while ((substr=strchr(substr+1,'\n')))
42884288
lines--;

‎Python/peephole.c‎

Lines changed: 47 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,15 @@ fold_tuple_on_constants(_Py_CODEUNIT *codestr, Py_ssize_t codelen,
152152
PyTuple_SET_ITEM(newconst,i,constant);
153153
}
154154

155+
Py_ssize_tindex=PyList_GET_SIZE(consts);
156+
#ifSIZEOF_SIZE_T>SIZEOF_INT
157+
if ((size_t)index >=UINT_MAX-1) {
158+
Py_DECREF(newconst);
159+
PyErr_SetString(PyExc_OverflowError,"too many constants");
160+
return-1;
161+
}
162+
#endif
163+
155164
/* Append folded constant onto consts */
156165
if (PyList_Append(consts,newconst)) {
157166
Py_DECREF(newconst);
@@ -160,7 +169,7 @@ fold_tuple_on_constants(_Py_CODEUNIT *codestr, Py_ssize_t codelen,
160169
Py_DECREF(newconst);
161170

162171
returncopy_op_arg(codestr,c_start,LOAD_CONST,
163-
PyList_GET_SIZE(consts)-1,opcode_end);
172+
(unsignedint)index,opcode_end);
164173
}
165174

166175
staticunsignedint*
@@ -223,7 +232,7 @@ PyObject *
223232
PyCode_Optimize(PyObject*code,PyObject*consts,PyObject*names,
224233
PyObject*lnotab_obj)
225234
{
226-
Py_ssize_th,i,nexti,op_start,codelen,tgt;
235+
Py_ssize_th,i,nexti,op_start,tgt;
227236
unsignedintj,nops;
228237
unsignedcharopcode,nextop;
229238
_Py_CODEUNIT*codestr=NULL;
@@ -251,17 +260,22 @@ PyCode_Optimize(PyObject *code, PyObject* consts, PyObject *names,
251260
the peephole optimizer doesn't modify line numbers. */
252261

253262
assert(PyBytes_Check(code));
254-
codelen=PyBytes_GET_SIZE(code);
255-
assert(codelen %sizeof(_Py_CODEUNIT)==0);
263+
Py_ssize_tcodesize=PyBytes_GET_SIZE(code);
264+
assert(codesize %sizeof(_Py_CODEUNIT)==0);
265+
Py_ssize_tcodelen=codesize /sizeof(_Py_CODEUNIT);
266+
if (codelen>INT_MAX) {
267+
/* Python assembler is limited to INT_MAX: see assembler.a_offset in
268+
compile.c. */
269+
gotoexitUnchanged;
270+
}
256271

257272
/* Make a modifiable copy of the code string */
258-
codestr= (_Py_CODEUNIT*)PyMem_Malloc(codelen);
273+
codestr= (_Py_CODEUNIT*)PyMem_Malloc(codesize);
259274
if (codestr==NULL) {
260275
PyErr_NoMemory();
261276
gotoexitError;
262277
}
263-
memcpy(codestr,PyBytes_AS_STRING(code),codelen);
264-
codelen /=sizeof(_Py_CODEUNIT);
278+
memcpy(codestr,PyBytes_AS_STRING(code),codesize);
265279

266280
blocks=markblocks(codestr,codelen);
267281
if (blocks==NULL)
@@ -359,7 +373,11 @@ PyCode_Optimize(PyObject *code, PyObject* consts, PyObject *names,
359373
jump past it), and all conditional jumps pop their
360374
argument when they're not taken (so change the
361375
first jump to pop its argument when it's taken). */
362-
h=set_arg(codestr,i, (tgt+1)*sizeof(_Py_CODEUNIT));
376+
Py_ssize_targ= (tgt+1);
377+
/* cannot overflow: codelen <= INT_MAX */
378+
assert((size_t)arg <=UINT_MAX /sizeof(_Py_CODEUNIT));
379+
arg *=sizeof(_Py_CODEUNIT);
380+
h=set_arg(codestr,i, (unsignedint)arg);
363381
j=opcode==JUMP_IF_TRUE_OR_POP ?
364382
POP_JUMP_IF_TRUE :POP_JUMP_IF_FALSE;
365383
}
@@ -392,17 +410,20 @@ PyCode_Optimize(PyObject *code, PyObject* consts, PyObject *names,
392410
codestr[op_start]=PACKOPARG(RETURN_VALUE,0);
393411
fill_nops(codestr,op_start+1,i+1);
394412
}elseif (UNCONDITIONAL_JUMP(_Py_OPCODE(codestr[tgt]))) {
395-
j=GETJUMPTGT(codestr,tgt);
413+
size_targ=GETJUMPTGT(codestr,tgt);
396414
if (opcode==JUMP_FORWARD) {/* JMP_ABS can go backwards */
397415
opcode=JUMP_ABSOLUTE;
398416
}elseif (!ABSOLUTE_JUMP(opcode)) {
399-
if ((Py_ssize_t)j<i+1) {
417+
if (arg<(size_t)(i+1)) {
400418
break;/* No backward relative jumps */
401419
}
402-
j-=i+1;/* Calc relative jump addr */
420+
arg-=i+1;/* Calc relative jump addr */
403421
}
404-
j *=sizeof(_Py_CODEUNIT);
405-
copy_op_arg(codestr,op_start,opcode,j,i+1);
422+
/* cannot overflow: codelen <= INT_MAX */
423+
assert(arg <= (UINT_MAX /sizeof(_Py_CODEUNIT)));
424+
arg *=sizeof(_Py_CODEUNIT);
425+
copy_op_arg(codestr,op_start,opcode,
426+
(unsignedint)arg,i+1);
406427
}
407428
break;
408429

@@ -422,11 +443,14 @@ PyCode_Optimize(PyObject *code, PyObject* consts, PyObject *names,
422443

423444
/* Fixup lnotab */
424445
for (i=0,nops=0;i<codelen;i++) {
425-
assert(i-nops <=INT_MAX);
446+
size_tblock= (size_t)i-nops;
447+
/* cannot overflow: codelen <= INT_MAX */
448+
assert(block <=UINT_MAX);
426449
/* original code offset => new code offset */
427-
blocks[i]=i-nops;
428-
if (_Py_OPCODE(codestr[i])==NOP)
450+
blocks[i]=(unsignedint)block;
451+
if (_Py_OPCODE(codestr[i])==NOP) {
429452
nops++;
453+
}
430454
}
431455
cum_orig_offset=0;
432456
last_offset=0;
@@ -473,12 +497,14 @@ PyCode_Optimize(PyObject *code, PyObject* consts, PyObject *names,
473497
j *=sizeof(_Py_CODEUNIT);
474498
break;
475499
}
476-
nexti=i-op_start+1;
477-
if (instrsize(j)>nexti)
500+
Py_ssize_tilen=i-op_start+1;
501+
if (instrsize(j)>ilen) {
478502
gotoexitUnchanged;
479-
/* If instrsize(j) < nexti, we'll emit EXTENDED_ARG 0 */
480-
write_op_arg(codestr+h,opcode,j,nexti);
481-
h+=nexti;
503+
}
504+
assert(ilen <=INT_MAX);
505+
/* If instrsize(j) < ilen, we'll emit EXTENDED_ARG 0 */
506+
write_op_arg(codestr+h,opcode,j, (int)ilen);
507+
h+=ilen;
482508
}
483509
assert(h+ (Py_ssize_t)nops==codelen);
484510

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2026 Movatter.jp