comparison src/if_py_both.h @ 3800:15cdcb8ddcfb v7.3.658

updated for version 7.3.658 Problem: NUL bytes truncate strings when converted from Python. Solution: Handle truncation as an error. (ZyX)
author Bram Moolenaar <bram@vim.org>
date Wed, 05 Sep 2012 19:09:11 +0200
parents 73557eda7027
children 5e909c379a1e
comparison
equal deleted inserted replaced
3799:48a53e1b08cd 3800:15cdcb8ddcfb
2528 func_ref(tv->vval.v_string); 2528 func_ref(tv->vval.v_string);
2529 } 2529 }
2530 #if PY_MAJOR_VERSION >= 3 2530 #if PY_MAJOR_VERSION >= 3
2531 else if (PyBytes_Check(obj)) 2531 else if (PyBytes_Check(obj))
2532 { 2532 {
2533 char_u *result = (char_u *) PyBytes_AsString(obj); 2533 char_u *result;
2534 2534
2535 if (PyString_AsStringAndSize(obj, (char **) &result, NULL) == -1)
2536 return -1;
2535 if (result == NULL) 2537 if (result == NULL)
2536 return -1; 2538 return -1;
2537 2539
2538 if (set_string_copy(result, tv) == -1) 2540 if (set_string_copy(result, tv) == -1)
2539 return -1; 2541 return -1;
2547 2549
2548 bytes = PyString_AsBytes(obj); 2550 bytes = PyString_AsBytes(obj);
2549 if (bytes == NULL) 2551 if (bytes == NULL)
2550 return -1; 2552 return -1;
2551 2553
2552 result = (char_u *) PyBytes_AsString(bytes); 2554 if(PyString_AsStringAndSize(bytes, (char **) &result, NULL) == -1)
2555 return -1;
2553 if (result == NULL) 2556 if (result == NULL)
2554 return -1; 2557 return -1;
2555 2558
2556 if (set_string_copy(result, tv) == -1) 2559 if (set_string_copy(result, tv) == -1)
2557 { 2560 {
2570 2573
2571 bytes = PyUnicode_AsEncodedString(obj, (char *)ENC_OPT, NULL); 2574 bytes = PyUnicode_AsEncodedString(obj, (char *)ENC_OPT, NULL);
2572 if (bytes == NULL) 2575 if (bytes == NULL)
2573 return -1; 2576 return -1;
2574 2577
2575 result=(char_u *) PyString_AsString(bytes); 2578 if(PyString_AsStringAndSize(bytes, (char **) &result, NULL) == -1)
2579 return -1;
2576 if (result == NULL) 2580 if (result == NULL)
2577 return -1; 2581 return -1;
2578 2582
2579 if (set_string_copy(result, tv) == -1) 2583 if (set_string_copy(result, tv) == -1)
2580 { 2584 {
2585 2589
2586 tv->v_type = VAR_STRING; 2590 tv->v_type = VAR_STRING;
2587 } 2591 }
2588 else if (PyString_Check(obj)) 2592 else if (PyString_Check(obj))
2589 { 2593 {
2590 char_u *result = (char_u *) PyString_AsString(obj); 2594 char_u *result;
2591 2595
2596 if(PyString_AsStringAndSize(obj, (char **) &result, NULL) == -1)
2597 return -1;
2592 if (result == NULL) 2598 if (result == NULL)
2593 return -1; 2599 return -1;
2594 2600
2595 if (set_string_copy(result, tv) == -1) 2601 if (set_string_copy(result, tv) == -1)
2596 return -1; 2602 return -1;