Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove private _PyCodec_Lookup() function #106269

Merged
merged 1 commit into from
Jun 30, 2023
Merged

Conversation

vstinner
Copy link
Member

Remove the following private functions of the C API:

  • _PyCodecInfo_GetIncrementalDecoder()
  • _PyCodecInfo_GetIncrementalEncoder()
  • _PyCodec_DecodeText()
  • _PyCodec_EncodeText()
  • _PyCodec_Forget()
  • _PyCodec_Lookup()
  • _PyCodec_LookupTextEncoding()

Move these functions to a new pycore_codecs.h internal header file.

These functions are no longer exported.

Remove the following private functions of the C API:

* _PyCodecInfo_GetIncrementalDecoder()
* _PyCodecInfo_GetIncrementalEncoder()
* _PyCodec_DecodeText()
* _PyCodec_EncodeText()
* _PyCodec_Forget()
* _PyCodec_Lookup()
* _PyCodec_LookupTextEncoding()

Move these functions to a new pycore_codecs.h internal header file.

These functions are no longer exported.
@vstinner
Copy link
Member Author

Code search on PyPI top 5,000 projects: only 2 projects mention these functions. In fact, orjson only mentions them in comments, and pyodbc only calls _PyCodec_Lookup() in a code which is only built on Python 2: use PyCodec_KnownEncoding() on Python 3.

PYPI-2023-04-13/orjson-3.8.10.tar.gz: orjson-3.8.10/local_dependencies/pyo3-ffi/src/codecs.rs: // skipped non-limited _PyCodec_Lookup from Include/codecs.h
PYPI-2023-04-13/orjson-3.8.10.tar.gz: orjson-3.8.10/local_dependencies/pyo3-ffi/src/codecs.rs: // skipped non-limited _PyCodec_Forget from Include/codecs.h
PYPI-2023-04-13/orjson-3.8.10.tar.gz: orjson-3.8.10/local_dependencies/pyo3-ffi/src/codecs.rs: // skipped non-limited _PyCodec_LookupTextEncoding from Include/codecs.h
PYPI-2023-04-13/orjson-3.8.10.tar.gz: orjson-3.8.10/local_dependencies/pyo3-ffi/src/codecs.rs: // skipped non-limited _PyCodec_EncodeText from Include/codecs.h
PYPI-2023-04-13/orjson-3.8.10.tar.gz: orjson-3.8.10/local_dependencies/pyo3-ffi/src/codecs.rs: // skipped non-limited _PyCodec_DecodeText from Include/codecs.h
PYPI-2023-04-13/orjson-3.8.10.tar.gz: orjson-3.8.10/local_dependencies/pyo3-ffi/src/codecs.rs: // skipped non-limited _PyCodecInfo_GetIncrementalDecoder from Include/codecs.h
PYPI-2023-04-13/orjson-3.8.10.tar.gz: orjson-3.8.10/local_dependencies/pyo3-ffi/src/codecs.rs: // skipped non-limited _PyCodecInfo_GetIncrementalEncoder from Include/codecs.h
PYPI-2023-04-13/orjson-3.8.10.tar.gz: orjson-3.8.10/include/pyo3/pyo3-ffi/src/codecs.rs: // skipped non-limited _PyCodec_Lookup from Include/codecs.h
PYPI-2023-04-13/orjson-3.8.10.tar.gz: orjson-3.8.10/include/pyo3/pyo3-ffi/src/codecs.rs: // skipped non-limited _PyCodec_Forget from Include/codecs.h
PYPI-2023-04-13/orjson-3.8.10.tar.gz: orjson-3.8.10/include/pyo3/pyo3-ffi/src/codecs.rs: // skipped non-limited _PyCodec_LookupTextEncoding from Include/codecs.h
PYPI-2023-04-13/orjson-3.8.10.tar.gz: orjson-3.8.10/include/pyo3/pyo3-ffi/src/codecs.rs: // skipped non-limited _PyCodec_EncodeText from Include/codecs.h
PYPI-2023-04-13/orjson-3.8.10.tar.gz: orjson-3.8.10/include/pyo3/pyo3-ffi/src/codecs.rs: // skipped non-limited _PyCodec_DecodeText from Include/codecs.h
PYPI-2023-04-13/orjson-3.8.10.tar.gz: orjson-3.8.10/include/pyo3/pyo3-ffi/src/codecs.rs: // skipped non-limited _PyCodecInfo_GetIncrementalDecoder from Include/codecs.h
PYPI-2023-04-13/orjson-3.8.10.tar.gz: orjson-3.8.10/include/pyo3/pyo3-ffi/src/codecs.rs: // skipped non-limited _PyCodecInfo_GetIncrementalEncoder from Include/codecs.h

PYPI-2023-04-13/pyodbc-4.0.38.tar.gz: pyodbc-4.0.38/src/pyodbccompat.cpp: PyObject* codec = _PyCodec_Lookup(encoding);

pyodbc compatibility function:

#if PY_MAJOR_VERSION < 3
int PyCodec_KnownEncoding(const char *encoding)
{
    PyObject* codec = _PyCodec_Lookup(encoding);

    if (codec)
    {
        Py_DECREF(codec);
        return 1;
    }

    PyErr_Clear();
    return 0;
}
#endif

@vstinner vstinner enabled auto-merge (squash) June 30, 2023 09:18
@vstinner vstinner merged commit 0b51463 into python:main Jun 30, 2023
@vstinner vstinner deleted the pycore_codecs branch July 17, 2023 17:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants