GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — gh-92651: Remove the Include/token.h header file by vstinner · Pull Request #92652 · python/cpython

Conversation

@vstinner

@vstinner vstinner commented May 11, 2022 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Member

Remove the token.h header file. There was never any public tokenizer
C API. The token.h header file was only designed to be used by Python
internals.

Move Include/token.h to Include/internal/pycore_token.h. Including
this header file now requires that the Py_BUILD_CORE macro is
defined. It no longer checks for the Py_LIMITED_API macro.

Rename functions:

  • PyToken_OneChar() => _PyToken_OneChar()
  • PyToken_TwoChars() => _PyToken_TwoChars()
  • PyToken_ThreeChars() => _PyToken_ThreeChars()

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@vstinner
vstinner requested review from a team, iritkatriel, lysnikolaou and pablogsal as code owners May 11, 2022 00:41
@bedevere-bot bedevere-bot added the awaiting core review label May 11, 2022
@vstinner

vstinner commented May 11, 2022

Copy link
Copy Markdown
Member Author

@pablogsal @lysnikolaou @iritkatriel: Do you see any reason to expose token.h as part of the public C API? Or are you fine with removing this header file from the public C API?

Issue: #92651

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@vstinner
gh-92651: Remove the Include/token.h header file
12fc168
Remove the token.h header file. There was never any public tokenizer
C API. The token.h header file was only designed to be used by Python
internals.

Move Include/token.h to Include/internal/pycore_token.h. Including
this header file now requires that the Py_BUILD_CORE macro is
defined. It no longer checks for the Py_LIMITED_API macro.

Rename functions:

* PyToken_OneChar() => _PyToken_OneChar()
* PyToken_TwoChars() => _PyToken_TwoChars()
* PyToken_ThreeChars() => _PyToken_ThreeChars()
@vstinner

vstinner commented May 11, 2022

Copy link
Copy Markdown
Member Author

These functions and _PyParser_TokenNames symbols are no longer exported.

I tried to no longer export these symbols, but it broke test_peg_generator. I reverted this change.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

serhiy-storchaka
serhiy-storchaka reviewed May 11, 2022
View reviewed changes

@serhiy-storchaka serhiy-storchaka left a comment

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Update also the default value in make_h().

Should PyAPI_FUNC and PyAPI_DATA be used in declarations?

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@vstinner
Update make_h() default value
e6273d2
@vstinner

vstinner commented May 11, 2022

Copy link
Copy Markdown
Member Author

Update also the default value in make_h().

Oh right, I updated my PR.

Should PyAPI_FUNC and PyAPI_DATA be used in declarations?

As I wrote in my previous comment, first, I removed PyAPI_FUNC() and PyAPI_DATA() but it broke test_peg_generator. This test builds C extensions which are linked dynamically.

I added // Symbols exported for test_peg_generator comment to future readers.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@pablogsal

pablogsal commented May 11, 2022

Copy link
Copy Markdown
Member

Do you see any reason to expose token.h as part of the public C API?

No, and is a bad idea to have it as part of the public C API, so if we can move it to the internal heafers folder, that would be great :)

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

pablogsal
pablogsal approved these changes May 11, 2022
View reviewed changes
@bedevere-bot bedevere-bot added awaiting merge and removed awaiting core review labels May 11, 2022
@vstinner

vstinner commented May 11, 2022

Copy link
Copy Markdown
Member Author

This PR doesn't respect PEP 387 deprecation process because:

  • token.h is not included by Python.h and so is part of "the Python C API"
  • it was never possible to get tokens from any public Python C API function: this header file is basically useless

In Python 3.10, Parser/tokenizer.h defines these functions:

extern struct tok_state *PyTokenizer_FromString(const char *, int);
extern struct tok_state *PyTokenizer_FromUTF8(const char *, int);
extern struct tok_state *PyTokenizer_FromFile(FILE *, const char*,
                                              const char *, const char *);
extern void PyTokenizer_Free(struct tok_state *);
extern int PyTokenizer_Get(struct tok_state *, const char **, const char **);

Python is now built with -fvisibility=hidden: functions which are not declared with PyAPI_FUNC() are not exported. So these functions are not exported.

In Python 3.11, these functions were renamed to get a "_Py" prefix. For example, PyTokenizer_FromString() was renamed to _PyTokenizer_FromString().

These functions are not exported and are private since Python 3.11 (_Py prefix).

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@vstinner
vstinner merged commit da5727a into python:main May 11, 2022
@bedevere-bot bedevere-bot removed the awaiting merge label May 11, 2022
@vstinner
vstinner deleted the pycore_token branch May 11, 2022 21:22
@vstinner

vstinner commented May 11, 2022

Copy link
Copy Markdown
Member Author

Merged. Thanks for the reviews!

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@ezio-melotti ezio-melotti mentioned this pull request Nov 14, 2022
Use :cpy-file: throughout the Devguide python/devguide#984
Merged
@ezio-melotti ezio-melotti mentioned this pull request Dec 9, 2022
Fix links to missing CPython files python/devguide#1003
Open
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

@serhiy-storchaka serhiy-storchaka serhiy-storchaka left review comments
@pablogsal pablogsal pablogsal approved these changes
@lysnikolaou lysnikolaou Awaiting requested review from lysnikolaou lysnikolaou is a code owner
@iritkatriel iritkatriel Awaiting requested review from iritkatriel

Uh oh!

There was an error while loading. Please reload this page.

Assignees

No one assigned

Labels

None yet

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

Uh oh!

There was an error while loading. Please reload this page.

4 participants

@vstinner @pablogsal @serhiy-storchaka @bedevere-bot
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.