Skip to content

Declare PDC_wcwidth() in curses.h; it defers to the locale even with PDC_FORCE_UTF8 #385

Description

@serhiy-storchaka

Two related things about PDC_wcwidth().

1. It isn't declared in a public header. The function is exported (PDCEX; nm shows T PDC_wcwidth), but declared only in curspriv.h, so a program linking against PDCursesMod has to declare the prototype itself.

This matters most on Windows, where the C runtime has no wcwidth() at all, so PDC_wcwidth() is the only implementation available in the process. A binding that needs to tell a spacing character from a zero-width combining mark — to validate setcchar() input, say — has to carry its own copy. Python's curses module is gaining PDCursesMod support and currently vendors ~120 lines of Markus Kuhn's wcwidth() for the Windows build, duplicating what the library already has and exports. Declaring the existing symbol in curses.h would let consumers drop that.

2. With PDC_FORCE_UTF8, deferring to the system wcwidth() looks wrong. HAVE_WCWIDTH is chosen from __linux + _XOPEN_SOURCE alone, independently of PDC_FORCE_UTF8. HISTORY.md gives the reasoning:

On Linux, we use the system-provided wcwidth() instead of our own. Aside from avoiding redundant code, this may help in non-Unicode locales (our wcwidth() is for Unicode only).

That reasoning holds for a locale-driven build, but PDC_FORCE_UTF8 means the library encodes cells as UTF-8 whatever the locale says — so classification should be Unicode-based too. Built WIDE=Y UTF8=Y with -D_XOPEN_SOURCE=700, under uk_UA.koi8u:

U+0301 (combining acute):  wcwidth() = -1,  PDC_wcwidth() = -1

The same library in a UTF-8 locale returns 0. Would it make sense for PDC_FORCE_UTF8 to select the built-in Unicode table regardless of platform?

(PDCursesMod 4.5.4, vt port, Linux.)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions