comparison src/if_py_both.h @ 3638:80ed6aa7b9eb v7.3.579

updated for version 7.3.579 Problem: Can't compile with Python 2.5. Solution: Use PyCObject when Capsules are not available.
author Bram Moolenaar <bram@vim.org>
date Fri, 29 Jun 2012 16:28:28 +0200
parents 0e9b2622c94a
children f02b6ad168ae
comparison
equal deleted inserted replaced
3637:d89729d89569 3638:80ed6aa7b9eb
54 54
55 static struct PyMethodDef OutputMethods[] = { 55 static struct PyMethodDef OutputMethods[] = {
56 /* name, function, calling, documentation */ 56 /* name, function, calling, documentation */
57 {"write", OutputWrite, 1, ""}, 57 {"write", OutputWrite, 1, ""},
58 {"writelines", OutputWritelines, 1, ""}, 58 {"writelines", OutputWritelines, 1, ""},
59 {"flush", OutputFlush, 1, ""}, 59 {"flush", OutputFlush, 1, ""},
60 { NULL, NULL, 0, NULL} 60 { NULL, NULL, 0, NULL}
61 }; 61 };
62 62
63 #define PyErr_SetVim(str) PyErr_SetString(VimError, str) 63 #define PyErr_SetVim(str) PyErr_SetString(VimError, str)
64 64
504 504
505 static struct PyMethodDef VimMethods[] = { 505 static struct PyMethodDef VimMethods[] = {
506 /* name, function, calling, documentation */ 506 /* name, function, calling, documentation */
507 {"command", VimCommand, 1, "Execute a Vim ex-mode command" }, 507 {"command", VimCommand, 1, "Execute a Vim ex-mode command" },
508 {"eval", VimEval, 1, "Evaluate an expression using Vim evaluator" }, 508 {"eval", VimEval, 1, "Evaluate an expression using Vim evaluator" },
509 {"bindeval", VimEvalPy, 1, "Like eval(), but returns objects attached to vim ones"}, 509 {"bindeval", VimEvalPy, 1, "Like eval(), but returns objects attached to vim ones"},
510 {"strwidth", VimStrwidth, 1, "Screen string width, counts <Tab> as having width 1"}, 510 {"strwidth", VimStrwidth, 1, "Screen string width, counts <Tab> as having width 1"},
511 { NULL, NULL, 0, NULL } 511 { NULL, NULL, 0, NULL }
512 }; 512 };
513 513
514 typedef struct 514 typedef struct
515 { 515 {
2430 2430
2431 static int 2431 static int
2432 convert_dl(PyObject *obj, typval_T *tv, 2432 convert_dl(PyObject *obj, typval_T *tv,
2433 pytotvfunc py_to_tv, PyObject *lookupDict) 2433 pytotvfunc py_to_tv, PyObject *lookupDict)
2434 { 2434 {
2435 # ifdef PY_USE_CAPSULE
2435 PyObject *capsule; 2436 PyObject *capsule;
2437 # else
2438 PyCObject *cobject;
2439 # endif
2436 char hexBuf[sizeof(void *) * 2 + 3]; 2440 char hexBuf[sizeof(void *) * 2 + 3];
2437 2441
2438 sprintf(hexBuf, "%p", obj); 2442 sprintf(hexBuf, "%p", obj);
2439 2443
2444 # ifdef PY_USE_CAPSULE
2440 capsule = PyDict_GetItemString(lookupDict, hexBuf); 2445 capsule = PyDict_GetItemString(lookupDict, hexBuf);
2441 if (capsule == NULL) 2446 if (capsule == NULL)
2442 { 2447 # else
2448 cobject = (PyCObject *)PyDict_GetItemString(lookupDict, hexBuf);
2449 if (cobject == NULL)
2450 # endif
2451 {
2452 # ifdef PY_USE_CAPSULE
2443 capsule = PyCapsule_New(tv, NULL, NULL); 2453 capsule = PyCapsule_New(tv, NULL, NULL);
2444 PyDict_SetItemString(lookupDict, hexBuf, capsule); 2454 PyDict_SetItemString(lookupDict, hexBuf, capsule);
2445 Py_DECREF(capsule); 2455 Py_DECREF(capsule);
2456 # else
2457 cobject = PyCObject_FromVoidPtr(tv, NULL);
2458 PyDict_SetItemString(lookupDict, hexBuf, cobject);
2459 Py_DECREF(cobject);
2460 # endif
2446 if (py_to_tv(obj, tv, lookupDict) == -1) 2461 if (py_to_tv(obj, tv, lookupDict) == -1)
2447 { 2462 {
2448 tv->v_type = VAR_UNKNOWN; 2463 tv->v_type = VAR_UNKNOWN;
2449 return -1; 2464 return -1;
2450 } 2465 }
2456 case VAR_LIST: ++tv->vval.v_list->lv_refcount; break; 2471 case VAR_LIST: ++tv->vval.v_list->lv_refcount; break;
2457 } 2472 }
2458 } 2473 }
2459 else 2474 else
2460 { 2475 {
2461 typval_T *v = PyCapsule_GetPointer(capsule, NULL); 2476 typval_T *v;
2477
2478 # ifdef PY_USE_CAPSULE
2479 v = PyCapsule_GetPointer(capsule, NULL);
2480 # else
2481 v = PyCObject_AsVoidPtr(cobject);
2482 # endif
2462 copy_tv(v, tv); 2483 copy_tv(v, tv);
2463 } 2484 }
2464 return 0; 2485 return 0;
2465 } 2486 }
2466 2487