4 From: Bram Moolenaar <Bram@moolenaar.net>
6 Content-Type: text/plain; charset=ISO-8859-1
7 Content-Transfer-Encoding: 8bit
11 Problem: Many warnings when compiling with Python 2.5.
12 Solution: Use ssize_t instead of int for some types. (James Vega)
13 Files: src/if_python.c
16 *** ../vim-7.1.306/src/if_python.c Thu Mar 8 10:20:28 2007
17 --- src/if_python.c Wed May 7 16:55:44 2008
21 # undef HAVE_STDARG_H /* Python's config.h defines it as well. */
24 + #define PY_SSIZE_T_CLEAN
27 #if defined(MACOS) && !defined(MACOS_X_UNIX)
32 # define PySequenceMethods int
35 + #if defined(PY_VERSION_HEX) && PY_VERSION_HEX >= 0x02050000
36 + # define PyInt Py_ssize_t
37 + # define PyInquiry lenfunc
38 + # define PyIntArgFunc ssizeargfunc
39 + # define PyIntIntArgFunc ssizessizeargfunc
40 + # define PyIntObjArgProc ssizeobjargproc
41 + # define PyIntIntObjArgProc ssizessizeobjargproc
44 + # define PyInquiry inquiry
45 + # define PyIntArgFunc intargfunc
46 + # define PyIntIntArgFunc intintargfunc
47 + # define PyIntObjArgProc intobjargproc
48 + # define PyIntIntObjArgProc intintobjargproc
52 #define single_input 256
53 #define file_input 257
56 static long(*dll_PyInt_AsLong)(PyObject *);
57 static PyObject*(*dll_PyInt_FromLong)(long);
58 static PyTypeObject* dll_PyInt_Type;
59 ! static PyObject*(*dll_PyList_GetItem)(PyObject *, int);
60 static PyObject*(*dll_PyList_Append)(PyObject *, PyObject *);
61 ! static PyObject*(*dll_PyList_New)(int size);
62 ! static int(*dll_PyList_SetItem)(PyObject *, int, PyObject *);
63 ! static int(*dll_PyList_Size)(PyObject *);
64 static PyTypeObject* dll_PyList_Type;
65 static PyObject*(*dll_PyImport_ImportModule)(const char *);
66 static PyObject*(*dll_PyDict_New)(void);
68 static long(*dll_PyInt_AsLong)(PyObject *);
69 static PyObject*(*dll_PyInt_FromLong)(long);
70 static PyTypeObject* dll_PyInt_Type;
71 ! static PyObject*(*dll_PyList_GetItem)(PyObject *, PyInt);
72 static PyObject*(*dll_PyList_Append)(PyObject *, PyObject *);
73 ! static PyObject*(*dll_PyList_New)(PyInt size);
74 ! static int(*dll_PyList_SetItem)(PyObject *, PyInt, PyObject *);
75 ! static PyInt(*dll_PyList_Size)(PyObject *);
76 static PyTypeObject* dll_PyList_Type;
77 static PyObject*(*dll_PyImport_ImportModule)(const char *);
78 static PyObject*(*dll_PyDict_New)(void);
81 static int(*dll_PyRun_SimpleString)(char *);
82 static char*(*dll_PyString_AsString)(PyObject *);
83 static PyObject*(*dll_PyString_FromString)(const char *);
84 ! static PyObject*(*dll_PyString_FromStringAndSize)(const char *, int);
85 ! static int(*dll_PyString_Size)(PyObject *);
86 static PyTypeObject* dll_PyString_Type;
87 static int(*dll_PySys_SetObject)(char *, PyObject *);
88 static int(*dll_PySys_SetArgv)(int, char **);
90 static int(*dll_PyRun_SimpleString)(char *);
91 static char*(*dll_PyString_AsString)(PyObject *);
92 static PyObject*(*dll_PyString_FromString)(const char *);
93 ! static PyObject*(*dll_PyString_FromStringAndSize)(const char *, PyInt);
94 ! static PyInt(*dll_PyString_Size)(PyObject *);
95 static PyTypeObject* dll_PyString_Type;
96 static int(*dll_PySys_SetObject)(char *, PyObject *);
97 static int(*dll_PySys_SetArgv)(int, char **);
100 * ----------------------------------------------
102 static PyObject *GetBufferLine(buf_T *, int);
103 ! static PyObject *GetBufferLineList(buf_T *, int, int);
105 static int SetBufferLine(buf_T *, int, PyObject *, int *);
106 ! static int SetBufferLineList(buf_T *, int, int, PyObject *, int *);
107 static int InsertBufferLines(buf_T *, int, PyObject *, int *);
109 static PyObject *LineToString(const char *);
111 * ----------------------------------------------
113 static PyObject *GetBufferLine(buf_T *, int);
114 ! static PyObject *GetBufferLineList(buf_T *, PyInt, PyInt);
116 static int SetBufferLine(buf_T *, int, PyObject *, int *);
117 ! static int SetBufferLineList(buf_T *, PyInt, PyInt, PyObject *, int *);
118 static int InsertBufferLines(buf_T *, int, PyObject *, int *);
120 static PyObject *LineToString(const char *);
124 OutputWritelines(PyObject *self, PyObject *args)
129 int error = ((OutputObject *)(self))->error;
133 OutputWritelines(PyObject *self, PyObject *args)
138 int error = ((OutputObject *)(self))->error;
142 static PyObject *BufferGetattr(PyObject *, char *);
143 static PyObject *BufferRepr(PyObject *);
145 ! static int BufferLength(PyObject *);
146 ! static PyObject *BufferItem(PyObject *, int);
147 ! static PyObject *BufferSlice(PyObject *, int, int);
148 ! static int BufferAssItem(PyObject *, int, PyObject *);
149 ! static int BufferAssSlice(PyObject *, int, int, PyObject *);
151 static PyObject *BufferAppend(PyObject *, PyObject *);
152 static PyObject *BufferMark(PyObject *, PyObject *);
154 static PyObject *BufferGetattr(PyObject *, char *);
155 static PyObject *BufferRepr(PyObject *);
157 ! static PyInt BufferLength(PyObject *);
158 ! static PyObject *BufferItem(PyObject *, PyInt);
159 ! static PyObject *BufferSlice(PyObject *, PyInt, PyInt);
160 ! static PyInt BufferAssItem(PyObject *, PyInt, PyObject *);
161 ! static PyInt BufferAssSlice(PyObject *, PyInt, PyInt, PyObject *);
163 static PyObject *BufferAppend(PyObject *, PyObject *);
164 static PyObject *BufferMark(PyObject *, PyObject *);
167 static PyObject *RangeGetattr(PyObject *, char *);
168 static PyObject *RangeRepr(PyObject *);
170 ! static int RangeLength(PyObject *);
171 ! static PyObject *RangeItem(PyObject *, int);
172 ! static PyObject *RangeSlice(PyObject *, int, int);
173 ! static int RangeAssItem(PyObject *, int, PyObject *);
174 ! static int RangeAssSlice(PyObject *, int, int, PyObject *);
176 static PyObject *RangeAppend(PyObject *, PyObject *);
179 static PyObject *RangeGetattr(PyObject *, char *);
180 static PyObject *RangeRepr(PyObject *);
182 ! static PyInt RangeLength(PyObject *);
183 ! static PyObject *RangeItem(PyObject *, PyInt);
184 ! static PyObject *RangeSlice(PyObject *, PyInt, PyInt);
185 ! static PyInt RangeAssItem(PyObject *, PyInt, PyObject *);
186 ! static PyInt RangeAssSlice(PyObject *, PyInt, PyInt, PyObject *);
188 static PyObject *RangeAppend(PyObject *, PyObject *);
192 * -------------------------------------------
195 ! static int WinListLength(PyObject *);
196 ! static PyObject *WinListItem(PyObject *, int);
198 /* Buffer list type - Implementation functions
199 * -------------------------------------------
202 ! static int BufListLength(PyObject *);
203 ! static PyObject *BufListItem(PyObject *, int);
205 /* Current objects type - Implementation functions
206 * -----------------------------------------------
208 * -------------------------------------------
211 ! static PyInt WinListLength(PyObject *);
212 ! static PyObject *WinListItem(PyObject *, PyInt);
214 /* Buffer list type - Implementation functions
215 * -------------------------------------------
218 ! static PyInt BufListLength(PyObject *);
219 ! static PyObject *BufListItem(PyObject *, PyInt);
221 /* Current objects type - Implementation functions
222 * -----------------------------------------------
226 result = Py_BuildValue("s", buf);
227 PyDict_SetItemString(lookupDict, ptrBuf, result);
230 + else if (our_tv->v_type == VAR_FLOAT)
232 + char buf[NUMBUFLEN];
234 + sprintf(buf, "%f", our_tv->vval.v_float);
235 + result = Py_BuildValue("s", buf);
236 + PyDict_SetItemString(lookupDict, ptrBuf, result);
239 else if (our_tv->v_type == VAR_LIST)
241 list_T *list = our_tv->vval.v_list;
247 ! RBItem(BufferObject *self, int n, int start, int end)
249 if (CheckBuffer(self))
255 ! RBItem(BufferObject *self, PyInt n, int start, int end)
257 if (CheckBuffer(self))
264 ! RBSlice(BufferObject *self, int lo, int hi, int start, int end)
268 if (CheckBuffer(self))
274 ! RBSlice(BufferObject *self, PyInt lo, PyInt hi, int start, int end)
278 if (CheckBuffer(self))
282 return GetBufferLineList(self->buf, lo+start, hi+start);
286 ! RBAssItem(BufferObject *self, int n, PyObject *val, int start, int end, int *new_end)
291 return GetBufferLineList(self->buf, lo+start, hi+start);
295 ! RBAssItem(BufferObject *self, PyInt n, PyObject *val, int start, int end, int *new_end)
305 ! RBAssSlice(BufferObject *self, int lo, int hi, PyObject *val, int start, int end, int *new_end)
314 ! RBAssSlice(BufferObject *self, PyInt lo, PyInt hi, PyObject *val, int start, int end, int *new_end)
322 static PySequenceMethods BufferAsSeq = {
323 ! (inquiry) BufferLength, /* sq_length, len(x) */
324 (binaryfunc) 0, /* BufferConcat, */ /* sq_concat, x+y */
325 ! (intargfunc) 0, /* BufferRepeat, */ /* sq_repeat, x*n */
326 ! (intargfunc) BufferItem, /* sq_item, x[i] */
327 ! (intintargfunc) BufferSlice, /* sq_slice, x[i:j] */
328 ! (intobjargproc) BufferAssItem, /* sq_ass_item, x[i]=v */
329 ! (intintobjargproc) BufferAssSlice, /* sq_ass_slice, x[i:j]=v */
332 static PyTypeObject BufferType = {
336 static PySequenceMethods BufferAsSeq = {
337 ! (PyInquiry) BufferLength, /* sq_length, len(x) */
338 (binaryfunc) 0, /* BufferConcat, */ /* sq_concat, x+y */
339 ! (PyIntArgFunc) 0, /* BufferRepeat, */ /* sq_repeat, x*n */
340 ! (PyIntArgFunc) BufferItem, /* sq_item, x[i] */
341 ! (PyIntIntArgFunc) BufferSlice, /* sq_slice, x[i:j] */
342 ! (PyIntObjArgProc) BufferAssItem, /* sq_ass_item, x[i]=v */
343 ! (PyIntIntObjArgProc) BufferAssSlice, /* sq_ass_slice, x[i:j]=v */
346 static PyTypeObject BufferType = {
353 BufferLength(PyObject *self)
355 /* HOW DO WE SIGNAL AN ERROR FROM THIS FUNCTION? */
361 BufferLength(PyObject *self)
363 /* HOW DO WE SIGNAL AN ERROR FROM THIS FUNCTION? */
369 ! BufferItem(PyObject *self, int n)
371 return RBItem((BufferObject *)(self), n, 1,
372 (int)((BufferObject *)(self))->buf->b_ml.ml_line_count);
376 ! BufferSlice(PyObject *self, int lo, int hi)
378 return RBSlice((BufferObject *)(self), lo, hi, 1,
379 (int)((BufferObject *)(self))->buf->b_ml.ml_line_count);
383 ! BufferAssItem(PyObject *self, int n, PyObject *val)
385 return RBAssItem((BufferObject *)(self), n, val, 1,
386 (int)((BufferObject *)(self))->buf->b_ml.ml_line_count,
391 ! BufferAssSlice(PyObject *self, int lo, int hi, PyObject *val)
393 return RBAssSlice((BufferObject *)(self), lo, hi, val, 1,
394 (int)((BufferObject *)(self))->buf->b_ml.ml_line_count,
399 ! BufferItem(PyObject *self, PyInt n)
401 return RBItem((BufferObject *)(self), n, 1,
402 (int)((BufferObject *)(self))->buf->b_ml.ml_line_count);
406 ! BufferSlice(PyObject *self, PyInt lo, PyInt hi)
408 return RBSlice((BufferObject *)(self), lo, hi, 1,
409 (int)((BufferObject *)(self))->buf->b_ml.ml_line_count);
413 ! BufferAssItem(PyObject *self, PyInt n, PyObject *val)
415 return RBAssItem((BufferObject *)(self), n, val, 1,
416 (int)((BufferObject *)(self))->buf->b_ml.ml_line_count,
421 ! BufferAssSlice(PyObject *self, PyInt lo, PyInt hi, PyObject *val)
423 return RBAssSlice((BufferObject *)(self), lo, hi, val, 1,
424 (int)((BufferObject *)(self))->buf->b_ml.ml_line_count,
429 static PySequenceMethods RangeAsSeq = {
430 ! (inquiry) RangeLength, /* sq_length, len(x) */
431 (binaryfunc) 0, /* RangeConcat, */ /* sq_concat, x+y */
432 ! (intargfunc) 0, /* RangeRepeat, */ /* sq_repeat, x*n */
433 ! (intargfunc) RangeItem, /* sq_item, x[i] */
434 ! (intintargfunc) RangeSlice, /* sq_slice, x[i:j] */
435 ! (intobjargproc) RangeAssItem, /* sq_ass_item, x[i]=v */
436 ! (intintobjargproc) RangeAssSlice, /* sq_ass_slice, x[i:j]=v */
439 static PyTypeObject RangeType = {
443 static PySequenceMethods RangeAsSeq = {
444 ! (PyInquiry) RangeLength, /* sq_length, len(x) */
445 (binaryfunc) 0, /* RangeConcat, */ /* sq_concat, x+y */
446 ! (PyIntArgFunc) 0, /* RangeRepeat, */ /* sq_repeat, x*n */
447 ! (PyIntArgFunc) RangeItem, /* sq_item, x[i] */
448 ! (PyIntIntArgFunc) RangeSlice, /* sq_slice, x[i:j] */
449 ! (PyIntObjArgProc) RangeAssItem, /* sq_ass_item, x[i]=v */
450 ! (PyIntIntObjArgProc) RangeAssSlice, /* sq_ass_slice, x[i:j]=v */
453 static PyTypeObject RangeType = {
460 RangeLength(PyObject *self)
462 /* HOW DO WE SIGNAL AN ERROR FROM THIS FUNCTION? */
468 RangeLength(PyObject *self)
470 /* HOW DO WE SIGNAL AN ERROR FROM THIS FUNCTION? */
476 ! RangeItem(PyObject *self, int n)
478 return RBItem(((RangeObject *)(self))->buf, n,
479 ((RangeObject *)(self))->start,
484 ! RangeItem(PyObject *self, PyInt n)
486 return RBItem(((RangeObject *)(self))->buf, n,
487 ((RangeObject *)(self))->start,
493 ! RangeSlice(PyObject *self, int lo, int hi)
495 return RBSlice(((RangeObject *)(self))->buf, lo, hi,
496 ((RangeObject *)(self))->start,
497 ((RangeObject *)(self))->end);
501 ! RangeAssItem(PyObject *self, int n, PyObject *val)
503 return RBAssItem(((RangeObject *)(self))->buf, n, val,
504 ((RangeObject *)(self))->start,
509 ! RangeSlice(PyObject *self, PyInt lo, PyInt hi)
511 return RBSlice(((RangeObject *)(self))->buf, lo, hi,
512 ((RangeObject *)(self))->start,
513 ((RangeObject *)(self))->end);
517 ! RangeAssItem(PyObject *self, PyInt n, PyObject *val)
519 return RBAssItem(((RangeObject *)(self))->buf, n, val,
520 ((RangeObject *)(self))->start,
523 &((RangeObject *)(self))->end);
527 ! RangeAssSlice(PyObject *self, int lo, int hi, PyObject *val)
529 return RBAssSlice(((RangeObject *)(self))->buf, lo, hi, val,
530 ((RangeObject *)(self))->start,
532 &((RangeObject *)(self))->end);
536 ! RangeAssSlice(PyObject *self, PyInt lo, PyInt hi, PyObject *val)
538 return RBAssSlice(((RangeObject *)(self))->buf, lo, hi, val,
539 ((RangeObject *)(self))->start,
544 static PySequenceMethods BufListAsSeq = {
545 ! (inquiry) BufListLength, /* sq_length, len(x) */
546 (binaryfunc) 0, /* sq_concat, x+y */
547 ! (intargfunc) 0, /* sq_repeat, x*n */
548 ! (intargfunc) BufListItem, /* sq_item, x[i] */
549 ! (intintargfunc) 0, /* sq_slice, x[i:j] */
550 ! (intobjargproc) 0, /* sq_ass_item, x[i]=v */
551 ! (intintobjargproc) 0, /* sq_ass_slice, x[i:j]=v */
554 static PyTypeObject BufListType = {
558 static PySequenceMethods BufListAsSeq = {
559 ! (PyInquiry) BufListLength, /* sq_length, len(x) */
560 (binaryfunc) 0, /* sq_concat, x+y */
561 ! (PyIntArgFunc) 0, /* sq_repeat, x*n */
562 ! (PyIntArgFunc) BufListItem, /* sq_item, x[i] */
563 ! (PyIntIntArgFunc) 0, /* sq_slice, x[i:j] */
564 ! (PyIntObjArgProc) 0, /* sq_ass_item, x[i]=v */
565 ! (PyIntIntObjArgProc) 0, /* sq_ass_slice, x[i:j]=v */
568 static PyTypeObject BufListType = {
575 BufListLength(PyObject *self)
583 BufListLength(PyObject *self)
591 ! BufListItem(PyObject *self, int n)
599 ! BufListItem(PyObject *self, PyInt n)
607 static PySequenceMethods WinListAsSeq = {
608 ! (inquiry) WinListLength, /* sq_length, len(x) */
609 (binaryfunc) 0, /* sq_concat, x+y */
610 ! (intargfunc) 0, /* sq_repeat, x*n */
611 ! (intargfunc) WinListItem, /* sq_item, x[i] */
612 ! (intintargfunc) 0, /* sq_slice, x[i:j] */
613 ! (intobjargproc) 0, /* sq_ass_item, x[i]=v */
614 ! (intintobjargproc) 0, /* sq_ass_slice, x[i:j]=v */
617 static PyTypeObject WinListType = {
621 static PySequenceMethods WinListAsSeq = {
622 ! (PyInquiry) WinListLength, /* sq_length, len(x) */
623 (binaryfunc) 0, /* sq_concat, x+y */
624 ! (PyIntArgFunc) 0, /* sq_repeat, x*n */
625 ! (PyIntArgFunc) WinListItem, /* sq_item, x[i] */
626 ! (PyIntIntArgFunc) 0, /* sq_slice, x[i:j] */
627 ! (PyIntObjArgProc) 0, /* sq_ass_item, x[i]=v */
628 ! (PyIntIntObjArgProc) 0, /* sq_ass_slice, x[i:j]=v */
631 static PyTypeObject WinListType = {
634 /* Window list object - Implementation
638 WinListLength(PyObject *self)
642 /* Window list object - Implementation
646 WinListLength(PyObject *self)
654 ! WinListItem(PyObject *self, int n)
662 ! WinListItem(PyObject *self, PyInt n)
668 * including, hi. The list is returned as a Python list of string objects.
671 ! GetBufferLineList(buf_T *buf, int lo, int hi)
675 PyObject *list = PyList_New(n);
679 * including, hi. The list is returned as a Python list of string objects.
682 ! GetBufferLineList(buf_T *buf, PyInt lo, PyInt hi)
686 PyObject *list = PyList_New(n);
691 * is set to the change in the buffer length.
694 ! SetBufferLineList(buf_T *buf, int lo, int hi, PyObject *list, int *len_change)
696 /* First of all, we check the thpe of the supplied Python object.
697 * There are three cases:
699 * is set to the change in the buffer length.
702 ! SetBufferLineList(buf_T *buf, PyInt lo, PyInt hi, PyObject *list, int *len_change)
704 /* First of all, we check the thpe of the supplied Python object.
705 * There are three cases:
709 if (list == Py_None || list == NULL)
713 buf_T *savebuf = curbuf;
718 if (list == Py_None || list == NULL)
722 buf_T *savebuf = curbuf;
728 else if (PyList_Check(list))
731 ! int new_len = PyList_Size(list);
732 ! int old_len = hi - lo;
733 int extra = 0; /* lines added to text, can be negative */
738 else if (PyList_Check(list))
741 ! PyInt new_len = PyList_Size(list);
742 ! PyInt old_len = hi - lo;
743 int extra = 0; /* lines added to text, can be negative */
749 else if (PyList_Check(lines))
752 ! int size = PyList_Size(lines);
758 else if (PyList_Check(lines))
761 ! PyInt size = PyList_Size(lines);
767 LineToString(const char *str)
770 ! int len = strlen(str);
773 /* Allocate an Python string object, with uninitialised contents. We
775 LineToString(const char *str)
778 ! PyInt len = strlen(str);
781 /* Allocate an Python string object, with uninitialised contents. We
791 if (obj == NULL || !PyString_Check(obj))
800 if (obj == NULL || !PyString_Check(obj))
801 *** ../vim-7.1.306/src/version.c Wed Jun 4 10:59:18 2008
802 --- src/version.c Wed Jun 4 13:31:40 2008
806 { /* Add new patch number below this line */
812 For humans, honesty is a matter of degree. Engineers are always honest in
813 matters of technology and human relationships. That's why it's a good idea
814 to keep engineers away from customers, romantic interests, and other people
815 who can't handle the truth.
816 (Scott Adams - The Dilbert principle)
818 /// Bram Moolenaar -- Bram@Moolenaar.net -- http://www.Moolenaar.net \\\
819 /// sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ \\\
820 \\\ download, build and distribute -- http://www.A-A-P.org ///
821 \\\ help me help AIDS victims -- http://ICCF-Holland.org ///