Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
gaoqiong
pybind11
Commits
31fbf18a
"git@developer.sourcefind.cn:gaoqiong/pybind11.git" did not exist on "5fd5074a0b19ff6f28c85513e2ebe01a9b20948e"
Commit
31fbf18a
authored
Nov 20, 2016
by
Wenzel Jakob
Browse files
replace redundant function_record->class_ field with 1 bit
parent
7c2461ee
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
14 additions
and
14 deletions
+14
-14
include/pybind11/attr.h
include/pybind11/attr.h
+9
-9
include/pybind11/pybind11.h
include/pybind11/pybind11.h
+5
-5
No files found.
include/pybind11/attr.h
View file @
31fbf18a
...
...
@@ -115,15 +115,15 @@ struct function_record {
/// True if the function has a '**kwargs' argument
bool
has_kwargs
:
1
;
/// True if this is a method
bool
is_method
:
1
;
/// Number of arguments
uint16_t
nargs
;
/// Python method object
PyMethodDef
*
def
=
nullptr
;
/// Python handle to the associated class (if this is method)
handle
class_
;
/// Python handle to the parent scope (a class or a module)
handle
scope
;
...
...
@@ -235,7 +235,7 @@ template <> struct process_attribute<sibling> : process_attribute_default<siblin
/// Process an attribute which indicates that this function is a method
template
<
>
struct
process_attribute
<
is_method
>
:
process_attribute_default
<
is_method
>
{
static
void
init
(
const
is_method
&
s
,
function_record
*
r
)
{
r
->
class_
=
s
.
class_
;
r
->
scope
=
s
.
class_
;
}
static
void
init
(
const
is_method
&
s
,
function_record
*
r
)
{
r
->
is_method
=
true
;
r
->
scope
=
s
.
class_
;
}
};
/// Process an attribute which indicates the parent scope of a method
...
...
@@ -251,7 +251,7 @@ template <> struct process_attribute<is_operator> : process_attribute_default<is
/// Process a keyword argument attribute (*without* a default value)
template
<
>
struct
process_attribute
<
arg
>
:
process_attribute_default
<
arg
>
{
static
void
init
(
const
arg
&
a
,
function_record
*
r
)
{
if
(
r
->
class_
&&
r
->
args
.
empty
())
if
(
r
->
is_method
&&
r
->
args
.
empty
())
r
->
args
.
emplace_back
(
"self"
,
nullptr
,
handle
());
r
->
args
.
emplace_back
(
a
.
name
,
nullptr
,
handle
());
}
...
...
@@ -260,17 +260,17 @@ template <> struct process_attribute<arg> : process_attribute_default<arg> {
/// Process a keyword argument attribute (*with* a default value)
template
<
>
struct
process_attribute
<
arg_v
>
:
process_attribute_default
<
arg_v
>
{
static
void
init
(
const
arg_v
&
a
,
function_record
*
r
)
{
if
(
r
->
class_
&&
r
->
args
.
empty
())
if
(
r
->
is_method
&&
r
->
args
.
empty
())
r
->
args
.
emplace_back
(
"self"
,
nullptr
,
handle
());
if
(
!
a
.
value
)
{
#if !defined(NDEBUG)
auto
descr
=
"'"
+
std
::
string
(
a
.
name
)
+
": "
+
a
.
type
+
"'"
;
if
(
r
->
class_
)
{
if
(
r
->
is_method
)
{
if
(
r
->
name
)
descr
+=
" in method '"
+
(
std
::
string
)
str
(
r
->
class_
)
+
"."
+
(
std
::
string
)
r
->
name
+
"'"
;
descr
+=
" in method '"
+
(
std
::
string
)
str
(
r
->
scope
)
+
"."
+
(
std
::
string
)
r
->
name
+
"'"
;
else
descr
+=
" in method of '"
+
(
std
::
string
)
str
(
r
->
class_
)
+
"'"
;
descr
+=
" in method of '"
+
(
std
::
string
)
str
(
r
->
scope
)
+
"'"
;
}
else
if
(
r
->
name
)
{
descr
+=
" in function named '"
+
(
std
::
string
)
r
->
name
+
"'"
;
}
...
...
include/pybind11/pybind11.h
View file @
31fbf18a
...
...
@@ -194,10 +194,10 @@ protected:
if
(
type_depth
==
0
&&
text
[
char_index
]
!=
'*'
&&
arg_index
<
args
)
{
if
(
!
rec
->
args
.
empty
())
{
signature
+=
rec
->
args
[
arg_index
].
name
;
}
else
if
(
arg_index
==
0
&&
rec
->
class_
)
{
}
else
if
(
arg_index
==
0
&&
rec
->
is_method
)
{
signature
+=
"self"
;
}
else
{
signature
+=
"arg"
+
std
::
to_string
(
arg_index
-
(
rec
->
class_
?
1
:
0
));
signature
+=
"arg"
+
std
::
to_string
(
arg_index
-
(
rec
->
is_method
?
1
:
0
));
}
signature
+=
": "
;
}
...
...
@@ -337,8 +337,8 @@ protected:
std
::
free
((
char
*
)
func
->
m_ml
->
ml_doc
);
func
->
m_ml
->
ml_doc
=
strdup
(
signatures
.
c_str
());
if
(
rec
->
class_
)
{
m_ptr
=
PYBIND11_INSTANCE_METHOD_NEW
(
m_ptr
,
rec
->
class_
.
ptr
());
if
(
rec
->
is_method
)
{
m_ptr
=
PYBIND11_INSTANCE_METHOD_NEW
(
m_ptr
,
rec
->
scope
.
ptr
());
if
(
!
m_ptr
)
pybind11_fail
(
"cpp_function::cpp_function(): Could not allocate instance method object"
);
Py_DECREF
(
func
);
...
...
@@ -1120,7 +1120,7 @@ public:
const
auto
property
=
reinterpret_steal
<
object
>
(
PyObject_CallFunctionObjArgs
((
PyObject
*
)
&
PyProperty_Type
,
fget
.
ptr
()
?
fget
.
ptr
()
:
Py_None
,
fset
.
ptr
()
?
fset
.
ptr
()
:
Py_None
,
Py_None
,
doc_obj
.
ptr
(),
nullptr
));
if
(
rec_fget
->
class_
)
if
(
rec_fget
->
is_method
&&
rec_fget
->
scope
)
attr
(
name
)
=
property
;
else
metaclass
().
attr
(
name
)
=
property
;
...
...
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