Minimal Boost Python example not working

オープン
#437 コメント 7 件 リアクション 0 件 担当者 0 名 GitHub で見る

まだ誰も着手していません。

評価

難易度
4/5
見積もり時間
3〜5日
初心者へのやさしさ
32/100
issue の種類
バグ
明瞭さ
おおむね明確
活発さ
停滞
技術スタック
cpp, python
領域
api, backend

調査の方向性

示されている C++20 Boost.Python モジュールを Python 3.10 と my_module.printStr 呼び出しで実行し、その後 def("printStr", printStr) 周辺の境界と std::string 変換を調べてください。問題を再現するために必要なビルドおよびランタイム構成を記録し、呼び出しが segmentation fault なしで BEFORE、メッセージ、AFTER を出力したら完了を確認してください。

索引モデルが issue の本文から書いたものです。

説明

I'm having trouble getting boost python to work with this minimal example. I've emailed the mailing list but have had no response.

I'm using C++20

#include <boost/python.hpp>

#include <iostream>
#include <string>

void printStr(const std::string &testStr) {
  std::cout << "BEFORE" <<std::endl;
  std::cout << testStr <<std::endl;
  std::cout << "AFTER" <<std::endl;
}

BOOST_PYTHON_MODULE(my_module) {
  using namespace boost::python;

  def("printStr", printStr);
}

This compiles fine, but I get a segmentation fault when I attempt to call the function from python (using 3.10):

import my_module

message = "This is a test"

my_module.printStr(message)

The output I get:

BEFORE
Segmentation fault

Can you tell me what I'm doing wrong? Thanks in advance

主要言語
C++
スター
537
フォーク
223
平均マージ
11時間 22分
マージ済み PR(30日)
2

コントリビューションガイド

このリポジトリのコントリビューションガイドは索引されていません

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

boostorg/python のほかの issue

boostorg/python の issue をすべて見る

似ている issue

C++ の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。