Ticket #473 (closed defect: fixed)

Opened 4 years ago

Last modified 4 years ago

cython 0.12 bug for microsoft visual studio 2008 compiler

Reported by: MattBro Owned by: robertwb
Priority: major Milestone: 0.12.1
Component: Code Generation Keywords:
Cc:

Description (last modified by robertwb) (diff)

Certain simple class structures will fail to compile under MS Vis. Studio 2008 under windows, if you turn the profiler on.

The output of the compiler and some embedded text files are shown below:

To install cython I used the technique of pointing PYTHONPATH and path to the cython0.12 directory. I am running 32 bit version of python2.6.4 and numpy.

I can now provide a complete test case (with one caveat) and show the output error. I have two source files, test.pyx and test.pxd. The vsip.h include file can not be redistributed, however it can be downloaded from:

 http://gpu-vsipl.gtri.gatech.edu/builds/gpuvsipl_2009Aug11.zip

To link everything you would need to have an NVIDIA cuda enabled graphics card, drivers and SDK, but the error occurs prior to linking, and during the compilation of the 'successfully' generated source. The code snippet doesn't do anything so I don't care about linking so far. (Until I hit the next problem.)

I am including the sources below


test.pyx :

# cython: profile=True
from __future__ import division
import numpy as np
cimport numpy as np

DTYPE = np.float32
pnorm = 2 * np.pi * 1j
# initialize the vsipl engine
vsip_init(<void *>0)
# create a global random seed state
cdef vsip_randstate *_vrs
# _vrs = vsip_randcreate(0, 4, 0, VSIP_NPRNG)


cpdef DTYPE_t pi = 3.1415926535897932384626433832795

cdef class rmat :

   def __cinit__(self, int r, int c):
       """ Generate a real matrix of r rows and c cols unitialized. """
       cdef vsip_block_f *myb
       cdef int istrue
       cdef np.ndarray[DTYPE_t, ndim=2] carr

text.pxd :

cimport numpy as np
ctypedef np.float32_t DTYPE_t
cdef struct cfloat:
    DTYPE_t r
    DTYPE_t i

cdef struct cdouble:
   double real
   double imag

cdef extern from "vsip.h" :
   int vsip_init(void *)
   ctypedef struct vsip_randstate

   ctypedef unsigned int vsip_length
   ctypedef unsigned int vsip_index

   ctypedef enum vsip_major:
       VSIP_ROW
       VSIP_COL

   ctypedef enum vsip_rng:
       VSIP_PRNG
       VSIP_NPRNG

   struct vsip_block_f
   vsip_randstate *vsip_randcreate ( vsip_index seed, vsip_index numprocs,
vsip_index id, vsip_rng portable)

To compile this in cython I did: compile('test.pyx')

in a python shell, and on the windows command line I did this ugly command, which sets the visual studio 2008 command line environment prior to calling cl.exe. ( I also show the reported error codes when the compile fails)

cmd.exe /c "C:\Program Files (x86)\Microsoft Visual Studio 9.0\VC\vcvarsall.bat"
x86&&   cl.exe /O2 /LD /EHsc /I. /IC:\python2
sip\windows32\gpu_vsip.lib E:\Apps\CUDA\lib\cudart.lib
E:\Apps\CUDA\lib\cufft.lib&&   copy test.dll test.pyd
Setting environment for using Microsoft Visual Studio 2008 x86 tools.
Microsoft (R) 32-bit C/C++ Optimizing Compiler Version 15.00.21022.08 for 80x86
Copyright (C) Microsoft Corporation.  All rights reserved.

test.c
test.c(812) : error C2143: syntax error : missing ';' before 'type'
test.c(812) : error C2275: 'PyFrameObject' : illegal use of this type as an
expression
       C:\python26\include\frameobject.h(47) : see declaration of
'PyFrameObject'
test.c(812) : error C2065: '__pyx_frame' : undeclared identifier
test.c(812) : error C2143: syntax error : missing ';' before 'type'
test.c(812) : error C2065: '__Pyx_use_tracing' : undeclared identifier
test.c(812) : error C2065: '__pyx_frame_code' : undeclared identifier
test.c(812) : warning C4047: 'function' : 'PyCodeObject **' differs in levels
of indirection from 'int *'
test.c(812) : warning C4024: '__Pyx_TraceSetupAndCall' : different types for
formal and actual parameter 1
test.c(812) : error C2065: '__pyx_frame' : undeclared identifier
test.c(812) : warning C4047: 'function' : 'PyFrameObject **' differs in levels
of indirection from 'int *'
test.c(812) : warning C4024: '__Pyx_TraceSetupAndCall' : different types for
formal and actual parameter 2
test.c(854) : error C2065: '__Pyx_use_tracing' : undeclared identifier
test.c(854) : error C2065: '__pyx_frame' : undeclared identifier
test.c(854) : warning C4047: 'function' : '_frame *' differs in levels of
indirection from 'int'
test.c(854) : warning C4024: 'function through pointer' : different types for
formal and actual parameter 2
test.c(854) : error C2065: '__pyx_frame' : undeclared identifier
test.c(854) : error C2065: '__pyx_frame' : undeclared identifier
test.c(854) : error C2065: '__pyx_frame' : undeclared identifier
test.c(890) : error C2143: syntax error : missing ';' before 'type'
test.c(890) : error C2275: 'PyFrameObject' : illegal use of this type as an
expression
       C:\python26\include\frameobject.h(47) : see declaration of
'PyFrameObject'
test.c(890) : error C2065: '__pyx_frame' : undeclared identifier
test.c(890) : error C2143: syntax error : missing ';' before 'type'
test.c(890) : error C2065: '__Pyx_use_tracing' : undeclared identifier
test.c(890) : error C2065: '__pyx_frame_code' : undeclared identifier
test.c(890) : warning C4047: 'function' : 'PyCodeObject **' differs in levels
of indirection from 'int *'
test.c(890) : warning C4024: '__Pyx_TraceSetupAndCall' : different types for
formal and actual parameter 1
test.c(890) : error C2065: '__pyx_frame' : undeclared identifier
test.c(890) : warning C4047: 'function' : 'PyFrameObject **' differs in levels
of indirection from 'int *'
test.c(890) : warning C4024: '__Pyx_TraceSetupAndCall' : different types for
formal and actual parameter 2
test.c(1661) : error C2065: '__Pyx_use_tracing' : undeclared identifier
test.c(1661) : error C2065: '__pyx_frame' : undeclared identifier
test.c(1661) : warning C4047: 'function' : '_frame *' differs in levels of
indirection from 'int'
test.c(1661) : warning C4024: 'function through pointer' : different types for
formal and actual parameter 2

Finally I show the relevant section of test.c


test.c

/* "E:\Projects\MUD\test.pyx":19
* cdef class rmat :
*
*     def __cinit__(self, int r, int c):             #<<<<<<<<<<<<<<
*         """ Generate a real matrix of r rows and c cols unitialized. """
*         cdef vsip_block_f *myb
*/

static int __pyx_pf_4test_4rmat___cinit__(PyObject *__pyx_v_self, PyObject
*__pyx_args, PyObject *__pyx_kwds); /*proto*/
static char __pyx_doc_4test_4rmat___cinit__[] = " Generate a real matrix of r rows
and c cols unitialized. ";
static int __pyx_pf_4test_4rmat___cinit__(PyObject *__pyx_v_self, PyObject
*__pyx_args, PyObject *__pyx_kwds) {
 int __pyx_v_r;
 int __pyx_v_c;
 int __pyx_r;
 static PyObject **__pyx_pyargnames[] = {&__pyx_n_s__r,&__pyx_n_s__c,0};
 __Pyx_RefNannySetupContext("__cinit__");
 __Pyx_TraceCall("__cinit__", __pyx_f[0], 19); /* This is line 812 */
 if (unlikely(__pyx_kwds)) {

Change History

Changed 4 years ago by robertwb

  • description modified (diff)

Changed 4 years ago by robertwb

  • owner changed from somebody to robertwb

test.c(812) : error C2143: syntax error : missing ';' before 'type' is about the most cryptic error I've seen, especially when buried in a messy macro. It might be the case that the variable declarations are made after the executable line

;

(due to no refnanny). Fix at  http://hg.cython.org/cython-devel/rev/3e685896dd7b

Changed 4 years ago by robertwb

To reproduce this bug/verify this fix, one must run a module with the refnanny off and tracing on with MSVC.

Changed 4 years ago by MattBro

As far as I can tell the recent update cython 0.12.1.beta.0 fixes this bug. cython now compiles my rather large and complex .pyx file without error and at least superficially, it appears to work.

Thanks for the quick update.

Changed 4 years ago by robertwb

  • status changed from new to closed
  • resolution set to fixed
Note: See TracTickets for help on using tickets.