Skip to content

Commit 00ac860

Browse files
committed
Generalize pybind_ops module name
1 parent e654189 commit 00ac860

File tree

4 files changed

+18
-2
lines changed

4 files changed

+18
-2
lines changed

src/torchcodec/_core/CMakeLists.txt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,12 @@ function(make_torchcodec_libraries
151151
PUBLIC
152152
"-fvisibility=hidden"
153153
)
154+
# TODO: comment explaining this
155+
target_compile_definitions(
156+
${pybind_ops_library_name}
157+
PRIVATE
158+
PYBIND_OPS_MODULE_NAME=decoder_core_pybind_ops
159+
)
154160
# If we don't make sure this flag is set, we run into segfauls at import
155161
# time on Mac. See:
156162
# https://github.com/pybind/pybind11/issues/3907#issuecomment-1170412764

src/torchcodec/_core/ops.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515

1616
from torchcodec._internally_replaced_utils import ( # @manual=//pytorch/torchcodec/src:internally_replaced_utils
1717
_get_extension_path,
18+
_get_pybind_ops_module_name,
1819
_load_pybind11_module,
1920
)
2021

@@ -43,8 +44,8 @@ def load_torchcodec_shared_libraries():
4344
# libraries do not meet those conditions.
4445

4546
exceptions = []
46-
pybind_ops_module_name = "decoder_core_pybind_ops"
4747
for ffmpeg_major_version in (7, 6, 5, 4):
48+
pybind_ops_module_name = _get_pybind_ops_module_name(ffmpeg_major_version)
4849
decoder_library_name = f"libtorchcodec_decoder{ffmpeg_major_version}"
4950
custom_ops_library_name = f"libtorchcodec_custom_ops{ffmpeg_major_version}"
5051
pybind_ops_library_name = f"libtorchcodec_pybind_ops{ffmpeg_major_version}"

src/torchcodec/_core/pybind_ops.cpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,11 @@ int64_t create_from_file_like(
3838
return reinterpret_cast<int64_t>(decoder);
3939
}
4040

41-
PYBIND11_MODULE(decoder_core_pybind_ops, m) {
41+
#ifndef PYBIND_OPS_MODULE_NAME
42+
#error PYBIND_OPS_MODULE_NAME must be defined!
43+
#endif
44+
45+
PYBIND11_MODULE(PYBIND_OPS_MODULE_NAME, m) {
4246
m.def("create_from_file_like", &create_from_file_like);
4347
}
4448

src/torchcodec/_internally_replaced_utils.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,3 +51,8 @@ def _load_pybind11_module(module_name: str, library_path: str) -> ModuleType:
5151
)
5252

5353
return importlib.util.module_from_spec(spec)
54+
55+
56+
def _get_pybind_ops_module_name(ffmpeg_major_version: str) -> str:
57+
return "decoder_core_pybind_ops"
58+

0 commit comments

Comments
 (0)