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

bpo-46920: Remove code made dead long ago with #if 0 #31681

Closed
wants to merge 5 commits into from
Closed
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
43 changes: 2 additions & 41 deletions Modules/_ctypes/_ctypes.c
Original file line number Diff line number Diff line change
Expand Up @@ -1418,49 +1418,10 @@ static PyGetSetDef WCharArray_getsets[] = {
};

/*
The next three functions copied from Python's typeobject.c.
The next function copied from Python's typeobject.c.

They are used to attach methods, members, or getsets to a type *after* it
has been created: Arrays of characters have additional getsets to treat them
as strings.
Arrays of characters have getsets to treat them as strings.
*/
/*
static int
add_methods(PyTypeObject *type, PyMethodDef *meth)
{
PyObject *dict = type->tp_dict;
for (; meth->ml_name != NULL; meth++) {
PyObject *descr;
descr = PyDescr_NewMethod(type, meth);
if (descr == NULL)
return -1;
if (PyDict_SetItemString(dict, meth->ml_name, descr) < 0) {
Py_DECREF(descr);
return -1;
}
Py_DECREF(descr);
}
return 0;
}

static int
add_members(PyTypeObject *type, PyMemberDef *memb)
{
PyObject *dict = type->tp_dict;
for (; memb->name != NULL; memb++) {
PyObject *descr;
descr = PyDescr_NewMember(type, memb);
if (descr == NULL)
return -1;
if (PyDict_SetItemString(dict, memb->name, descr) < 0) {
Py_DECREF(descr);
return -1;
}
Py_DECREF(descr);
}
return 0;
}
*/

static int
add_getset(PyTypeObject *type, PyGetSetDef *gsp)
Expand Down
13 changes: 0 additions & 13 deletions Modules/_elementtree.c
Original file line number Diff line number Diff line change
Expand Up @@ -36,17 +36,6 @@

/* -------------------------------------------------------------------- */

#if 0
static int memory = 0;
#define ALLOC(size, comment)\
do { memory += size; printf("%8d - %s\n", memory, comment); } while (0)
#define RELEASE(size, comment)\
do { memory -= size; printf("%8d - %s\n", memory, comment); } while (0)
#else
#define ALLOC(size, comment)
#define RELEASE(size, comment)
#endif

/* compiler tweaks */
#if defined(_MSC_VER)
#define LOCAL(type) static __inline type __fastcall
Expand Down Expand Up @@ -301,7 +290,6 @@ create_new_element(PyObject* tag, PyObject* attrib)

self->weakreflist = NULL;

ALLOC(sizeof(ElementObject), "create element");
PyObject_GC_Track(self);

if (attrib != NULL && !is_empty_dict(attrib)) {
Expand Down Expand Up @@ -676,7 +664,6 @@ element_dealloc(ElementObject* self)
*/
element_gc_clear(self);

RELEASE(sizeof(ElementObject), "destroy element");
Py_TYPE(self)->tp_free((PyObject *)self);
Py_TRASHCAN_END
}
Expand Down
6 changes: 0 additions & 6 deletions Modules/_tkinter.c
Original file line number Diff line number Diff line change
Expand Up @@ -3440,11 +3440,5 @@ PyInit__tkinter(void)
return NULL;
}

#if 0
/* This was not a good idea; through <Destroy> bindings,
Tcl_Finalize() may invoke Python code but at that point the
interpreter and thread state have already been destroyed! */
Py_AtExit(Tcl_Finalize);
#endif
return m;
}
19 changes: 0 additions & 19 deletions Modules/getaddrinfo.c
Original file line number Diff line number Diff line change
Expand Up @@ -38,25 +38,6 @@
* - PF_UNSPEC case would be handled in getipnodebyname() with the AI_ALL flag.
*/

#if 0
#include <sys/types.h>
#include <sys/param.h>
#include <sys/sysctl.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <arpa/nameser.h>
#include <netdb.h>
#include <resolv.h>
#include <string.h>
#include <stdlib.h>
#include <stddef.h>
#include <ctype.h>
#include <unistd.h>

#include "addrinfo.h"
#endif

#if defined(__KAME__) && defined(ENABLE_IPV6)
# define FAITH
#endif
Expand Down
14 changes: 0 additions & 14 deletions Modules/getnameinfo.c
Original file line number Diff line number Diff line change
Expand Up @@ -34,20 +34,6 @@
* but INRIA implementation returns EAI_xxx defined for getaddrinfo().
*/

#if 0
#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <arpa/nameser.h>
#include <netdb.h>
#include <resolv.h>
#include <string.h>
#include <stddef.h>

#include "addrinfo.h"
#endif

