Issue33279
Created on 2018-04-14 18:32 by bup, last changed 2022-04-11 14:58 by admin. This issue is now closed.
| Messages (2) | |||
|---|---|---|---|
| msg315300 - (view) | Author: Dan Snider (bup) * | Date: 2018-04-14 18:32 | |
New to both C and the CPython api so I'm not sure what compiler details matter but this is with VS14 and default compile parameters on windows 10 with 32bit Python.
The following function:
static PyObject *spam(PyObject *module) {
digit w = 9;
int x = 9;
long y = 9;
int32_t z = 9;
return Py_BuildValue("(HIK)(lll)(LLL)", w,w,w,x,y,z,x,y,z);
}
returns:
>>> spam()
((9, 9, 38654705673), (9, 9, 9), (38654705673, 438244858264171835, 6133859984))
Above was the most I could fit in a single Py_BuildValue call without causing a crash (it instantly crashes if "O" or "N" fields are present). I believe this happens because the ints are being upcasted as pointers, which is undefined behavior.
|
|||
| msg315301 - (view) | Author: Serhiy Storchaka (serhiy.storchaka) * ![]() |
Date: 2018-04-14 18:46 | |
This isn't a bug in CPython API. You need to pass arguments of correct type to functions with a variable number of parameters. The compiler doesn't know what type is expected and can't coerce the value automatically. The same undefined behavior your can see with say printf(). |
|||
| History | |||
|---|---|---|---|
| Date | User | Action | Args |
| 2022-04-11 14:58:59 | admin | set | github: 77460 |
| 2018-04-14 18:46:04 | serhiy.storchaka | set | status: open -> closed nosy:
+ serhiy.storchaka resolution: not a bug |
| 2018-04-14 18:32:30 | bup | set | title: Py_Build value is causing crashes with the "L" and "K" format characters when upcasting sub 64-bit integer types -> Py_BuildValue is causing crashes with the "L" and "K" format characters when upcasting sub 64-bit integer types |
| 2018-04-14 18:32:00 | bup | create | |
