ctypes.CDLL on Linux creates a "main program" object when passed an empty string

Open
#99,874 3 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
3/5
Estimated time
1-2 days
Newbie friendliness
46/100
Issue type
Bug
Clarity
Mostly clear
Activity status
Stale
Tech stack
python

Research direction

Start by running the reported ctypes.CDLL('') reproducer on Linux and compare it with a missing library name. Trace the ctypes.CDLL loading path and make the empty-string case raise an exception rather than create a dummy object; done when that behavior is covered by a regression test.

Written by the indexing model from the issue text.

Description

docs topic-ctypes

Bug report

ctypes.CDLL throws an exception when it can't find a library in the path pointed at by its name argument; however, if name is an empty string a dummy object is created:

>>> import ctypes
>>> ctypes.CDLL('')
<CDLL '', handle 7fb30d2d3190 at 0x7fb30c2caa60>

I don't think this is correct, since that dummy object will break things when trying to use it later on.

Your environment

  • CPython versions tested on: 3.8.10, 3.10.8
  • Operating system and architecture: Ubuntu 20.04.5 LTS for x86_64

This doesn't happen on Windows with Python 3.10.7; there I see an exception being thrown for the empty string.

Dominant language
Python
Stars
77.2k
Forks
36k
Avg merge
1d 9h
Merged PRs (30d)
558

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from python/cpython

All issues in python/cpython

Similar issues

More Python issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.