initializer is not a constant, error C2099, on compiling a module written in c for python

2024/10/13 11:23:31

i tried to compile a python module called distance, whith c "python setup.py install --with-c" using msvc 2017 on windows 10, i got this error ,

Cdistance / distance.c (647): error C2099: initializer is not aconstant

Cdistance / distance.c (689): error C2099: initializer is not aconstant

Error: command 'C: \ Program Files (x86) \ Microsoft Visual Studio \2017 \ BuildTools \ VC \ Tools \ MSVC \ 14.10.25017 \ bin \ HostX64 \x64 \ cl .exe 'failed with exit status 2

here is the code on line 647

   646 PyTypeObject IFastComp_Type = {647     PyVarObject_HEAD_INIT(&PyType_Type, 0)648  "distance.ifast_comp", /* tp_name */649  sizeof(ItorState), /* tp_basicsize */650  0, /* tp_itemsize */(destructor)itor_dealloc, /* tp_dealloc */0, /* tp_print */0, /* tp_getattr */0, /* tp_setattr */0, /* tp_reserved */0, /* tp_repr */0, /* tp_as_number */0, /* tp_as_sequence */0, /* tp_as_mapping */0, /* tp_hash */0, /* tp_call */0, /* tp_str */0, /* tp_getattro */0, /* tp_setattro */0, /* tp_as_buffer */Py_TPFLAGS_DEFAULT, /* tp_flags */ifast_comp_doc, /* tp_doc */0, /* tp_traverse */0, /* tp_clear */0, /* tp_richcompare */0, /* tp_weaklistoffset */PyObject_SelfIter, /* tp_iter */(iternextfunc)ifastcomp_next, /* tp_iternext */0, /* 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 */0, /* tp_init */PyType_GenericAlloc, /* tp_alloc */ifastcomp_new, /* tp_new */};

in the line 689 is another like strucure,

688  PyTypeObject ILevenshtein_Type = {
689     PyVarObject_HEAD_INIT(&PyType_Type, 0)"distance.ilevenshtein", /* tp_name */sizeof(ItorState), /* tp_basicsize */0, /* tp_itemsize */(destructor)itor_dealloc, /* tp_dealloc */0, /* tp_print */0, /* tp_getattr */0, /* tp_setattr */0, /* tp_reserved */0, /* tp_repr */

both referenced as follow, in the same page

762 if (PyType_Ready(&IFastComp_Type) != 0 || PyType_Ready(&ILevenshtein_Type)!= 0)
763 #if PY_MAJOR_VERSION >= 3return NULL;#elsereturn;#endifPy_INCREF((PyObject *)&IFastComp_Type);Py_INCREF((PyObject *)&ILevenshtein_Type);

thanks

Answer

i have found the solution, by looking to the definition of the structure PyTypeObject PyTypeObject , i have changed yVarObject_HEAD_INIT(&PyType_Type, 0) by PyVarObject_HEAD_INIT(NULL, 0) and it compiles successfully, and i have tried some functions and it works, so the error is caused by &PyType_Type which is a PyObject*, i know that because IFastComp_Type is a globale varailble it should be initialised by a constante, but i still don't know why the author of the module gave &PyType_Type as argument , thank you all for your comments.

https://en.xdnf.cn/q/118089.html

Related Q&A

How can make pandas columns compare check cell?

I have a two file. a.txt has the below data.Zone,Aliase1,Aliase2 VNX7600SPB3_8B3_H1,VNX7600SPB3,8B3_H1 VNX7600SPBA_8B4_H1,VNX7600SPA3,8B4_H1 CX480SPA1_11B3_H1,CX480SPA1,11B3_H1 CX480SPB1_11B4_H1,CX480S…

Flask argument of type _RequestGlobals is not iterable

When I tried to use Flask-WTForms, I followed these steps:from flask_wtf import Form from wtforms import StringField, PasswordField from wtforms.validators import DataRequired, Emailclass EmailPassword…

PumpStreamHandler can capture the process output in realtime

I try to capture a python process output via apache-commons-exec. But it looks like it wont print the output, the output is only displayed after I the python process is finished.Heres my java codeComma…

Freezing a CNN tensorflow model into a .pb file

Im currently experimenting with superresolution using CNNs. To serve my model Ill need to frezze it first, into a .pb file, right? Being a newbie I dont really know how to do that. My model basically …

flattening a list or a tuple in python. Not sure what the error is

def flatten(t):list = []for i in t:if(type(i) != list and type(i) != tuple):list.append(i)else:list.extend(flatten(i))return listHere is the function that Ive written to flatten a list or a tuple that …

Counting word occurrences in csv and determine row appearances

I have a csv file such as the following in one column. The symbols and numbers are only to show that the file does not just contain text. I have two objectives:count the number of occurrences of a wo…

Converting Python 3.6 script to .exe? [duplicate]

This question already has answers here:How can I convert a .py to .exe for Python?(8 answers)Closed 6 years ago.I would like to convert a .py file to an .exe. I am using Python 3.6. I already tried py…

Error while reading csv file in python

I tried to run following programme in ubuntu terminal but I am getting some error. But it is not giving any error in jupyter notebookFile "imsl.py", line 5 SyntaxError: Non-ASCII character \x…

Searching for a USB in Python is returning there is no disk in drive

I wrote up a function in Python that looks for a USB drive based on a key identifier file, however when called upon it returns There is no disk in the drive. Please insert a disk into drive D:/ (which …

Counting phrases in Python using NLTK

I am trying to get a phrase count from a text file but so far I am only able to obtain a word count (see below). I need to extend this logic to count the number of times a two-word phrase appears in th…