Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
Greenplum
Opencv
提交
ef85b24a
O
Opencv
项目概览
Greenplum
/
Opencv
大约 1 年 前同步成功
通知
7
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
O
Opencv
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
ef85b24a
编写于
1月 27, 2022
作者:
V
Vadim Levin
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
fix: wrong reference counter after module initialization
上级
16661847
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
21 addition
and
9 deletion
+21
-9
modules/python/src2/cv2.cpp
modules/python/src2/cv2.cpp
+9
-5
modules/python/test/test_misc.py
modules/python/test/test_misc.py
+12
-4
未找到文件。
modules/python/src2/cv2.cpp
浏览文件 @
ef85b24a
...
@@ -2184,18 +2184,22 @@ static PyObject* createSubmodule(PyObject* parent_module, const std::string& nam
...
@@ -2184,18 +2184,22 @@ static PyObject* createSubmodule(PyObject* parent_module, const std::string& nam
submodule_name
.
c_str
());
submodule_name
.
c_str
());
if
(
!
submodule
)
if
(
!
submodule
)
{
{
/// Populates global modules dictionary and returns borrowed reference to it
submodule
=
PyImport_AddModule
(
full_submodule_name
.
c_str
());
submodule
=
PyImport_AddModule
(
full_submodule_name
.
c_str
());
if
(
!
submodule
)
{
/// Return `PyImport_AddModule` NULL with an exception set on failure.
return
NULL
;
}
/// Populates parent module dictionary. Submodule lifetime should be managed
/// by the global modules dictionary and parent module dictionary, so Py_DECREF after
/// successfull call to the `PyDict_SetItemString` is redundant.
if
(
PyDict_SetItemString
(
parent_module_dict
,
submodule_name
.
c_str
(),
submodule
)
<
0
)
{
if
(
PyDict_SetItemString
(
parent_module_dict
,
submodule_name
.
c_str
(),
submodule
)
<
0
)
{
Py_CLEAR
(
submodule
);
return
PyErr_Format
(
PyExc_ImportError
,
return
PyErr_Format
(
PyExc_ImportError
,
"Can't register a submodule '%s' (full name: '%s')"
,
"Can't register a submodule '%s' (full name: '%s')"
,
submodule_name
.
c_str
(),
full_submodule_name
.
c_str
()
submodule_name
.
c_str
(),
full_submodule_name
.
c_str
()
);
);
}
}
/// PyDict_SetItemString doesn't steal a reference so the reference counter
/// of the submodule should be decremented to bind submodule lifetime to the
/// parent module
Py_DECREF
(
submodule
);
}
}
submodule_name_start
=
submodule_name_end
+
1
;
submodule_name_start
=
submodule_name_end
+
1
;
...
...
modules/python/test/test_misc.py
浏览文件 @
ef85b24a
...
@@ -602,10 +602,18 @@ class Arguments(NewOpenCVTests):
...
@@ -602,10 +602,18 @@ class Arguments(NewOpenCVTests):
msg
=
"Module is not generated for nested namespace"
)
msg
=
"Module is not generated for nested namespace"
)
self
.
assertTrue
(
hasattr
(
cv
.
utils
.
nested
,
"testEchoBooleanFunction"
),
self
.
assertTrue
(
hasattr
(
cv
.
utils
.
nested
,
"testEchoBooleanFunction"
),
msg
=
"Function in nested module is not available"
)
msg
=
"Function in nested module is not available"
)
self
.
assertEqual
(
sys
.
getrefcount
(
cv
.
utils
.
nested
),
2
,
msg
=
"Nested submodule lifetime should be managed by "
# Nested submodule is managed by the global submodules dictionary
"the parent module so the reference count should be "
# and parent native module
"2, because `getrefcount` temporary increases it."
)
expected_ref_count
=
2
# `getrefcount` temporary increases reference counter by 1
actual_ref_count
=
sys
.
getrefcount
(
cv
.
utils
.
nested
)
-
1
self
.
assertEqual
(
actual_ref_count
,
expected_ref_count
,
msg
=
"Nested submodule reference counter has wrong value
\n
"
"Expected: {}. Actual: {}"
.
format
(
expected_ref_count
,
actual_ref_count
))
for
flag
in
(
True
,
False
):
for
flag
in
(
True
,
False
):
self
.
assertEqual
(
flag
,
cv
.
utils
.
nested
.
testEchoBooleanFunction
(
flag
),
self
.
assertEqual
(
flag
,
cv
.
utils
.
nested
.
testEchoBooleanFunction
(
flag
),
msg
=
"Function in nested module returns wrong result"
)
msg
=
"Function in nested module returns wrong result"
)
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录