Skip to content

Conversation

veyron95
Copy link
Contributor

@veyron95 veyron95 commented Oct 10, 2022

PR types

Bug fixes

PR changes

Others

Describe

Bug fixes --- 修复PaddleSeg模型报错问题

Linux 机器
int, long, long long, sizeof 分别是 4 8 8

Windows 机器
int, long, long long, sizeof 分别是 4 4 8

原代码:
other = static_cast<float>(CastPyArg2AttrInt(other_obj, 0));

在 windows 机器下,PyLong_AsLong 接收 8 字节的数据会 overflow

int CastPyArg2AttrInt(PyObject* obj, ssize_t arg_pos) {
  if (PyObject_CheckLongOrConvertToLong(&obj)) {
    return static_cast<int>(PyLong_AsLong(obj)); // overflow 发生的地方
  } else {
    PADDLE_THROW(platform::errors::InvalidArgument(
        "argument (position %d) must be "
        "int, but got %s",
        arg_pos + 1,
        (reinterpret_cast<PyTypeObject*>(obj->ob_type))->tp_name));
  }
}

现代码:
other = CastPyArg2AttrFloat(other_obj, 0);
内部返回 static_cast< float >(PyFloat_AsDouble(obj)); 可以避免因接收 8 字节数据导致的 overflow 问题

@paddle-bot
Copy link

paddle-bot bot commented Oct 10, 2022

你的PR提交成功,感谢你对开源项目的贡献!
请关注后续CI自动化测试结果,详情请参考Paddle-CI手册
Your PR has been submitted. Thanks for your contribution!
Please wait for the result of CI firstly. See Paddle CI Manual for details.

Copy link
Contributor

@wanghuancoder wanghuancoder left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@wanghuancoder wanghuancoder merged commit 9eefc38 into PaddlePaddle:develop Oct 11, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants