Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in / Register
Toggle navigation
O
opencv
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Packages
Packages
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
submodule
opencv
Commits
d4ac4fcd
Commit
d4ac4fcd
authored
Aug 30, 2018
by
Hamdi Sahloul
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Python binding: METH_STATIC instead of METH_CLASS for static functions
parent
335e61dc
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
14 additions
and
14 deletions
+14
-14
gen2.py
modules/python/src2/gen2.py
+14
-14
No files found.
modules/python/src2/gen2.py
View file @
d4ac4fcd
...
...
@@ -534,13 +534,13 @@ class FuncVariant(object):
class
FuncInfo
(
object
):
def
__init__
(
self
,
classname
,
name
,
cname
,
isconstructor
,
namespace
,
is
classmethod
):
def
__init__
(
self
,
classname
,
name
,
cname
,
isconstructor
,
namespace
,
is
_static
):
self
.
classname
=
classname
self
.
name
=
name
self
.
cname
=
cname
self
.
isconstructor
=
isconstructor
self
.
namespace
=
namespace
self
.
is
classmethod
=
isclassmethod
self
.
is
_static
=
is_static
self
.
variants
=
[]
def
add_variant
(
self
,
decl
,
isphantom
=
False
):
...
...
@@ -555,8 +555,8 @@ class FuncInfo(object):
else
:
classname
=
""
if
self
.
is
classmethod
:
name
+=
"_
cls
"
if
self
.
is
_static
:
name
+=
"_
static
"
return
"pyopencv_"
+
self
.
namespace
.
replace
(
'.'
,
'_'
)
+
'_'
+
classname
+
name
...
...
@@ -615,7 +615,7 @@ class FuncInfo(object):
return
Template
(
' {"$py_funcname", CV_PY_FN_WITH_KW_($wrap_funcname, $flags), "$py_docstring"},
\n
'
)
.
substitute
(
py_funcname
=
self
.
variants
[
0
]
.
wname
,
wrap_funcname
=
self
.
get_wrapper_name
(),
flags
=
'METH_
CLASS'
if
self
.
isclassmethod
else
'0'
,
py_docstring
=
full_docstring
)
flags
=
'METH_
STATIC'
if
self
.
is_static
else
'0'
,
py_docstring
=
full_docstring
)
def
gen_code
(
self
,
codegen
):
all_classes
=
codegen
.
classes
...
...
@@ -632,7 +632,7 @@ class FuncInfo(object):
selfinfo
=
all_classes
[
self
.
classname
]
if
not
self
.
isconstructor
:
amp
=
"&"
if
selfinfo
.
issimple
else
""
if
self
.
is
classmethod
:
if
self
.
is
_static
:
pass
elif
selfinfo
.
isalgorithm
:
code
+=
gen_template_check_self_algo
.
substitute
(
name
=
selfinfo
.
name
,
cname
=
selfinfo
.
cname
,
amp
=
amp
)
...
...
@@ -652,7 +652,7 @@ class FuncInfo(object):
all_cargs
=
[]
parse_arglist
=
[]
if
v
.
isphantom
and
ismethod
and
not
self
.
is
classmethod
:
if
v
.
isphantom
and
ismethod
and
not
self
.
is
_static
:
code_args
+=
"_self_"
# declare all the C function arguments,
...
...
@@ -740,7 +740,7 @@ class FuncInfo(object):
if
v
.
rettype
:
code_decl
+=
" "
+
v
.
rettype
+
" retval;
\n
"
code_fcall
+=
"retval = "
if
ismethod
and
not
self
.
is
classmethod
:
if
ismethod
and
not
self
.
is
_static
:
code_fcall
+=
"_self_->"
+
self
.
cname
else
:
code_fcall
+=
self
.
cname
...
...
@@ -821,7 +821,7 @@ class FuncInfo(object):
#if dump: pprint(vars(classinfo))
if
self
.
isconstructor
:
py_name
=
'cv.'
+
classinfo
.
wname
elif
self
.
is
classmethod
:
elif
self
.
is
_static
:
py_name
=
'.'
.
join
([
self
.
namespace
,
classinfo
.
sname
+
'_'
+
self
.
variants
[
0
]
.
wname
])
else
:
cname
=
classinfo
.
cname
+
'::'
+
cname
...
...
@@ -929,12 +929,12 @@ class PythonWrapperGenerator(object):
namespace
=
'.'
.
join
(
namespace
)
isconstructor
=
name
==
bareclassname
is
classmethod
=
False
is
_static
=
False
isphantom
=
False
mappable
=
None
for
m
in
decl
[
2
]:
if
m
==
"/S"
:
is
classmethod
=
True
is
_static
=
True
elif
m
==
"/phantom"
:
isphantom
=
True
cname
=
cname
.
replace
(
"::"
,
"_"
)
...
...
@@ -948,10 +948,10 @@ class PythonWrapperGenerator(object):
if
isconstructor
:
name
=
"_"
.
join
(
classes
[:
-
1
]
+
[
name
])
if
is
classmethod
:
if
is
_static
:
# Add it as a method to the class
func_map
=
self
.
classes
[
classname
]
.
methods
func
=
func_map
.
setdefault
(
name
,
FuncInfo
(
classname
,
name
,
cname
,
isconstructor
,
namespace
,
is
classmethod
))
func
=
func_map
.
setdefault
(
name
,
FuncInfo
(
classname
,
name
,
cname
,
isconstructor
,
namespace
,
is
_static
))
func
.
add_variant
(
decl
,
isphantom
)
# Add it as global function
...
...
@@ -966,7 +966,7 @@ class PythonWrapperGenerator(object):
else
:
func_map
=
self
.
namespaces
.
setdefault
(
namespace
,
Namespace
())
.
funcs
func
=
func_map
.
setdefault
(
name
,
FuncInfo
(
classname
,
name
,
cname
,
isconstructor
,
namespace
,
is
classmethod
))
func
=
func_map
.
setdefault
(
name
,
FuncInfo
(
classname
,
name
,
cname
,
isconstructor
,
namespace
,
is
_static
))
func
.
add_variant
(
decl
,
isphantom
)
if
classname
and
isconstructor
:
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment