Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
KDevelop
KDevelop Python Support
Commits
cefa7ec2
Commit
cefa7ec2
authored
Oct 24, 2022
by
frmdstryr
Committed by
Sven Brauch
Nov 05, 2022
Browse files
Add slice and use PyObjectRef instead of decrefs
parent
7026ff59
Changes
4
Expand all
Hide whitespace changes
Inline
Side-by-side
parser/astbuilder.cpp
View file @
cefa7ec2
...
...
@@ -52,17 +52,6 @@ QString PyUnicodeObjectToQString(PyObject* obj) {
Q_UNREACHABLE
();
}
class
PyObjectRef
{
public:
PyObjectRef
(
PyObject
*
py_obj
)
:
obj
(
py_obj
)
{}
PyObject
*
get
()
{
return
obj
;}
~
PyObjectRef
()
{
Py_XDECREF
(
obj
);
obj
=
nullptr
;
}
PyObject
*
obj
=
nullptr
;
};
struct
PythonParser
:
private
QMutexLocker
{
PyObject
*
m_parser_mod
=
nullptr
;
...
...
@@ -87,14 +76,14 @@ struct PythonParser : private QMutexLocker
QString
supportDir
=
parserFile
.
absoluteDir
().
path
();
Q_ASSERT
(
supportDir
.
size
());
PyObjectRef
sys
=
PyImport_ImportModule
(
"sys"
);
if
(
!
sys
.
get
()
)
return
;
PyObjectRef
path
=
PyObject_GetAttrString
(
sys
.
get
()
,
"path"
);
if
(
!
path
.
get
()
)
return
;
PyObjectRef
append
=
PyObject_GetAttrString
(
path
.
get
()
,
"append"
);
if
(
!
append
.
get
()
)
return
;
if
(
!
sys
)
return
;
PyObjectRef
path
=
PyObject_GetAttrString
(
sys
,
"path"
);
if
(
!
path
)
return
;
PyObjectRef
append
=
PyObject_GetAttrString
(
path
,
"append"
);
if
(
!
append
)
return
;
PyObjectRef
arg
=
PyUnicode_FromString
(
supportDir
.
toUtf8
().
data
());
if
(
!
arg
.
get
()
)
return
;
PyObjectRef
r
=
PyObject_CallOneArg
(
append
.
get
(),
arg
.
get
()
);
if
(
!
arg
)
return
;
PyObjectRef
r
=
PyObject_CallOneArg
(
append
,
arg
);
}
// Call parser function and return the python ast.Module.
...
...
parser/asttransformer.cpp
View file @
cefa7ec2
This diff is collapsed.
Click to expand it.
parser/asttransformer.h
View file @
cefa7ec2
...
...
@@ -5,6 +5,20 @@
namespace
Python
{
class
PyObjectRef
{
public:
PyObjectRef
(
PyObject
*
py_obj
)
:
obj
(
py_obj
)
{}
operator
PyObject
*
()
const
{
return
obj
;
}
~
PyObjectRef
()
{
Py_XDECREF
(
obj
);
obj
=
nullptr
;
}
PyObject
*
obj
=
nullptr
;
};
class
AstTransformer
{
public:
CodeAst
*
ast
;
...
...
parser/python_grammar.h
View file @
cefa7ec2
...
...
@@ -148,6 +148,9 @@ public:
// withitem
PyObject
*
ast_withitem
;
// slice
PyObject
*
ast_slice
;
#if PYTHON_VERSION >= QT_VERSION_CHECK(3, 10, 0)
// match_case
PyObject
*
ast_match_case
;
...
...
@@ -295,6 +298,7 @@ public:
Py_GRAMMAR_GET
(
mod
,
keyword
);
Py_GRAMMAR_GET
(
mod
,
alias
);
Py_GRAMMAR_GET
(
mod
,
withitem
);
Py_GRAMMAR_GET
(
mod
,
slice
);
#if PYTHON_VERSION >= QT_VERSION_CHECK(3, 10, 0)
Py_GRAMMAR_GET
(
mod
,
match_case
);
...
...
@@ -437,6 +441,7 @@ public:
Py_XDECREF
(
ast_keyword
);
Py_XDECREF
(
ast_alias
);
Py_XDECREF
(
ast_withitem
);
Py_XDECREF
(
ast_slice
);
#if PYTHON_VERSION >= QT_VERSION_CHECK(3, 10, 0)
Py_XDECREF
(
ast_match_case
);
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new 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