Mercurial > vim
comparison src/if_py_both.h @ 4511:ce94a870b59b v7.3.1003
updated for version 7.3.1003
Problem: Python interface does not compile with Python 2.2
Solution: Fix thread issues and True/False. (ZyX)
author | Bram Moolenaar <bram@vim.org> |
---|---|
date | Tue, 21 May 2013 22:23:56 +0200 |
parents | b498224f5b41 |
children | cadb57fbb781 |
comparison
equal
deleted
inserted
replaced
4510:c5406fa95658 | 4511:ce94a870b59b |
---|---|
29 #define INVALID_BUFFER_VALUE ((buf_T *)(-1)) | 29 #define INVALID_BUFFER_VALUE ((buf_T *)(-1)) |
30 #define INVALID_WINDOW_VALUE ((win_T *)(-1)) | 30 #define INVALID_WINDOW_VALUE ((win_T *)(-1)) |
31 #define INVALID_TABPAGE_VALUE ((tabpage_T *)(-1)) | 31 #define INVALID_TABPAGE_VALUE ((tabpage_T *)(-1)) |
32 | 32 |
33 typedef void (*rangeinitializer)(void *); | 33 typedef void (*rangeinitializer)(void *); |
34 typedef void (*runner)(const char *, void *, PyGILState_STATE *); | 34 typedef void (*runner)(const char *, void * |
35 #ifdef PY_CAN_RECURSE | |
36 , PyGILState_STATE * | |
37 #endif | |
38 ); | |
35 | 39 |
36 static int ConvertFromPyObject(PyObject *, typval_T *); | 40 static int ConvertFromPyObject(PyObject *, typval_T *); |
37 static int _ConvertFromPyObject(PyObject *, typval_T *, PyObject *); | 41 static int _ConvertFromPyObject(PyObject *, typval_T *, PyObject *); |
38 static PyObject *WindowNew(win_T *, tabpage_T *); | 42 static PyObject *WindowNew(win_T *, tabpage_T *); |
39 static PyObject *BufferNew (buf_T *); | 43 static PyObject *BufferNew (buf_T *); |
3487 RangeStart = (PyInt) curwin->w_cursor.lnum; | 3491 RangeStart = (PyInt) curwin->w_cursor.lnum; |
3488 RangeEnd = RangeStart; | 3492 RangeEnd = RangeStart; |
3489 } | 3493 } |
3490 | 3494 |
3491 static void | 3495 static void |
3492 run_cmd(const char *cmd, void *arg UNUSED, PyGILState_STATE *pygilstate UNUSED) | 3496 run_cmd(const char *cmd, void *arg UNUSED |
3497 #ifdef PY_CAN_RECURSE | |
3498 , PyGILState_STATE *pygilstate UNUSED | |
3499 #endif | |
3500 ) | |
3493 { | 3501 { |
3494 PyRun_SimpleString((char *) cmd); | 3502 PyRun_SimpleString((char *) cmd); |
3495 } | 3503 } |
3496 | 3504 |
3497 static const char *code_hdr = "def " DOPY_FUNC "(line, linenr):\n "; | 3505 static const char *code_hdr = "def " DOPY_FUNC "(line, linenr):\n "; |
3498 static int code_hdr_len = 30; | 3506 static int code_hdr_len = 30; |
3499 | 3507 |
3500 static void | 3508 static void |
3501 run_do(const char *cmd, void *arg UNUSED, PyGILState_STATE *pygilstate) | 3509 run_do(const char *cmd, void *arg UNUSED |
3510 #ifdef PY_CAN_RECURSE | |
3511 , PyGILState_STATE *pygilstate | |
3512 #endif | |
3513 ) | |
3502 { | 3514 { |
3503 PyInt lnum; | 3515 PyInt lnum; |
3504 size_t len; | 3516 size_t len; |
3505 char *code; | 3517 char *code; |
3506 int status; | 3518 int status; |
3526 } | 3538 } |
3527 | 3539 |
3528 status = 0; | 3540 status = 0; |
3529 pymain = PyImport_AddModule("__main__"); | 3541 pymain = PyImport_AddModule("__main__"); |
3530 pyfunc = PyObject_GetAttrString(pymain, DOPY_FUNC); | 3542 pyfunc = PyObject_GetAttrString(pymain, DOPY_FUNC); |
3543 #ifdef PY_CAN_RECURSE | |
3531 PyGILState_Release(*pygilstate); | 3544 PyGILState_Release(*pygilstate); |
3545 #endif | |
3532 | 3546 |
3533 for (lnum = RangeStart; lnum <= RangeEnd; ++lnum) | 3547 for (lnum = RangeStart; lnum <= RangeEnd; ++lnum) |
3534 { | 3548 { |
3535 PyObject *line, *linenr, *ret; | 3549 PyObject *line, *linenr, *ret; |
3536 | 3550 |
3551 #ifdef PY_CAN_RECURSE | |
3537 *pygilstate = PyGILState_Ensure(); | 3552 *pygilstate = PyGILState_Ensure(); |
3553 #endif | |
3538 if (!(line = GetBufferLine(curbuf, lnum))) | 3554 if (!(line = GetBufferLine(curbuf, lnum))) |
3539 goto err; | 3555 goto err; |
3540 if (!(linenr = PyInt_FromLong((long) lnum))) | 3556 if (!(linenr = PyInt_FromLong((long) lnum))) |
3541 { | 3557 { |
3542 Py_DECREF(line); | 3558 Py_DECREF(line); |
3552 if (SetBufferLine(curbuf, lnum, ret, NULL) == FAIL) | 3568 if (SetBufferLine(curbuf, lnum, ret, NULL) == FAIL) |
3553 goto err; | 3569 goto err; |
3554 | 3570 |
3555 Py_XDECREF(ret); | 3571 Py_XDECREF(ret); |
3556 PythonIO_Flush(); | 3572 PythonIO_Flush(); |
3573 #ifdef PY_CAN_RECURSE | |
3557 PyGILState_Release(*pygilstate); | 3574 PyGILState_Release(*pygilstate); |
3575 #endif | |
3558 } | 3576 } |
3559 goto out; | 3577 goto out; |
3560 err: | 3578 err: |
3579 #ifdef PY_CAN_RECURSE | |
3561 *pygilstate = PyGILState_Ensure(); | 3580 *pygilstate = PyGILState_Ensure(); |
3581 #endif | |
3562 PyErr_PrintEx(0); | 3582 PyErr_PrintEx(0); |
3563 PythonIO_Flush(); | 3583 PythonIO_Flush(); |
3564 status = 1; | 3584 status = 1; |
3565 out: | 3585 out: |
3586 #ifdef PY_CAN_RECURSE | |
3566 if (!status) | 3587 if (!status) |
3567 *pygilstate = PyGILState_Ensure(); | 3588 *pygilstate = PyGILState_Ensure(); |
3589 #endif | |
3568 Py_DECREF(pyfunc); | 3590 Py_DECREF(pyfunc); |
3569 PyObject_SetAttrString(pymain, DOPY_FUNC, NULL); | 3591 PyObject_SetAttrString(pymain, DOPY_FUNC, NULL); |
3570 if (status) | 3592 if (status) |
3571 return; | 3593 return; |
3572 check_cursor(); | 3594 check_cursor(); |
3573 update_curbuf(NOT_VALID); | 3595 update_curbuf(NOT_VALID); |
3574 } | 3596 } |
3575 | 3597 |
3576 static void | 3598 static void |
3577 run_eval(const char *cmd, typval_T *rettv, PyGILState_STATE *pygilstate UNUSED) | 3599 run_eval(const char *cmd, typval_T *rettv |
3600 #ifdef PY_CAN_RECURSE | |
3601 , PyGILState_STATE *pygilstate UNUSED | |
3602 #endif | |
3603 ) | |
3578 { | 3604 { |
3579 PyObject *r; | 3605 PyObject *r; |
3580 | 3606 |
3581 r = PyRun_String((char *) cmd, Py_eval_input, globals, globals); | 3607 r = PyRun_String((char *) cmd, Py_eval_input, globals, globals); |
3582 if (r == NULL) | 3608 if (r == NULL) |