#define SUCCESS 0
#define YES 1
#define NO 0
Expand Down
28 changes: 0 additions & 28 deletions Modules/sre_lib.h
Original file line number Diff line number Diff line change
Expand Up @@ -333,34 +333,6 @@ SRE(count)(SRE_STATE* state, const SRE_CODE* pattern, Py_ssize_t maxcount)
return ptr - (SRE_CHAR*) state->ptr;
}

#if 0 /* not used in this release */
LOCAL(int)
SRE(info)(SRE_STATE* state, const SRE_CODE* pattern)
{
/* check if an SRE_OP_INFO block matches at the current position.
returns the number of SRE_CODE objects to skip if successful, 0
if no match */

const SRE_CHAR* end = (const SRE_CHAR*) state->end;
const SRE_CHAR* ptr = (const SRE_CHAR*) state->ptr;
Py_ssize_t i;

/* check minimal length */
if (pattern[3] && end - ptr < pattern[3])
return 0;

/* check known prefix */
if (pattern[2] & SRE_INFO_PREFIX && pattern[5] > 1) {
/* <length> <skip> <prefix data> <overlap data> */
for (i = 0; i < pattern[5]; i++)
if ((SRE_CODE) ptr[i] != pattern[7 + i])
return 0;
return pattern[0] + 2 * pattern[6];
}
return pattern[0];
}
#endif

/* The macros below should be used to protect recursive SRE(match)()
* calls that *failed* and do *not* return immediately (IOW, those
* that will backtrack). Explaining:
Expand Down
18 changes: 1 addition & 17 deletions Objects/classobject.c
Original file line number Diff line number Diff line change
Expand Up @@ -516,22 +516,6 @@ instancemethod_repr(PyObject *self)
return result;
}

/*
static long
instancemethod_hash(PyObject *self)
{
long x, y;
x = (long)self;
y = PyObject_Hash(PyInstanceMethod_GET_FUNCTION(self));
if (y == -1)
return -1;
x = x ^ y;
if (x == -1)
x = -2;
return x;
}
*/

PyDoc_STRVAR(instancemethod_doc,
"instancemethod(function)\n\
\n\
Expand Down Expand Up @@ -569,7 +553,7 @@ PyTypeObject PyInstanceMethod_Type = {
0, /* tp_as_number */
0, /* tp_as_sequence */
0, /* tp_as_mapping */
0, /*(hashfunc)instancemethod_hash, tp_hash */
0, /* tp_hash */
instancemethod_call, /* tp_call */
0, /* tp_str */
instancemethod_getattro, /* tp_getattro */
Expand Down
13 changes: 0 additions & 13 deletions Objects/unicodeobject.c
Original file line number Diff line number Diff line change
Expand Up @@ -13657,14 +13657,6 @@ unicode_zfill_impl(PyObject *self, Py_ssize_t width)
return u;
}

#if 0
static PyObject *
unicode__decimal2ascii(PyObject *self)
{
return PyUnicode_TransformDecimalAndSpaceToASCII(self);
}
#endif

PyDoc_STRVAR(startswith__doc__,
"S.startswith(prefix[, start[, end]]) -> bool\n\
\n\
Expand Down Expand Up @@ -14250,11 +14242,6 @@ static PyMethodDef unicode_methods[] = {
UNICODE___FORMAT___METHODDEF
UNICODE_MAKETRANS_METHODDEF
UNICODE_SIZEOF_METHODDEF
#if 0
/* These methods are just used for debugging the implementation. */
{"_decimal2ascii", (PyCFunction) unicode__decimal2ascii, METH_NOARGS},
#endif

{"__getnewargs__", unicode_getnewargs, METH_NOARGS},
{NULL, NULL}
};
Expand Down
11 changes: 0 additions & 11 deletions Parser/pegen.c
Original file line number Diff line number Diff line change
Expand Up @@ -37,17 +37,6 @@ _PyPegen_byte_offset_to_character_offset(PyObject *line, Py_ssize_t col_offset)
return size;
}

#if 0
static const char *
token_name(int type)
{
if (0 <= type && type <= N_TOKENS) {
return _PyParser_TokenNames[type];
}
return "<Huh?>";
}
#endif

// Here, mark is the start of the node, while p->mark is the end.
// If node==NULL, they should be the same.
int
Expand Down
10 changes: 0 additions & 10 deletions Parser/pegen.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,8 @@
#include <token.h>
#include <pycore_ast.h>

#if 0
#define PyPARSE_YIELD_IS_KEYWORD 0x0001
#endif

#define PyPARSE_DONT_IMPLY_DEDENT 0x0002

#if 0
#define PyPARSE_WITH_IS_KEYWORD 0x0003
#define PyPARSE_PRINT_IS_FUNCTION 0x0004
#define PyPARSE_UNICODE_LITERALS 0x0008
#endif

