This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

作者 josh.r
收信人 AVINASH MISHRA, jdemeyer, josh.r, ncoghlan, remi.lapeyre, ronaldoussoren, serhiy.storchaka, vstinner
日期 2019-01-28.16:53:11
SpamBayes Score -1.0
Marked as misclassified
Message-id <1548694391.77.0.29119544903.issue35707@roundup.psfhosted.org>
In-reply-to
内容
You've got a reference leak in your __index__ based paths. PyNumber_Index is returning a new reference (either to the existing obj, or a new one, if the existing obj isn't already an int). You never release this reference. Simplest fix is to make intobj top level, initialized to NULL, and Py_XDECREF it along the convert_from_int code path (you can't DECREF it in the index specific path because it needs to survive past the goto, since it's replacing obj).

I'm also mildly concerned by how duplicative the code becomes post-patch. If it's not a major performance hit (don't think it is; not even sure the API is even used anymore), perhaps just implement _PyTime_ObjectToTime_t as a wrapper for _PyTime_ObjectToDenominator (with a denominator of 2, so rounding simplifies to just 0 == round down, 1 == round up)?

Example:

int
_PyTime_ObjectToTime_t(PyObject *obj, time_t *sec, _PyTime_round_t round)
{
    long numerator;
    if (_PyTime_ObjectToDenominator(obj, sec, &numerator, 2, round) == 0) {
       if (numerator) {
           if (*sec == _Py_IntegralTypeMax(time_t)) {
               error_time_t_overflow();
               return -1;
           }
           ++*sec;
       }
       return 0;
    }
    return -1;
}

Sorry for not commenting on GitHub, but my work computer has a broken Firefox that GitHub no longer supports properly.
历史
日期 用户 动作 参数
2019-01-28 16:53:13josh.r修改recipients: + josh.r, ronaldoussoren, ncoghlan, vstinner, serhiy.storchaka, jdemeyer, remi.lapeyre, AVINASH MISHRA
2019-01-28 16:53:11josh.r修改messageid: <1548694391.77.0.29119544903.issue35707@roundup.psfhosted.org>
2019-01-28 16:53:11josh.r链接issue35707 messages
2019-01-28 16:53:11josh.r创建