Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
P
pybind11
Overview
Overview
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
Wiki
Wiki
Snippets
Snippets
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
open
pybind11
Commits
31fbf18a
Commit
31fbf18a
authored
Nov 20, 2016
by
Wenzel Jakob
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
replace redundant function_record->class_ field with 1 bit
parent
7c2461ee
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
14 additions
and
14 deletions
+14
-14
include/pybind11/attr.h
+9
-9
include/pybind11/pybind11.h
+5
-5
No files found.
include/pybind11/attr.h
View file @
31fbf18a
...
@@ -115,15 +115,15 @@ struct function_record {
...
@@ -115,15 +115,15 @@ struct function_record {
/// True if the function has a '**kwargs' argument
/// True if the function has a '**kwargs' argument
bool
has_kwargs
:
1
;
bool
has_kwargs
:
1
;
/// True if this is a method
bool
is_method
:
1
;
/// Number of arguments
/// Number of arguments
uint16_t
nargs
;
uint16_t
nargs
;
/// Python method object
/// Python method object
PyMethodDef
*
def
=
nullptr
;
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)
/// Python handle to the parent scope (a class or a module)
handle
scope
;
handle
scope
;
...
@@ -235,7 +235,7 @@ template <> struct process_attribute<sibling> : process_attribute_default<siblin
...
@@ -235,7 +235,7 @@ template <> struct process_attribute<sibling> : process_attribute_default<siblin
/// Process an attribute which indicates that this function is a method
/// Process an attribute which indicates that this function is a method
template
<>
struct
process_attribute
<
is_method
>
:
process_attribute_default
<
is_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
/// 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
...
@@ -251,7 +251,7 @@ template <> struct process_attribute<is_operator> : process_attribute_default<is
/// Process a keyword argument attribute (*without* a default value)
/// Process a keyword argument attribute (*without* a default value)
template
<>
struct
process_attribute
<
arg
>
:
process_attribute_default
<
arg
>
{
template
<>
struct
process_attribute
<
arg
>
:
process_attribute_default
<
arg
>
{
static
void
init
(
const
arg
&
a
,
function_record
*
r
)
{
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
(
"self"
,
nullptr
,
handle
());
r
->
args
.
emplace_back
(
a
.
name
,
nullptr
,
handle
());
r
->
args
.
emplace_back
(
a
.
name
,
nullptr
,
handle
());
}
}
...
@@ -260,17 +260,17 @@ template <> struct process_attribute<arg> : process_attribute_default<arg> {
...
@@ -260,17 +260,17 @@ template <> struct process_attribute<arg> : process_attribute_default<arg> {
/// Process a keyword argument attribute (*with* a default value)
/// Process a keyword argument attribute (*with* a default value)
template
<>
struct
process_attribute
<
arg_v
>
:
process_attribute_default
<
arg_v
>
{
template
<>
struct
process_attribute
<
arg_v
>
:
process_attribute_default
<
arg_v
>
{
static
void
init
(
const
arg_v
&
a
,
function_record
*
r
)
{
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
());
r
->
args
.
emplace_back
(
"self"
,
nullptr
,
handle
());
if
(
!
a
.
value
)
{
if
(
!
a
.
value
)
{
#if !defined(NDEBUG)
#if !defined(NDEBUG)
auto
descr
=
"'"
+
std
::
string
(
a
.
name
)
+
": "
+
a
.
type
+
"'"
;
auto
descr
=
"'"
+
std
::
string
(
a
.
name
)
+
": "
+
a
.
type
+
"'"
;
if
(
r
->
class_
)
{
if
(
r
->
is_method
)
{
if
(
r
->
name
)
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
else
descr
+=
" in method of '"
+
(
std
::
string
)
str
(
r
->
class_
)
+
"'"
;
descr
+=
" in method of '"
+
(
std
::
string
)
str
(
r
->
scope
)
+
"'"
;
}
else
if
(
r
->
name
)
{
}
else
if
(
r
->
name
)
{
descr
+=
" in function named '"
+
(
std
::
string
)
r
->
name
+
"'"
;
descr
+=
" in function named '"
+
(
std
::
string
)
r
->
name
+
"'"
;
}
}
...
...
include/pybind11/pybind11.h
View file @
31fbf18a
...
@@ -194,10 +194,10 @@ protected:
...
@@ -194,10 +194,10 @@ protected:
if
(
type_depth
==
0
&&
text
[
char_index
]
!=
'*'
&&
arg_index
<
args
)
{
if
(
type_depth
==
0
&&
text
[
char_index
]
!=
'*'
&&
arg_index
<
args
)
{
if
(
!
rec
->
args
.
empty
())
{
if
(
!
rec
->
args
.
empty
())
{
signature
+=
rec
->
args
[
arg_index
].
name
;
signature
+=
rec
->
args
[
arg_index
].
name
;
}
else
if
(
arg_index
==
0
&&
rec
->
class_
)
{
}
else
if
(
arg_index
==
0
&&
rec
->
is_method
)
{
signature
+=
"self"
;
signature
+=
"self"
;
}
else
{
}
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
+=
": "
;
signature
+=
": "
;
}
}
...
@@ -337,8 +337,8 @@ protected:
...
@@ -337,8 +337,8 @@ protected:
std
::
free
((
char
*
)
func
->
m_ml
->
ml_doc
);
std
::
free
((
char
*
)
func
->
m_ml
->
ml_doc
);
func
->
m_ml
->
ml_doc
=
strdup
(
signatures
.
c_str
());
func
->
m_ml
->
ml_doc
=
strdup
(
signatures
.
c_str
());
if
(
rec
->
class_
)
{
if
(
rec
->
is_method
)
{
m_ptr
=
PYBIND11_INSTANCE_METHOD_NEW
(
m_ptr
,
rec
->
class_
.
ptr
());
m_ptr
=
PYBIND11_INSTANCE_METHOD_NEW
(
m_ptr
,
rec
->
scope
.
ptr
());
if
(
!
m_ptr
)
if
(
!
m_ptr
)
pybind11_fail
(
"cpp_function::cpp_function(): Could not allocate instance method object"
);
pybind11_fail
(
"cpp_function::cpp_function(): Could not allocate instance method object"
);
Py_DECREF
(
func
);
Py_DECREF
(
func
);
...
@@ -1120,7 +1120,7 @@ public:
...
@@ -1120,7 +1120,7 @@ public:
const
auto
property
=
reinterpret_steal
<
object
>
(
const
auto
property
=
reinterpret_steal
<
object
>
(
PyObject_CallFunctionObjArgs
((
PyObject
*
)
&
PyProperty_Type
,
fget
.
ptr
()
?
fget
.
ptr
()
:
Py_None
,
PyObject_CallFunctionObjArgs
((
PyObject
*
)
&
PyProperty_Type
,
fget
.
ptr
()
?
fget
.
ptr
()
:
Py_None
,
fset
.
ptr
()
?
fset
.
ptr
()
:
Py_None
,
Py_None
,
doc_obj
.
ptr
(),
nullptr
));
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
;
attr
(
name
)
=
property
;
else
else
metaclass
().
attr
(
name
)
=
property
;
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