Opened 5 years ago

Closed 5 years ago

#23857 closed enhancement (fixed)

Implement conversion C++ <-> str

Reported by: Jeroen Demeyer Owned by:
Priority: major Milestone: sage-8.1
Component: python3 Keywords:
Cc: Erik Bray Merged in:
Authors: Jeroen Demeyer Reviewers: Vincent Delecroix
Report Upstream: N/A Work issues:
Branch: b7127ce (Commits, GitHub, GitLab) Commit: b7127ce548910ff52d71867a817ab9485ca5636b
Dependencies: Stopgaps:

Status badges

Description (last modified by Jeroen Demeyer)

In order to clean up the wrapping of C++ code, we need proper conversion of C++ objects to and from Python strings. This is currently done in a hacky way in ccobject.h but it can be done more cleanly using Cython's support for C++ templates.

In particular, we implement:

  • ccrepr() to convert any C++ object to str
  • ccreadstr() to convert a str to a C++ object

We intentionally use the words repr and read because this is using string input/output (operators << and >>).

Moreover, this new function will support both Python 2 and Python 3. In the latter case, the filesystem encoding is used.

Change History (15)

comment:1 Changed 5 years ago by Jeroen Demeyer

Description: modified (diff)
Summary: Implement cppstr() to convert any C++ object to strImplement ccstr() to convert any C++ object to str

comment:2 Changed 5 years ago by Jeroen Demeyer

Component: cythonpython3
Description: modified (diff)

comment:3 Changed 5 years ago by Jeroen Demeyer

Description: modified (diff)

comment:4 Changed 5 years ago by Jeroen Demeyer

Description: modified (diff)
Summary: Implement ccstr() to convert any C++ object to strImplement conversion C++ <-> str

comment:5 Changed 5 years ago by Jeroen Demeyer

Branch: u/jdemeyer/implement_cppstr___to_convert_any_c___object_to_str

comment:6 Changed 5 years ago by Jeroen Demeyer

Commit: 5952084bb630d922463bc103c38a314f91d6bc28
Status: newneeds_review

New commits:

5952084Implement conversion C++ <-> str

comment:7 Changed 5 years ago by git

Commit: 5952084bb630d922463bc103c38a314f91d6bc2888d9ded1584a98ebe4bd57a9e88945bad3d30f60

Branch pushed to git repo; I updated commit sha1. This was a forced push. New commits:

88d9dedImplement conversion C++ <-> str

comment:8 Changed 5 years ago by git

Commit: 88d9ded1584a98ebe4bd57a9e88945bad3d30f608598ab6f1fb354f63c21c5a9876b4d075b57aeb9

Branch pushed to git repo; I updated commit sha1. This was a forced push. New commits:

8598ab6Implement conversion C++ <-> str

comment:9 Changed 5 years ago by git

Commit: 8598ab6f1fb354f63c21c5a9876b4d075b57aeb9b7127ce548910ff52d71867a817ab9485ca5636b

Branch pushed to git repo; I updated commit sha1. This was a forced push. New commits:

b7127ceImplement conversion C++ <-> str

comment:10 Changed 5 years ago by Jeroen Demeyer

Cc: Erik Bray added
Description: modified (diff)

comment:11 Changed 5 years ago by Jeroen Demeyer

Description: modified (diff)

comment:12 Changed 5 years ago by Vincent Delecroix

This is nice! How did you test the Python3 version?

comment:13 in reply to:  12 Changed 5 years ago by Jeroen Demeyer

Replying to vdelecroix:

This is nice! How did you test the Python3 version?

To be honest, I did not. I am just hoping that it works.

comment:14 Changed 5 years ago by Vincent Delecroix

Reviewers: Vincent Delecroix
Status: needs_reviewpositive_review

comment:15 Changed 5 years ago by Volker Braun

Branch: u/jdemeyer/implement_cppstr___to_convert_any_c___object_to_strb7127ce548910ff52d71867a817ab9485ca5636b
Resolution: fixed
Status: positive_reviewclosed
Note: See TracTickets for help on using tickets.