Skip to content

Commit 6df8693

Browse files
committed
Merge branch 'master' into sh_merge_master
2 parents e654460 + 68e6fda commit 6df8693

22 files changed

+232
-112
lines changed

.github/workflows/ci_sh_def.yml.patch

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
--- ci.yml 2022-07-21 06:53:22.850154382 -0700
2-
+++ ci_sh_def.yml 2022-07-21 06:54:29.947056986 -0700
1+
--- ci.yml 2022-08-21 19:29:32.986391968 -0700
2+
+++ ci_sh_def.yml 2022-08-21 19:31:47.618458226 -0700
33
@@ -1,4 +1,16 @@
44
-name: CI
55
+# PLEASE KEEP THIS GROUP OF FILES IN SYNC AT ALL TIMES:
@@ -154,26 +154,26 @@
154154
- name: Configure C++11
155155
# LTO leads to many undefined reference like
156156
# `pybind11::detail::function_call::function_call(pybind11::detail::function_call&&)
157-
- run: cmake -G "MinGW Makefiles" -DCMAKE_CXX_STANDARD=11 -DDOWNLOAD_CATCH=ON -S . -B build
158-
+ run: cmake -G "MinGW Makefiles" -DCMAKE_CXX_STANDARD=11 -DDOWNLOAD_CATCH=ON -DCMAKE_CXX_FLAGS="-DPYBIND11_USE_SMART_HOLDER_AS_DEFAULT" -S . -B build
157+
- run: cmake -G "MinGW Makefiles" -DCMAKE_CXX_STANDARD=11 -DCMAKE_VERBOSE_MAKEFILE=ON -DPYBIND11_WERROR=ON -DDOWNLOAD_CATCH=ON -S . -B build
158+
+ run: cmake -G "MinGW Makefiles" -DCMAKE_CXX_STANDARD=11 -DCMAKE_VERBOSE_MAKEFILE=ON -DPYBIND11_WERROR=ON -DDOWNLOAD_CATCH=ON -DCMAKE_CXX_FLAGS="-DPYBIND11_USE_SMART_HOLDER_AS_DEFAULT" -S . -B build
159159

160160
- name: Build C++11
161161
run: cmake --build build -j 2
162162
@@ -930,7 +956,7 @@
163163
run: git clean -fdx
164164

165165
- name: Configure C++14
166-
- run: cmake -G "MinGW Makefiles" -DCMAKE_CXX_STANDARD=14 -DDOWNLOAD_CATCH=ON -S . -B build2
167-
+ run: cmake -G "MinGW Makefiles" -DCMAKE_CXX_STANDARD=14 -DDOWNLOAD_CATCH=O -DCMAKE_CXX_FLAGS="-DPYBIND11_USE_SMART_HOLDER_AS_DEFAULT" -S . -B build2
166+
- run: cmake -G "MinGW Makefiles" -DCMAKE_CXX_STANDARD=14 -DCMAKE_VERBOSE_MAKEFILE=ON -DPYBIND11_WERROR=ON -DDOWNLOAD_CATCH=ON -S . -B build2
167+
+ run: cmake -G "MinGW Makefiles" -DCMAKE_CXX_STANDARD=14 -DCMAKE_VERBOSE_MAKEFILE=ON -DPYBIND11_WERROR=ON -DDOWNLOAD_CATCH=ON -DCMAKE_CXX_FLAGS="-DPYBIND11_USE_SMART_HOLDER_AS_DEFAULT" -S . -B build2
168168

169169
- name: Build C++14
170170
run: cmake --build build2 -j 2
171171
@@ -948,7 +974,7 @@
172172
run: git clean -fdx
173173