#define PyPARSE_IGNORE_COOKIE 0x0010
#define PyPARSE_BARRY_AS_BDFL 0x0020
#define PyPARSE_TYPE_COMMENTS 0x0040
Expand Down
24 changes: 0 additions & 24 deletions Parser/tokenizer.c
Original file line number Diff line number Diff line change
Expand Up @@ -282,30 +282,6 @@ check_bom(int get_char(struct tok_state *),
unget_char(ch1, tok);
return 1;
}
#if 0
/* Disable support for UTF-16 BOMs until a decision
is made whether this needs to be supported. */
} else if (ch1 == 0xFE) {
ch2 = get_char(tok);
if (ch2 != 0xFF) {
unget_char(ch2, tok);
unget_char(ch1, tok);
return 1;
}
if (!set_readline(tok, "utf-16-be"))
return 0;
tok->decoding_state = STATE_NORMAL;
} else if (ch1 == 0xFF) {
ch2 = get_char(tok);
if (ch2 != 0xFE) {
unget_char(ch2, tok);
unget_char(ch1, tok);
return 1;
}
if (!set_readline(tok, "utf-16-le"))
return 0;
tok->decoding_state = STATE_NORMAL;
#endif
} else {
unget_char(ch1, tok);
return 1;
Expand Down
6 changes: 0 additions & 6 deletions Python/ceval.c
Original file line number Diff line number Diff line change
Expand Up @@ -7062,12 +7062,6 @@ PyEval_MergeCompilerFlags(PyCompilerFlags *cf)
result = 1;
cf->cf_flags |= compilerflags;
}
#if 0 /* future keyword */
if (codeflags & CO_GENERATOR_ALLOWED) {
result = 1;
cf->cf_flags |= CO_GENERATOR_ALLOWED;
}
#endif
}
return result;
}
Expand Down
18 changes: 0 additions & 18 deletions Python/formatter_unicode.c
Original file line number Diff line number Diff line change
Expand Up @@ -137,24 +137,6 @@ typedef struct {
Py_UCS4 type;
} InternalFormatSpec;

#if 0
/* Occasionally useful for debugging. Should normally be commented out. */
static void
DEBUG_PRINT_FORMAT_SPEC(InternalFormatSpec *format)
{
printf("internal format spec: fill_char %d\n", format->fill_char);
printf("internal format spec: align %d\n", format->align);
printf("internal format spec: alternate %d\n", format->alternate);
printf("internal format spec: sign %d\n", format->sign);
printf("internal format spec: width %zd\n", format->width);
printf("internal format spec: thousands_separators %d\n",
format->thousands_separators);
printf("internal format spec: precision %zd\n", format->precision);
printf("internal format spec: type %c\n", format->type);
printf("\n");
}
#endif


/*
ptr points to the start of the format_spec, end points just past its end.
Expand Down
21 changes: 0 additions & 21 deletions Python/pylifecycle.c
Original file line number Diff line number Diff line change
Expand Up @@ -1825,25 +1825,6 @@ Py_FinalizeEx(void)
status = -1;
}

/* Collect final garbage. This disposes of cycles created by
* class definitions, for example.
* XXX This is disabled because it caused too many problems. If
* XXX a __del__ or weakref callback triggers here, Python code has
* XXX a hard time running, because even the sys module has been
* XXX cleared out (sys.stdout is gone, sys.excepthook is gone, etc).
* XXX One symptom is a sequence of information-free messages
* XXX coming from threads (if a __del__ or callback is invoked,
* XXX other threads can execute too, and any exception they encounter
* XXX triggers a comedy of errors as subsystem after subsystem
* XXX fails to find what it *expects* to find in sys to help report
* XXX the exception and consequent unexpected failures). I've also
* XXX seen segfaults then, after adding print statements to the
* XXX Python code getting called.
*/
Copy link
Member

Choose a reason for hiding this comment

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

This comment is oudated and must be removed.

#if 0
_PyGC_CollectIfEnabled();
#endif
Copy link
Member

@vstinner vstinner Mar 7, 2022

Choose a reason for hiding this comment

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

I spent significant time to rework how the GC is called. The last call is now in interpreter_clear() of pystate.c.
See: https://pythondev.readthedocs.io/finalization.html


/* Disable tracemalloc after all Python objects have been destroyed,
so it is possible to use tracemalloc in objects destructor. */
_PyTraceMalloc_Fini();
Expand Down Expand Up @@ -2424,7 +2405,6 @@ init_sys_streams(PyThreadState *tstate)
_PySys_SetAttr(&_Py_ID(stdout), std);
Py_DECREF(std);

#if 1 /* Disable this if you have trouble debugging bootstrap stuff */
/* Set sys.stderr, replaces the preliminary stderr */
fd = fileno(stderr);
std = create_stdio(config, iomod, fd, 1, "<stderr>",
Expand Down Expand Up @@ -2455,7 +2435,6 @@ init_sys_streams(PyThreadState *tstate)
goto error;
}
Py_DECREF(std);
#endif

goto done;

Expand Down