[Pyrex] Re: pyCdk SystemError: Objects/longobject.c:240: bad
argument to internal function
forestiero at qwest.net
forestiero at qwest.net
Fri Mar 4 07:36:00 CET 2005
Greg Ewing wrote:
> Dog Walker wrote:
>
>> linux:/home/dw/pycdk/examples # python calendar.py
>> Traceback (most recent call last):
>> File "calendar.py", line 13, in ?
>> calendar = cdk.Calendar(screen, 0, 0, title, d, m, y, curses.A_BOLD,
>> curses.A_BOLD, curses.A_BOLD, curses.A_REVERSE, curses.A_REVERSE)
>> File "cdk.pyx", line 511, in cdk.Calendar.__new__
>> SystemError: Objects/longobject.c:240: bad argument to internal function
>>
> > I would like to either fix pyrex 0.9.3 or pyCdk's cdk.c.
>
> Find the place in Pyrex/Compiler/PyrexTypes.py which says
>
> class CULongType(CIntType):
>
> to_py_function = "PyLong_FromUnsignedLong"
> from_py_function = "PyLong_AsUnsignedLong"
>
> and change "PyLong_AsUnsignedLong" to "PyInt_AsUnsignedLongMask".
> (Python 2.3 or later is needed for this to work, I think.)
>
>> (Are there older versions of Pyrex which don't raise this error?)
>
> Yes, that particular problem shouldn't happen in 0.9.2 (but
> other things may go wrong with converting Python longs
> >= 0x80000000 to C unsigned longs).
>
> I hope to have a release out soon that will fix this.
>
Thanks! Found the place and made the change.
Unfortunately I have another problem when I try to run the pycdk setup.py to
create the cdk extension from the pyrex generated cdk.c:
----------------[output from python setup.py install]----------------
running install
running build
running build_ext
building 'cdk' extension
gcc -pthread -fno-strict-aliasing -DNDEBUG -D_FILE_OFFSET_BITS=64
-DHAVE_LARGEFILE_SUPPORT -O2 -march=i586 -mcp
u=i686 -fmessage-length=0 -fPIC -Wall -fPIC -I/usr/local/include/cdk -I/usr
include -I/usr/include/python2.3 -c
cdk.c -o build/temp.linux-i686-2.3/cdk.o
cdk.c:66: error: parse error before "CDKBUTTON"
cdk.c:66: warning: no semicolon at end of struct or union
cdk.c:68: error: parse error before '}' token
cdk.c:106: error: parse error before "CDKFSCALE"
[...]
----------------[cdk.c]----------------
1 /* Generated by Pyrex 0.9.3 on Thu Mar 3 21:32:35 2005 */
2
3 #include "Python.h"
4 #include "structmember.h"
5 #ifndef PY_LONG_LONG
6 #define PY_LONG_LONG LONG_LONG
7 #endif
8 #include "stdlib.h"
9 #include "curses.h"
10 #include "py_curses.h"
11 #include "cdk.h"
12
13
14 typedef struct {PyObject **p; char *s;} __Pyx_InternTabEntry;
*proto*/
15 typedef struct {PyObject **p; char *s; long n;}
__Pyx_StringTabEntry; /*proto*/
16 static PyObject *__Pyx_UnpackItem(PyObject *, int); /*proto*/
17 static int __Pyx_EndUnpack(PyObject *, int); /*proto*/
18 static int __Pyx_PrintItem(PyObject *); /*proto*/
19 static int __Pyx_PrintNewline(void); /*proto*/
20 static void __Pyx_Raise(PyObject *type, PyObject *value, PyObject
*tb); /*proto*/
21 static void __Pyx_ReRaise(void); /*proto*/
22 static PyObject *__Pyx_Import(PyObject *name, PyObject
*from_list); /*proto*/
23 static PyObject *__Pyx_GetExcValue(void); /*proto*/
24 static int __Pyx_ArgTypeTest(PyObject *obj, PyTypeObject *type, int
none_allowed, char *name); /*proto*
/
25 static int __Pyx_TypeTest(PyObject *obj, PyTypeObject *type);
*proto*/
26 static int __Pyx_GetStarArgs(PyObject **args, PyObject **kwds, char
*kwd_list[], int nargs, PyObject **
args2, PyObject **kwds2); /*proto*/
27 static void __Pyx_WriteUnraisable(char *name); /*proto*/
28 static void __Pyx_AddTraceback(char *funcname); /*proto*/
29 static PyTypeObject *__Pyx_ImportType(char *module_name, char
*class_name, long size); /*proto*/
30 static int __Pyx_SetVtable(PyObject *dict, void *vtable); /*proto*/
31 static int __Pyx_GetVtable(PyObject *dict, void *vtabptr); /*proto*/
32 static PyObject *__Pyx_CreateClass(PyObject *bases, PyObject *dict,
PyObject *name, char *modname); /*p
roto*/
33 static int __Pyx_InternStrings(__Pyx_InternTabEntry *t); /*proto*/
34 static int __Pyx_InitStrings(__Pyx_StringTabEntry *t); /*proto*/
35 static PyObject *__Pyx_GetName(PyObject *dict, PyObject *name);
*proto*/
36
37 static PyObject *__pyx_m;
38 static PyObject *__pyx_b;
39 static int __pyx_lineno;
40 static char *__pyx_filename;
41 staticforward char **__pyx_f;
42
43 /* Declarations from cdk */
44
45 staticforward PyTypeObject __pyx_type_3cdk_Screen;
46
47 struct __pyx_obj_3cdk_Screen {
48 PyObject_HEAD
49 CDKSCREEN (*ptrScreen);
50 WINDOW (*ptrCursesWin);
51 PyObject *pyCursesWin;
52 };
53
54 staticforward PyTypeObject __pyx_type_3cdk_Alphalist;
55
56 struct __pyx_obj_3cdk_Alphalist {
57 PyObject_HEAD
58 CDKALPHALIST (*ptrWidget);
59 CDKSCREEN (*ptrScreen);
60 };
61
62 staticforward PyTypeObject __pyx_type_3cdk_Button;
63
64 struct __pyx_obj_3cdk_Button {
65 PyObject_HEAD
66 CDKBUTTON (*ptrWidget);
67 CDKSCREEN (*ptrScreen);
68 };
69
70 staticforward PyTypeObject __pyx_type_3cdk_Buttonbox;
71
[...]
----------------[setup.py]----------------
from distutils.core import setup
from distutils.extension import Extension
from Pyrex.Distutils import build_ext
import os
import sys
# change this to where you have cdk unpacked
CDK_HOME='/home/dw/cdk-4.9.11'
if os.name == 'nt':
print 'Sorry - not supported on Windows'
elif os.name == 'posix':
include_dirs = ['/usr/local/include/cdk', '/usr/include']
library_dirs = ['/usr/local/lib', '/usr/lib']
libraries = ['cdk', 'ncurses']
setup(
name = "pyCDK",
description = 'pyCDK: A Python interface to the Curses Development Kit',
author = 'Richard Lawson',
author_email = 'lawson89 at users.sourceforge.net',
url = 'http://sourceforge.net/projects/pycdk/',
ext_modules=[
Extension( "cdk",
["cdk.pyx"],
libraries = libraries,
include_dirs = include_dirs,
library_dirs = library_dirs)
],
cmdclass = {'build_ext': build_ext}
)
More information about the Pyrex
mailing list