comparison src/userfunc.c @ 19013:dd9ab0674eec v8.2.0067

patch 8.2.0067: ERROR_UNKNOWN clashes on some systems Commit: https://github.com/vim/vim/commit/ef140544f6703a7a4c0f6a15f610508ed6b09e89 Author: Bram Moolenaar <Bram@vim.org> Date: Tue Dec 31 21:27:13 2019 +0100 patch 8.2.0067: ERROR_UNKNOWN clashes on some systems Problem: ERROR_UNKNOWN clashes on some systems. Solution: Rename ERROR_ to FCERR_. (Ola S?der, closes https://github.com/vim/vim/issues/5415)
author Bram Moolenaar <Bram@vim.org>
date Tue, 31 Dec 2019 21:30:04 +0100
parents 847cc7932c42
children b920ae62c7b1
comparison
equal deleted inserted replaced
19012:5eb079827641 19013:dd9ab0674eec
547 fname_buf[2] = (int)KE_SNR; 547 fname_buf[2] = (int)KE_SNR;
548 i = 3; 548 i = 3;
549 if (eval_fname_sid(name)) // "<SID>" or "s:" 549 if (eval_fname_sid(name)) // "<SID>" or "s:"
550 { 550 {
551 if (current_sctx.sc_sid <= 0) 551 if (current_sctx.sc_sid <= 0)
552 *error = ERROR_SCRIPT; 552 *error = FCERR_SCRIPT;
553 else 553 else
554 { 554 {
555 sprintf((char *)fname_buf + 3, "%ld_", 555 sprintf((char *)fname_buf + 3, "%ld_",
556 (long)current_sctx.sc_sid); 556 (long)current_sctx.sc_sid);
557 i = (int)STRLEN(fname_buf); 557 i = (int)STRLEN(fname_buf);
564 } 564 }
565 else 565 else
566 { 566 {
567 fname = alloc(i + STRLEN(name + llen) + 1); 567 fname = alloc(i + STRLEN(name + llen) + 1);
568 if (fname == NULL) 568 if (fname == NULL)
569 *error = ERROR_OTHER; 569 *error = FCERR_OTHER;
570 else 570 else
571 { 571 {
572 *tofree = fname; 572 *tofree = fname;
573 mch_memmove(fname, fname_buf, (size_t)i); 573 mch_memmove(fname, fname_buf, (size_t)i);
574 STRCPY(fname + i, name + llen); 574 STRCPY(fname + i, name + llen);
1480 typval_T *argvars_in, // vars for arguments, must have "argcount" 1480 typval_T *argvars_in, // vars for arguments, must have "argcount"
1481 // PLUS ONE elements! 1481 // PLUS ONE elements!
1482 funcexe_T *funcexe) // more arguments 1482 funcexe_T *funcexe) // more arguments
1483 { 1483 {
1484 int ret = FAIL; 1484 int ret = FAIL;
1485 int error = ERROR_NONE; 1485 int error = FCERR_NONE;
1486 int i; 1486 int i;
1487 ufunc_T *fp; 1487 ufunc_T *fp;
1488 char_u fname_buf[FLEN_FIXED + 1]; 1488 char_u fname_buf[FLEN_FIXED + 1];
1489 char_u *tofree = NULL; 1489 char_u *tofree = NULL;
1490 char_u *fname; 1490 char_u *fname;
1518 // When the function has a partial with a dict and there is a dict 1518 // When the function has a partial with a dict and there is a dict
1519 // argument, use the dict argument. That is backwards compatible. 1519 // argument, use the dict argument. That is backwards compatible.
1520 // When the dict was bound explicitly use the one from the partial. 1520 // When the dict was bound explicitly use the one from the partial.
1521 if (partial->pt_dict != NULL && (selfdict == NULL || !partial->pt_auto)) 1521 if (partial->pt_dict != NULL && (selfdict == NULL || !partial->pt_auto))
1522 selfdict = partial->pt_dict; 1522 selfdict = partial->pt_dict;
1523 if (error == ERROR_NONE && partial->pt_argc > 0) 1523 if (error == FCERR_NONE && partial->pt_argc > 0)
1524 { 1524 {
1525 for (argv_clear = 0; argv_clear < partial->pt_argc; ++argv_clear) 1525 for (argv_clear = 0; argv_clear < partial->pt_argc; ++argv_clear)
1526 { 1526 {
1527 if (argv_clear + argcount_in >= MAX_FUNC_ARGS) 1527 if (argv_clear + argcount_in >= MAX_FUNC_ARGS)
1528 { 1528 {
1529 error = ERROR_TOOMANY; 1529 error = FCERR_TOOMANY;
1530 goto theend; 1530 goto theend;
1531 } 1531 }
1532 copy_tv(&partial->pt_argv[argv_clear], &argv[argv_clear]); 1532 copy_tv(&partial->pt_argv[argv_clear], &argv[argv_clear]);
1533 } 1533 }
1534 for (i = 0; i < argcount_in; ++i) 1534 for (i = 0; i < argcount_in; ++i)
1536 argvars = argv; 1536 argvars = argv;
1537 argcount = partial->pt_argc + argcount_in; 1537 argcount = partial->pt_argc + argcount_in;
1538 } 1538 }
1539 } 1539 }
1540 1540
1541 if (error == ERROR_NONE && funcexe->evaluate) 1541 if (error == FCERR_NONE && funcexe->evaluate)
1542 { 1542 {
1543 char_u *rfname = fname; 1543 char_u *rfname = fname;
1544 1544
1545 // Ignore "g:" before a function name. 1545 // Ignore "g:" before a function name.
1546 if (fname[0] == 'g' && fname[1] == ':') 1546 if (fname[0] == 'g' && fname[1] == ':')
1547 rfname = fname + 2; 1547 rfname = fname + 2;
1548 1548
1549 rettv->v_type = VAR_NUMBER; // default rettv is number zero 1549 rettv->v_type = VAR_NUMBER; // default rettv is number zero
1550 rettv->vval.v_number = 0; 1550 rettv->vval.v_number = 0;
1551 error = ERROR_UNKNOWN; 1551 error = FCERR_UNKNOWN;
1552 1552
1553 if (!builtin_function(rfname, -1)) 1553 if (!builtin_function(rfname, -1))
1554 { 1554 {
1555 /* 1555 /*
1556 * User defined function. 1556 * User defined function.
1575 // loaded a package, search for the function again 1575 // loaded a package, search for the function again
1576 fp = find_func(rfname); 1576 fp = find_func(rfname);
1577 } 1577 }
1578 1578
1579 if (fp != NULL && (fp->uf_flags & FC_DELETED)) 1579 if (fp != NULL && (fp->uf_flags & FC_DELETED))
1580 error = ERROR_DELETED; 1580 error = FCERR_DELETED;
1581 else if (fp != NULL) 1581 else if (fp != NULL)
1582 { 1582 {
1583 if (funcexe->argv_func != NULL) 1583 if (funcexe->argv_func != NULL)
1584 // postponed filling in the arguments, do it now 1584 // postponed filling in the arguments, do it now
1585 argcount = funcexe->argv_func(argcount, argvars, argv_clear, 1585 argcount = funcexe->argv_func(argcount, argvars, argv_clear,
1596 } 1596 }
1597 1597
1598 if (fp->uf_flags & FC_RANGE && funcexe->doesrange != NULL) 1598 if (fp->uf_flags & FC_RANGE && funcexe->doesrange != NULL)
1599 *funcexe->doesrange = TRUE; 1599 *funcexe->doesrange = TRUE;
1600 if (argcount < fp->uf_args.ga_len - fp->uf_def_args.ga_len) 1600 if (argcount < fp->uf_args.ga_len - fp->uf_def_args.ga_len)
1601 error = ERROR_TOOFEW; 1601 error = FCERR_TOOFEW;
1602 else if (!fp->uf_varargs && argcount > fp->uf_args.ga_len) 1602 else if (!fp->uf_varargs && argcount > fp->uf_args.ga_len)
1603 error = ERROR_TOOMANY; 1603 error = FCERR_TOOMANY;
1604 else if ((fp->uf_flags & FC_DICT) && selfdict == NULL) 1604 else if ((fp->uf_flags & FC_DICT) && selfdict == NULL)
1605 error = ERROR_DICT; 1605 error = FCERR_DICT;
1606 else 1606 else
1607 { 1607 {
1608 int did_save_redo = FALSE; 1608 int did_save_redo = FALSE;
1609 save_redo_T save_redo; 1609 save_redo_T save_redo;
1610 1610
1628 // now. 1628 // now.
1629 func_clear_free(fp, FALSE); 1629 func_clear_free(fp, FALSE);
1630 if (did_save_redo) 1630 if (did_save_redo)
1631 restoreRedobuff(&save_redo); 1631 restoreRedobuff(&save_redo);
1632 restore_search_patterns(); 1632 restore_search_patterns();
1633 error = ERROR_NONE; 1633 error = FCERR_NONE;
1634 } 1634 }
1635 } 1635 }
1636 } 1636 }
1637 else if (funcexe->basetv != NULL) 1637 else if (funcexe->basetv != NULL)
1638 { 1638 {
1660 * emsg()) is normally updated has not been reached yet. We need to 1660 * emsg()) is normally updated has not been reached yet. We need to
1661 * update that flag first to make aborting() reliable. 1661 * update that flag first to make aborting() reliable.
1662 */ 1662 */
1663 update_force_abort(); 1663 update_force_abort();
1664 } 1664 }
1665 if (error == ERROR_NONE) 1665 if (error == FCERR_NONE)
1666 ret = OK; 1666 ret = OK;
1667 1667
1668 theend: 1668 theend:
1669 /* 1669 /*
1670 * Report an error unless the argument evaluation or function call has been 1670 * Report an error unless the argument evaluation or function call has been
1672 */ 1672 */
1673 if (!aborting()) 1673 if (!aborting())
1674 { 1674 {
1675 switch (error) 1675 switch (error)
1676 { 1676 {
1677 case ERROR_UNKNOWN: 1677 case FCERR_UNKNOWN:
1678 emsg_funcname(N_("E117: Unknown function: %s"), name); 1678 emsg_funcname(N_("E117: Unknown function: %s"), name);
1679 break; 1679 break;
1680 case ERROR_NOTMETHOD: 1680 case FCERR_NOTMETHOD:
1681 emsg_funcname( 1681 emsg_funcname(
1682 N_("E276: Cannot use function as a method: %s"), 1682 N_("E276: Cannot use function as a method: %s"),
1683 name); 1683 name);
1684 break; 1684 break;
1685 case ERROR_DELETED: 1685 case FCERR_DELETED:
1686 emsg_funcname(N_("E933: Function was deleted: %s"), name); 1686 emsg_funcname(N_("E933: Function was deleted: %s"), name);
1687 break; 1687 break;
1688 case ERROR_TOOMANY: 1688 case FCERR_TOOMANY:
1689 emsg_funcname((char *)e_toomanyarg, name); 1689 emsg_funcname((char *)e_toomanyarg, name);
1690 break; 1690 break;
1691 case ERROR_TOOFEW: 1691 case FCERR_TOOFEW:
1692 emsg_funcname( 1692 emsg_funcname(
1693 N_("E119: Not enough arguments for function: %s"), 1693 N_("E119: Not enough arguments for function: %s"),
1694 name); 1694 name);
1695 break; 1695 break;
1696 case ERROR_SCRIPT: 1696 case FCERR_SCRIPT:
1697 emsg_funcname( 1697 emsg_funcname(
1698 N_("E120: Using <SID> not in a script context: %s"), 1698 N_("E120: Using <SID> not in a script context: %s"),
1699 name); 1699 name);
1700 break; 1700 break;
1701 case ERROR_DICT: 1701 case FCERR_DICT:
1702 emsg_funcname( 1702 emsg_funcname(
1703 N_("E725: Calling dict function without Dictionary: %s"), 1703 N_("E725: Calling dict function without Dictionary: %s"),
1704 name); 1704 name);
1705 break; 1705 break;
1706 } 1706 }
3845 int 3845 int
3846 set_ref_in_func(char_u *name, ufunc_T *fp_in, int copyID) 3846 set_ref_in_func(char_u *name, ufunc_T *fp_in, int copyID)
3847 { 3847 {
3848 ufunc_T *fp = fp_in; 3848 ufunc_T *fp = fp_in;
3849 funccall_T *fc; 3849 funccall_T *fc;
3850 int error = ERROR_NONE; 3850 int error = FCERR_NONE;
3851 char_u fname_buf[FLEN_FIXED + 1]; 3851 char_u fname_buf[FLEN_FIXED + 1];
3852 char_u *tofree = NULL; 3852 char_u *tofree = NULL;
3853 char_u *fname; 3853 char_u *fname;
3854 int abort = FALSE; 3854 int abort = FALSE;
3855 3855