bpo-46920: Remove code made dead long ago with #if 0 by arhadthedev · Pull Request #31681 · python/cpython

git grep "#if 0" gives the following occurences of dead code (analyzed with git blame, removed by this commit):

  • added on 27 Apr 2020 by 2b74c83:

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

    Since these constants aren't mentioned anywhere else, I think it's some initial experiment now abandoned.

  • added on 23 Apr 2020 by c5fc156:

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

    token_name is mentioned nowhere in the CPython codebase too.

  • added on 20 Nov 2014 by d600951:

    #if 0
    _PyGC_CollectIfEnabled();
    #endif

    with the following note:

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

    So the call is faulty for seven years with no progress.

  • added on 26 Oct 2013 by 8444ebb:

    #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 Secret Labs' Regular Expression Engine was vendored nine years ago so not used in this release is permanent and can be removed.

  • added on 28 Sep 2011 by d63a3b8:

    #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

    DEBUG_PRINT_FORMAT_SPEC is used nowhere, plus putting a debugger breakpoint onto an interesting InternalFormatSpec is more convenient.

  • added on (already commented out) 11 Dec 2007 by a3534a6:

    /*
    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;
    }
    */
  • added on 27 Aug 2007 by e226b55:

    #if 0
    static PyObject *
    unicode__decimal2ascii(PyObject *self)
    {
    return PyUnicode_TransformDecimalAndSpaceToASCII(self);
    }
    #endif
    #if 0
    /* These methods are just used for debugging the implementation. */
    {"_decimal2ascii", (PyCFunction) unicode__decimal2ascii, METH_NOARGS},
    #endif

    _decimal2ascii is mentioned nowhere else in the CPython codebase.

  • added (already commented out) on 8 Mar 2006 by d4c9320:

    /*
    The next three functions 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.
    */
    /*
    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;
    }
    */
  • added on 7 Dec 2005 by 8c8836b:

    #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

    In addition, ALLOC() and RELEASE() are removed as unconditional no-ops.

  • added on 4 Aug 2002 by 00f1e3f:

    #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

    /* Disable support for UTF-16 BOMs until a decision is made whether this needs to be supported */ - I have every reason to believe that the decision was Never Ever.

  • added on 23 Mar 2002 by c24ea08:

    #if 0 /* future keyword */
    if (codeflags & CO_GENERATOR_ALLOWED) {
    result = 1;
    cf->cf_flags |= CO_GENERATOR_ALLOWED;
    }
    #endif

    The /* future keyword */ is quite overdue already.

  • added on 23 Jun 2001 by 01dfdb3:

    #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 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
  • added on 14 Jul 1998 by 43ff868:

    #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