Skip to content
GitLab
Projects Groups Snippets
  • /
  • Help
    • Help
    • Support
    • Community forum
    • Submit feedback
    • Contribute to GitLab
  • Sign in / Register
  • G GLib
  • Project information
    • Project information
    • Activity
    • Labels
    • Members
  • Repository
    • Repository
    • Files
    • Commits
    • Branches
    • Tags
    • Contributors
    • Graph
    • Compare
  • Issues 862
    • Issues 862
    • List
    • Boards
    • Service Desk
    • Milestones
  • Merge requests 41
    • Merge requests 41
  • CI/CD
    • CI/CD
    • Pipelines
    • Jobs
    • Schedules
  • Deployments
    • Deployments
    • Releases
  • Packages and registries
    • Packages and registries
    • Container Registry
  • Analytics
    • Analytics
    • Value stream
    • CI/CD
    • Repository
  • Wiki
    • Wiki
  • Snippets
    • Snippets
  • Activity
  • Graph
  • Create a new issue
  • Jobs
  • Commits
  • Issue Boards
Collapse sidebar
  • GNOMEGNOME
  • GLib
  • Issues
  • #1430
Closed
Open
Issue created Jun 25, 2018 by Will Thompson@wjtDeveloper

With LC_ALL=C, glib-mkenums crashes when writing non-ASCII chars to stdout

It is common to call glib-mkenums from a Makefile like this:

glib-mkenums ... > $@.tmp && mv $@.tmp $@

If the template (and hence output) contains non-ASCII characters, and LC_ALL=C, then this will fail:

$ cat enums.h.template 
/*** BEGIN file-header ***/
/* © */
/*** END file-header ***/

$ LC_ALL=C glib-mkenums --template enums.h.template c.h > /tmp/enums.h
Traceback (most recent call last):
  File "/usr/bin/glib-mkenums", line 425, in <module>
    write_output(prod)
  File "/usr/bin/glib-mkenums", line 74, in write_output
    print(output, file=output_stream)
UnicodeEncodeError: 'ascii' codec can't encode character '\xa9' in position 3: ordinal not in range(128)

This is apparently not specific to running this script with Python 3.

This is not purely theoretical because GNOME Builder sets LC_ALL and friends to C in order to be able to parse directory changes in the output.

The fix on a per-project basis is to use the --output argument, which seems to have existed for a long time and is the documented pattern, but perhaps it's worth trying to cope better, perhaps by detecting that stdout's encoding is ASCII and silently “upgrading” it to UTF-8.

Assignee
Assign to
Time tracking