174174
- name: Configure C++17
175-
- run: cmake -G "MinGW Makefiles" -DCMAKE_CXX_STANDARD=17 -DDOWNLOAD_CATCH=ON -S . -B build3
176-
+ run: cmake -G "MinGW Makefiles" -DCMAKE_CXX_STANDARD=17 -DDOWNLOAD_CATCH=O -DCMAKE_CXX_FLAGS="-DPYBIND11_USE_SMART_HOLDER_AS_DEFAULT" -S . -B build3
175+
- run: cmake -G "MinGW Makefiles" -DCMAKE_CXX_STANDARD=17 -DCMAKE_VERBOSE_MAKEFILE=ON -DPYBIND11_WERROR=ON -DDOWNLOAD_CATCH=ON -S . -B build3
176+
+ run: cmake -G "MinGW Makefiles" -DCMAKE_CXX_STANDARD=17 -DCMAKE_VERBOSE_MAKEFILE=ON -DPYBIND11_WERROR=ON -DDOWNLOAD_CATCH=ON -DCMAKE_CXX_FLAGS="-DPYBIND11_USE_SMART_HOLDER_AS_DEFAULT" -S . -B build3
177177

178178
- name: Build C++17
179179
run: cmake --build build3 -j 2

.pre-commit-config.yaml

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,9 @@
1212
#
1313
# See https://github.com/pre-commit/pre-commit
1414

15+
# third-party content
16+
exclude: ^tools/JoinPaths.cmake$
17+
1518
repos:
1619
# Standard hooks
1720
- repo: https://github.com/pre-commit/pre-commit-hooks
@@ -93,7 +96,7 @@ repos:
9396

9497
# Automatically remove noqa that are not used
9598
- repo: https://github.com/asottile/yesqa
96-
rev: "v1.3.0"
99+
rev: "v1.4.0"
97100
hooks:
98101
- id: yesqa
99102
additional_dependencies: &flake8_dependencies
@@ -102,7 +105,7 @@ repos:
102105

103106
# Flake8 also supports pre-commit natively (same author)
104107
- repo: https://github.com/PyCQA/flake8
105-
rev: "5.0.2"
108+
rev: "5.0.4"
106109
hooks:
107110
- id: flake8
108111
exclude: ^(docs/.*|tools/.*|ubench/.*)$

CMakeLists.txt

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -205,6 +205,9 @@ else()
205205
endif()
206206

207207
include("${CMAKE_CURRENT_SOURCE_DIR}/tools/pybind11Common.cmake")
208+
# https://github.com/jtojnar/cmake-snips/#concatenating-paths-when-building-pkg-config-files
209+
# TODO: cmake 3.20 adds the cmake_path() function, which obsoletes this snippet
210+
include("${CMAKE_CURRENT_SOURCE_DIR}/tools/JoinPaths.cmake")
208211

209212
# Relative directory setting
210213
if(USE_PYTHON_INCLUDE_DIR AND DEFINED Python_INCLUDE_DIRS)
@@ -269,6 +272,16 @@ if(PYBIND11_INSTALL)
269272
NAMESPACE "pybind11::"
270273
DESTINATION ${PYBIND11_CMAKECONFIG_INSTALL_DIR})
271274

