santa | 4 Aug 10:31 2011
Picon

Re: Problem with ValueError: <classname> has the wrong size, try recompiling

Hi,

thanks for your answer! I just upgraded to the current version of cython to make sure I have a working cythonize (w/ sudo pip install cython --upgrade). 
cython --version yields Cython version 0.14.1

Recompile all your .pyx files again (you can force this by removing

all your .c files)

Doesn't work when removing all .c, .o and .so files and then directly calling setup.py afterwards; same issue. Manually cythonizing the pyx files first (cython *.pyx) and then calling the old setup works like a charm. :)

or use a setup like
http://wiki.cython.org/enhancements/distutils_preprocessing that
understands interdependencies.

Using the exact setup.py script proposed in your link (with cython 0.14.1), I get the following:
<terminal>
~/bitbucket/c_test >python setup.py build_ext --inplace
Traceback (most recent call last):
  File "setup.py", line 6, in <module>
    ext_modules = cythonize(["*.pyx"]),
  File "/usr/local/lib/python2.7/dist-packages/Cython/Build/Dependencies.py", line 456, in cythonize
    aliases=aliases)
  File "/usr/local/lib/python2.7/dist-packages/Cython/Build/Dependencies.py", line 426, in create_extension_list
    pkg = deps.package(file)
  File "/usr/local/lib/python2.7/dist-packages/Cython/Build/Dependencies.py", line 21, in wrapper
    res = cache[args] = f(self, *args)
  File "/usr/local/lib/python2.7/dist-packages/Cython/Build/Dependencies.py", line 287, in package
    return self.package(dir) + (os.path.basename(dir),)
  File "/usr/local/lib/python2.7/dist-packages/Cython/Build/Dependencies.py", line 21, in wrapper
    res = cache[args] = f(self, *args)
  File "/usr/local/lib/python2.7/dist-packages/Cython/Build/Dependencies.py", line 287, in package
    return self.package(dir) + (os.path.basename(dir),)
... # removed a few hundred repeating lines
  File "/usr/local/lib/python2.7/dist-packages/Cython/Build/Dependencies.py", line 287, in package
    return self.package(dir) + (os.path.basename(dir),)
  File "/usr/local/lib/python2.7/dist-packages/Cython/Build/Dependencies.py", line 21, in wrapper
    res = cache[args] = f(self, *args)
  File "/usr/local/lib/python2.7/dist-packages/Cython/Build/Dependencies.py", line 286, in package
    if os.path.exists(os.path.join(dir, '__init__.py')):
  File "/usr/lib/python2.7/posixpath.py", line 68, in join
    elif path == '' or path.endswith('/'):
RuntimeError: maximum recursion depth exceeded in cmp
</terminal>
 

The long answer:

You have node.pyx, node.pxd, problemreader.pyx. When compiling
problemreader.pyx it looks at node.pxd and uses information about
object struct layouts, etc. to generate the .c file.

ok

If you then
modify node.pxd without re-compiling problemreader.pyx the C-level
layout of your Node class can change rendering it incompatible with
problemreader.c. Cython detects this at runtime (when it can) and
trows this value error.

 I think this would be much easier to understand if I actually modified anything... but the problem occurs on executing the setup script on a version without any c etc. files. Everything is generated, then nothing is changed and the error still occurs. Would be nice to be able to understand this, however I'm happy that I have now one way of creating everything that doesn't fail (manually cythonizing the .pyx files and then calling the old setup). I guess whatever goes wrong with the new setup script deserves a look as well - do you want me to file a bug? [1]

/gerald

[1] I couldn't find any related bug on http://trac.cython.org.

Gmane