classification
Title: Symbol resolution conflict when embeding python in an application using libedit
Type: crash Stage: resolved
Components: Library (Lib) Versions: Python 3.9, Python 3.8
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: gregory.p.smith Nosy List: gregory.p.smith, miss-islington, ned.deily, pmpp, serge-sans-paille, vstinner
Priority: normal Keywords: patch

Created on 2019-10-29 15:17 by serge-sans-paille, last changed 2019-12-04 17:08 by vstinner. This issue is now closed.

Pull Requests
URL Status Linked Edit
PR 16986 merged serge-sans-paille, 2019-10-29 15:17
PR 17466 merged miss-islington, 2019-12-04 16:03
Messages (6)
msg355656 - (view) Author: (serge-sans-paille) * Date: 2019-10-29 15:17
See https://bugs.llvm.org/show_bug.cgi?id=43830, but basically the follwing code:

```
// a.c
#include <Python.h>

int main() {
  Py_Initialize();
  PyRun_SimpleString("import readline; print(readline.__doc__)");
  return 0;
}
```

compiled like this:

```
% gcc a.c `./install/bin/python3-config --cflags --ldflags --libs` -lpython3.9
```

runs fine:

```
% ./a.out                                          
Importing this module enables command line editing using GNU readline.
```

However the following:

```
% gcc a.c `./install/bin/python3-config --cflags --ldflags --libs` -ledit -lpython3.9
```

compiles but segfaults at runtime.
msg355672 - (view) Author: Ned Deily (ned.deily) * (Python committer) Date: 2019-10-29 19:42
This appears to be essentially a duplicate of Issue13631 which has long proposed full support of libedit.
msg355931 - (view) Author: (serge-sans-paille) * Date: 2019-11-04 08:27
@ned I(d rather see this as an evolution of Issue13631, as this solves a problem when libreadline and libedit are both loaded in the same executable. As such, using libedit instead of readline wouldn't solve the issue: what if the program Python is embeded in is linked to readline?

I find python approach relatively elegant: detect the linked library at runtime and use the ad-hoc implementation based on this.

An other option would be to dlopen readline using the RTLD_LOCAL flag, so that we get a better, non intrusive symbol resolution.

What do you think?
msg357808 - (view) Author: STINNER Victor (vstinner) * (Python committer) Date: 2019-12-04 16:03
New changeset 7105319ada2e663659020cbe9fdf7ff38f421ab2 by Victor Stinner (serge-sans-paille) in branch 'master':
 bpo-38634: Allow non-apple build to cope with libedit (GH-16986)
https://github.com/python/cpython/commit/7105319ada2e663659020cbe9fdf7ff38f421ab2
msg357810 - (view) Author: miss-islington (miss-islington) Date: 2019-12-04 16:21
New changeset 68669ef7883ea6338ca441e50f4f9d975f54d017 by Miss Islington (bot) in branch '3.8':
bpo-38634: Allow non-apple build to cope with libedit (GH-16986)
https://github.com/python/cpython/commit/68669ef7883ea6338ca441e50f4f9d975f54d017
msg357813 - (view) Author: STINNER Victor (vstinner) * (Python committer) Date: 2019-12-04 17:08
Thanks serge-sans-paille for the bug report and the fix!

I backported it to 3.8 since it could be automated, but I don't think that it's worth it to backport it to 3.7:
https://github.com/python/cpython/pull/16986#issuecomment-561711232
History
Date User Action Args
2019-12-04 17:08:27vstinnersetstatus: open -> closed
resolution: fixed
messages: + msg357813

stage: patch review -> resolved
2019-12-04 16:21:21miss-islingtonsetnosy: + miss-islington
messages: + msg357810
2019-12-04 16:03:58vstinnersetcomponents: + Library (Lib)
versions: + Python 3.8, Python 3.9
2019-12-04 16:03:22miss-islingtonsetpull_requests: + pull_request16945
2019-12-04 16:03:04vstinnersetnosy: + vstinner
messages: + msg357808
2019-11-04 08:27:47serge-sans-paillesetmessages: + msg355931
2019-10-29 19:42:04ned.deilysetassignee: gregory.p.smith

messages: + msg355672
nosy: + gregory.p.smith, ned.deily
2019-10-29 15:28:37pmppsetnosy: + pmpp
2019-10-29 15:17:41serge-sans-paillesetkeywords: + patch
stage: patch review
pull_requests: + pull_request16512
2019-10-29 15:17:05serge-sans-paillecreate