Segfault when importing Python Module
Chưa có ai nhận issue này.
Đánh giá
- Độ khó
- 4/5
- Thời gian dự kiến
- 3-5 ngày
- Mức phù hợp với người mới
- 25/100
- Loại issue
- Lỗi
- Độ rõ ràng
- Khá rõ ràng
- Mức độ hoạt động
- Đình trệ
- Lĩnh vực
- backend, build-system
Hướng nghiên cứu
Tái hiện việc import và khởi tạo CarmaClock bằng lớp C++ trong carma_clock.h, wrapper Boost.Python và script Python được cung cấp. Trước tiên, kiểm tra thư viện dùng chung được build bởi CMake và sử dụng core dump với gdb để xác định vị trí segfault; sau đó xác minh rằng việc import module và khởi tạo CarmaClock hoàn tất mà không bị crash.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Mô tả
Hello, I am attempting to wrap a C++ class using boost python into a python includable module. I am using CMake instead of bjam to build the project but I am running into a segfault when I attempt to include import the generated shared library into a python script.
Below is the class as well as the boost python wrapper code and the python script I am using to test this. The entire branch can be found here
/*
* Copyright (C) 2023 LEIDOS.
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
* use this file except in compliance with the License. You may obtain a copy of
* the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations under
* the License.
*/
#pragma once
#include <memory>
#include <condition_variable>
#include <mutex>
#include <vector>
namespace fwha_stol::lib::time {
/** Alias for a timestamp in seconds. */
using timeStampSeconds = uint32_t;
/** Alias for a timestamp in milliseconds. */
using timeStampMilliseconds = uint64_t;
using sleepCVPair = std::pair<std::shared_ptr<std::condition_variable>, std::shared_ptr<std::mutex>>;
using sleepValuePair = std::pair<timeStampMilliseconds, sleepCVPair>;
/**
* @brief Provides access to current time and various utilities. If a simulation is enabled, all time-related
* functions reflect simulation time. Otherwise system time (via std::chrono::system_clock) is utilized.
*
* No interpolation is performed; the most recently received simulation time point is considered to
* be current.
*/
class CarmaClock {
public:
/**
* @brief Create a clock instance using read time mode (default) or simulation mode.
* @param simulation_mode bool flag to indicate whether clock is in simulation mode.
*/
explicit CarmaClock(bool simulation_mode = false);
/**
* @brief Destructor
*/
~CarmaClock() = default;
// Public move constructor and move assignment operator
CarmaClock(const CarmaClock&) = delete; // Deleted copy constructor
CarmaClock& operator=(const CarmaClock&) = delete; // Deleted copy assignment operator
CarmaClock(CarmaClock&&) = delete; // Deleted move constructor
CarmaClock& operator=(CarmaClock&&) = delete; // Deleted move assignment operator
public:
/**
* @brief Get the current time in seconds.
* @return epoch time in seconds as a uint32_t.
*/
timeStampSeconds nowInSeconds() const;
/**
* @brief Get the current time in milliseconds.
* @return epoch time in milliseconds as a uint64_t.
*/
timeStampMilliseconds nowInMilliseconds() const;
public:
/**
* @brief Update the clock time. First call to update will initialize the carma-clock
* @attention only valid when in simulation mode.
* @param current_time in milliseconds to update the clock to.
* @throws std::invalid_argument exception if called while carma-clock is not in simulation
* mode.
*/
void update(timeStampMilliseconds current_time);
public:
/**
* @brief Return whether this instance is in simulation mode.
*/
inline bool is_simulation_mode() const {return _is_simulation_mode; };
/**
* @brief Will block calling thread until carma-clock has been initiliazed
* with the first call to update.
* @attention Only relavent when clock is in simulation mode. If not, will
* immediately unblock.
*/
void wait_for_initialization();
/**
* @brief Sleep until future time.
* @param future_time epoch timestamp in milliseconds to sleep until.
* @throw std::invalid_argument if carma-clock is not initialized.
*/
void sleep_until(timeStampMilliseconds future_time);
/**
* @brief Sleep for time_to_sleep in milliseconds.
* @param time_to_sleep milliseconds from current time to sleep for.
*/
void sleep_for(timeStampMilliseconds time_to_sleep);
private:
// Current simulation time
timeStampMilliseconds _current_time = 0;
// Simulation mode
bool _is_simulation_mode;
// Initialization variables
bool _is_initialized;
// Mutex for conditional variable
std::mutex _initialization_mutex;
// Conditional_variable used to block one or multiple threads until
// carma-clock object is initialized. On initialization all threads are
// notified.
std::condition_variable _initialization_cv;
// sleep related items
// Mutex for conditional variable
std::mutex _sleep_mutex;
// A vector of time, mutex and conditional variables used to
// block calling threads until a certain time update. Each call
// to sleep_until, creates a new entry that includes a time, a conditional
// variable and a mutex for the conditional variable. On each incoming time update
// , all vector entries with times smaller or equal to the incoming update are notified.
// NOTE: Each entry is only expected to have a single thread waiting on it so the relevant
// time update will only notify a single thread for each entry. Multiple threads waiting on
// the same time should each have their one entry in this vector.
std::vector <sleepValuePair> _sleep_holder;
};
}
#include <boost/python.hpp>
#include <boost/python/def.hpp>
#include "carma_clock.h"
BOOST_PYTHON_MODULE(libcarma_clockd) {
using namespace boost::python;
class_<fwha_stol::lib::time::CarmaClock, boost::noncopyable>("CarmaClock", init<bool>(arg("simulation_mode")=false))
.def("nowInSeconds", &fwha_stol::lib::time::CarmaClock::nowInSeconds)
.def("nowInMilliseconds", &fwha_stol::lib::time::CarmaClock::nowInMilliseconds)
.def("update", &fwha_stol::lib::time::CarmaClock::update,args("current_time"))
.def("is_simulation_mode", &fwha_stol::lib::time::CarmaClock::is_simulation_mode)
.def("wait_for_initialization",&fwha_stol::lib::time::CarmaClock::wait_for_initialization)
.def("sleep_until",&fwha_stol::lib::time::CarmaClock::sleep_until,args("future_time"))
.def("sleep_for",&fwha_stol::lib::time::CarmaClock::sleep_for,args("time_to_sleep"));
init_module_libcarma_clockd();
}
#!/usr/bin/python3
import libcarma_clockd
print("Creating Clock Object")
clock = libcarma_clockd.CarmaClock(False)
I suspect this is either related to our constructor with default parameters or our use of std::thread or std::mutex. I am unsure how to continue debugging this issue other than looking at the core dumb with gdb. Any help would be greatly appreciated.
This is currently being built in Jammy dev containers using boost 1.74 and cmake version 3.27.7
- Ngôn ngữ chính
- C++
- Star
- 540
- Fork
- 224
- Chỉ số merge pull request
- Không có pull request nào được merge trong 30 ngày
Chuẩn bị môi trường
Dự án này không cung cấp dev container, Dockerfile hay hướng dẫn đóng góp, nên bạn cần tự thiết lập môi trường: hãy bắt đầu từ README và xem hướng dẫn đóng góp lần đầu của chúng tôi để biết các bước chung.
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Issue khác của boostorg/python
-
numpy::from_data calls vector::front and crashes (or has UB) when called with a scalar objectĐang mở
Độ khó 1/5 Dưới một giờ Mức phù hợp với người mới 84/100
-
Windows CI does not fail if one or more tests failCó thể đã có người làm @stephengtuggy đã nhận 148 ngày trước. Đang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 68/100
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 64/100
-
BoostDetectToolset-1.90.0.cmake file not found in an include() call in boost_python-config.cmakeĐang mở
Độ khó 3/5 1-2 ngày Mức phù hợp với người mới 48/100
-
Windows CI: vcpkg dependency caching not workingCó thể đã có người làm @stephengtuggy đã nhận 148 ngày trước. Đang mở
Độ khó 4/5 3-5 ngày Mức phù hợp với người mới 25/100
Tất cả issue của boostorg/python
Issue tương tự
-
bot-triaged module: correctness (silent) module: fft triage review
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 75/100
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 1/5 Dưới một giờ Mức phù hợp với người mới 68/100
patrickjquinn/Marathon-Shell#84 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 1/5 Dưới một giờ Mức phù hợp với người mới 78/100
sav-oss-org/ptusa_main#1610 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Command gate: one shared constant for the just-below-1e-9 MoveAxis stop epsilon (ZWO, Bisque)Đang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 74/100
open-astro/AlpacaBridge#2606 · 1 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Refactor force_torque_system integration test to use EcmScopeCó thể đã có người làm @patelshivani2283-lab đã nhận hôm nay. Đang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 70/100
Maintainer thường phản hồi trong vòng 1 ngày