Skip to content

gh-100062: Remove error code tables from _ssl and err_names_to_codes #100063

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

Merged
merged 2 commits into from
Apr 3, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 0 additions & 14 deletions Modules/_ssl.c
Original file line number Diff line number Diff line change
Expand Up @@ -5991,9 +5991,6 @@ sslmodule_init_errorcodes(PyObject *module)
state->err_codes_to_names = PyDict_New();
if (state->err_codes_to_names == NULL)
return -1;
state->err_names_to_codes = PyDict_New();
if (state->err_names_to_codes == NULL)
return -1;
state->lib_codes_to_names = PyDict_New();
if (state->lib_codes_to_names == NULL)
return -1;
Expand All @@ -6007,8 +6004,6 @@ sslmodule_init_errorcodes(PyObject *module)
return -1;
if (PyDict_SetItem(state->err_codes_to_names, key, mnemo))
return -1;
if (PyDict_SetItem(state->err_names_to_codes, mnemo, key))
return -1;
Py_DECREF(key);
Py_DECREF(mnemo);
errcode++;
Expand All @@ -6028,13 +6023,6 @@ sslmodule_init_errorcodes(PyObject *module)
libcode++;
}

if (PyModule_AddObjectRef(module, "err_codes_to_names", state->err_codes_to_names))
return -1;
if (PyModule_AddObjectRef(module, "err_names_to_codes", state->err_names_to_codes))
return -1;
if (PyModule_AddObjectRef(module, "lib_codes_to_names", state->lib_codes_to_names))
return -1;

return 0;
}

Expand Down Expand Up @@ -6189,7 +6177,6 @@ sslmodule_traverse(PyObject *m, visitproc visit, void *arg)
Py_VISIT(state->PySSLSyscallErrorObject);
Py_VISIT(state->PySSLEOFErrorObject);
Py_VISIT(state->err_codes_to_names);
Py_VISIT(state->err_names_to_codes);
Py_VISIT(state->lib_codes_to_names);
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'm not very familiar with the CPython API, so I wasn't sure if this should be removed now that the objects are no longer exported. I noticed Sock_Type doesn't seem to be exported, but is traversed, while str_library is also unexported but not traversed.

Copy link
Member

Choose a reason for hiding this comment

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

This is for cycle detection. Sock_Type is a type object, which may contain references that could cause cycles, while I assume str_library is a string, which can never participate in a cycle. So we visit the former but not the latter.

Py_VISIT(state->Sock_Type);

Expand All @@ -6214,7 +6201,6 @@ sslmodule_clear(PyObject *m)
Py_CLEAR(state->PySSLSyscallErrorObject);
Py_CLEAR(state->PySSLEOFErrorObject);
Py_CLEAR(state->err_codes_to_names);
Py_CLEAR(state->err_names_to_codes);
Py_CLEAR(state->lib_codes_to_names);
Py_CLEAR(state->Sock_Type);
Py_CLEAR(state->str_library);
Expand Down
1 change: 0 additions & 1 deletion Modules/_ssl.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ typedef struct {
PyObject *PySSLEOFErrorObject;
/* Error mappings */
PyObject *err_codes_to_names;
PyObject *err_names_to_codes;
PyObject *lib_codes_to_names;
/* socket type from module CAPI */
PyTypeObject *Sock_Type;
Expand Down