275+
# pkg-config support
276+
if(NOT prefix_for_pc_file)
277+
set(prefix_for_pc_file "${CMAKE_INSTALL_PREFIX}")
278+
endif()
279+
join_paths(includedir_for_pc_file "\${prefix}" "${CMAKE_INSTALL_INCLUDEDIR}")
280+
configure_file("${CMAKE_CURRENT_SOURCE_DIR}/tools/pybind11.pc.in"
281+
"${CMAKE_CURRENT_BINARY_DIR}/pybind11.pc" @ONLY)
282+
install(FILES "${CMAKE_CURRENT_BINARY_DIR}/pybind11.pc"
283+
DESTINATION "${CMAKE_INSTALL_DATAROOTDIR}/pkgconfig/")
284+
272285
# Uninstall target
273286
if(PYBIND11_MASTER_PROJECT)
274287
configure_file("${CMAKE_CURRENT_SOURCE_DIR}/tools/cmake_uninstall.cmake.in"

include/pybind11/detail/class.h

Lines changed: 11 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -504,31 +504,6 @@ inline PyObject *make_object_base_type(PyTypeObject *metaclass) {
504504
return (PyObject *) heap_type;
505505
}
506506

507-
/// dynamic_attr: Support for `d = instance.__dict__`.
508-
extern "C" inline PyObject *pybind11_get_dict(PyObject *self, void *) {
509-
PyObject *&dict = *_PyObject_GetDictPtr(self);
510-
if (!dict) {
511-
dict = PyDict_New();
512-
}
513-
Py_XINCREF(dict);
514-
return dict;
515-
}
516-
517-
/// dynamic_attr: Support for `instance.__dict__ = dict()`.
518-
extern "C" inline int pybind11_set_dict(PyObject *self, PyObject *new_dict, void *) {
519-
if (!PyDict_Check(new_dict)) {
520-
PyErr_Format(PyExc_TypeError,
521-
"__dict__ must be set to a dictionary, not a '%.200s'",
522-
get_fully_qualified_tp_name(Py_TYPE(new_dict)).c_str());
523-
return -1;
524-
}
525-
PyObject *&dict = *_PyObject_GetDictPtr(self);
526-
Py_INCREF(new_dict);
527-
Py_CLEAR(dict);
528-
dict = new_dict;
529-
return 0;
530-
}
531-
532507
/// dynamic_attr: Allow the garbage collector to traverse the internal instance `__dict__`.
533508
extern "C" inline int pybind11_traverse(PyObject *self, visitproc visit, void *arg) {
534509
PyObject *&dict = *_PyObject_GetDictPtr(self);
@@ -560,9 +535,17 @@ inline void enable_dynamic_attributes(PyHeapTypeObject *heap_type) {
560535
type->tp_traverse = pybind11_traverse;
561536
type->tp_clear = pybind11_clear;
562537

563-
static PyGetSetDef getset[] = {
564-
{const_cast<char *>("__dict__"), pybind11_get_dict, pybind11_set_dict, nullptr, nullptr},
565-
{nullptr, nullptr, nullptr, nullptr, nullptr}};
538+
static PyGetSetDef getset[] = {{
539+
#if PY_VERSION_HEX < 0x03070000
540+
const_cast<char *>("__dict__"),
541+
#else
542+
"__dict__",
543+
#endif
544+
PyObject_GenericGetDict,
545+
PyObject_GenericSetDict,
546+
nullptr,
547+
nullptr},
548+
{nullptr, nullptr, nullptr, nullptr, nullptr}};
566549
type->tp_getset = getset;
567550
}
568551

include/pybind11/embed.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,8 @@ inline void initialize_interpreter(bool init_signal_handlers = true,
150150
#else
151151
PyConfig config;
152152
PyConfig_InitIsolatedConfig(&config);
153+
config.isolated = 0;
154+
config.use_environment = 1;
153155
config.install_signal_handlers = init_signal_handlers ? 1 : 0;
154156

155157
PyStatus status = PyConfig_SetBytesArgv(&config, argc, const_cast<char *const *>(argv));

include/pybind11/stl.h

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ using forwarded_type = conditional_t<std::is_lvalue_reference<T>::value,
4545
/// Forwards a value U as rvalue or lvalue according to whether T is rvalue or lvalue; typically
4646
/// used for forwarding a container's elements.
4747
template <typename T, typename U>
48-
forwarded_type<T, U> forward_like(U &&u) {
48+
constexpr forwarded_type<T, U> forward_like(U &&u) {
4949
return std::forward<detail::forwarded_type<T, U>>(std::forward<U>(u));
5050
}
5151

@@ -78,7 +78,7 @@ struct set_caster {
7878
pybind11::set s;
7979
for (auto &&value : src) {
8080
auto value_ = reinterpret_steal<object>(
81-
key_conv::cast(forward_like<T>(value), policy, parent));
81+
key_conv::cast(detail::forward_like<T>(value), policy, parent));
8282
if (!value_ || !s.add(std::move(value_))) {
8383
return handle();
8484
}
@@ -122,9 +122,9 @@ struct map_caster {
122122
}
123123
for (auto &&kv : src) {
124124
auto key = reinterpret_steal<object>(
125-
key_conv::cast(forward_like<T>(kv.first), policy_key, parent));
125+
key_conv::cast(detail::forward_like<T>(kv.first), policy_key, parent));
126126
auto value = reinterpret_steal<object>(
127-
value_conv::cast(forward_like<T>(kv.second), policy_value, parent));
127+
value_conv::cast(detail::forward_like<T>(kv.second), policy_value, parent));
128128
if (!key || !value) {
129129
return handle();
130130
}
@@ -178,7 +178,7 @@ struct list_caster {
178178
ssize_t index = 0;
179179
for (auto &&value : src) {
180180
auto value_ = reinterpret_steal<object>(
181-
value_conv::cast(forward_like<T>(value), policy, parent));
181+
value_conv::cast(detail::forward_like<T>(value), policy, parent));
182182
if (!value_) {
183183
return handle();
184184
}
@@ -242,7 +242,7 @@ struct array_caster {
242242
ssize_t index = 0;
243243
for (auto &&value : src) {
244244
auto value_ = reinterpret_steal<object>(
245-
value_conv::cast(forward_like<T>(value), policy, parent));
245+
value_conv::cast(detail::forward_like<T>(value), policy, parent));
246246
if (!value_) {
247247
return handle();
248248
}

noxfile.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ def lint(session: nox.Session) -> None:
2727
Lint the codebase (except for clang-format/tidy).
2828
"""
2929
session.install("pre-commit")
30-
session.run("pre-commit", "run", "-a")
30+
session.run("pre-commit", "run", "-a", *session.posargs)
3131

3232

3333
@nox.session(python=PYTHON_VERSIONS)
@@ -58,7 +58,7 @@ def tests_packaging(session: nox.Session) -> None:
5858
"""
5959

6060
session.install("-r", "tests/requirements.txt", "--prefer-binary")
61-
session.run("pytest", "tests/extra_python_package")
61+
session.run("pytest", "tests/extra_python_package", *session.posargs)
6262

6363

6464
@nox.session(reuse_venv=True)

pybind11/__init__.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,12 @@
66

77

88
from ._version import __version__, version_info
9-
from .commands import get_cmake_dir, get_include
9+
from .commands import get_cmake_dir, get_include, get_pkgconfig_dir
1010

1111
__all__ = (
1212
"version_info",
1313
"__version__",
1414
"get_include",
1515
"get_cmake_dir",
16+
"get_pkgconfig_dir",
1617
)

pybind11/__main__.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
import sys
55
import sysconfig
66

7-
from .commands import get_cmake_dir, get_include
7+
from .commands import get_cmake_dir, get_include, get_pkgconfig_dir
88

99

1010
def print_includes() -> None:
@@ -36,13 +36,20 @@ def main() -> None:
3636
action="store_true",
3737
help="Print the CMake module directory, ideal for setting -Dpybind11_ROOT in CMake.",
3838
)
39+
parser.add_argument(
40+
"--pkgconfigdir",
41+
action="store_true",
42+
help="Print the pkgconfig directory, ideal for setting $PKG_CONFIG_PATH.",
43+
)
3944
args = parser.parse_args()
4045
if not sys.argv[1:]:
4146
parser.print_help()
4247
if args.includes:
4348
print_includes()
4449
if args.cmakedir:
4550
print(get_cmake_dir())
51+
if args.pkgconfigdir:
52+
print(get_pkgconfig_dir())
4653

4754

4855
if __name__ == "__main__":

pybind11/commands.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,3 +23,15 @@ def get_cmake_dir() -> str:
2323

2424
msg = "pybind11 not installed, installation required to access the CMake files"
2525
raise ImportError(msg)
26+
27+
28+
def get_pkgconfig_dir() -> str:
29+
"""
30+
Return the path to the pybind11 pkgconfig directory.
31+
"""
32+
pkgconfig_installed_path = os.path.join(DIR, "share", "pkgconfig")
33+
if os.path.exists(pkgconfig_installed_path):
34+
return pkgconfig_installed_path
35+
36+
msg = "pybind11 not installed, installation required to access the pkgconfig files"
37+
raise ImportError(msg)

setup.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,7 @@ def remove_output(*sources: str) -> Iterator[None]:
127127
"-DCMAKE_INSTALL_PREFIX=pybind11",
128128
"-DBUILD_TESTING=OFF",
129129
"-DPYBIND11_NOPYTHON=ON",
130+
"-Dprefix_for_pc_file=${pcfiledir}/../../",
130131
]
131132
if "CMAKE_ARGS" in os.environ:
132133
fcommand = [

0 commit comments

Comments
 (0)