0

I have downloaded the Python 2.7.1 source code, after extraction issued this command:

D:\sources\Python-2.7.1>gcc -c -I.\Include -I.\PC -I.\Python .\Python\Python-ast.c
.\Python\Python-ast.c:464: error: initializer element is not constant
.\Python\Python-ast.c:464: error: (near initialization for 'AST_type.ob_type')

The code in question:

static PyTypeObject AST_type = {
    PyVarObject_HEAD_INIT(&PyType_Type, 0) //this is line 464
    "_ast.AST",
    sizeof(PyObject),
    0,
    0,                       /* tp_dealloc */
    0,                       /* tp_print */
    0,                       /* tp_getattr */
    0,                       /* tp_setattr */
    0,                       /* tp_compare */
    0,                       /* tp_repr */
    0,                       /* tp_as_number */
    0,                       /* tp_as_sequence */
    0,                       /* tp_as_mapping */
    0,                       /* tp_hash */
    0,                       /* tp_call */
    0,                       /* tp_str */
    PyObject_GenericGetAttr, /* tp_getattro */
    PyObject_GenericSetAttr, /* tp_setattro */
    0,                       /* tp_as_buffer */
    Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /* tp_flags */
    0,                       /* tp_doc */
    0,                       /* tp_traverse */
    0,                       /* tp_clear */
    0,                       /* tp_richcompare */
    0,                       /* tp_weaklistoffset */
    0,                       /* tp_iter */
    0,                       /* tp_iternext */
    ast_type_methods,        /* tp_methods */
    0,                       /* tp_members */
    0,                       /* tp_getset */
    0,                       /* tp_base */
    0,                       /* tp_dict */
    0,                       /* tp_descr_get */
    0,                       /* tp_descr_set */
    0,                       /* tp_dictoffset */
    (initproc)ast_type_init, /* tp_init */
    PyType_GenericAlloc,     /* tp_alloc */
    PyType_GenericNew,       /* tp_new */
    PyObject_Del,            /* tp_free */
};

I am using TDM GCC:

gcc version 4.4.1 (TDM-1 mingw32)

The specified directories contain all the includes needed. Why is this happening? The code in Python-ast.c seems like standard C.

Thanks for the help

1 Answer 1

1

Python on Windows expects to be compiled with MSVC. The #defines and the like are set up for it. They probably look for the macro _WIN32 or something, which is defined by MSVC and (if I remember correctly) by mingw32. Since you're compiling with mingw and not MSVC, that may be part of the problem.

I would also find out where PyVarObject_HEAD_INIT is defined and try to figure out what it puts on that line that can cause the error.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.