diff options
| author | Paul Eggert | 2015-03-23 08:55:25 -0700 |
|---|---|---|
| committer | Paul Eggert | 2015-03-23 08:57:34 -0700 |
| commit | 24960fc72c5a6b7e97a25416ed986ca7054d1260 (patch) | |
| tree | d46affb0a59fc15b0f9c9915e001fd7a65475400 /src/process.c | |
| parent | bad7308e0c7bfe0192ac05d7aea72e1f7bea7b08 (diff) | |
| download | emacs-24960fc72c5a6b7e97a25416ed986ca7054d1260.tar.gz emacs-24960fc72c5a6b7e97a25416ed986ca7054d1260.zip | |
Minor refactoring of new Fmake_process code
* process.c (Fmake_process): Refactor to avoid call to Flength, to
avoid cast to 'char **', and to reduce indenting and reuse of locals.
Diffstat (limited to 'src/process.c')
| -rw-r--r-- | src/process.c | 68 |
1 files changed, 32 insertions, 36 deletions
diff --git a/src/process.c b/src/process.c index 5abe7489d0d..dd61f3008de 100644 --- a/src/process.c +++ b/src/process.c | |||
| @@ -1399,7 +1399,6 @@ usage: (make-process &rest ARGS) */) | |||
| 1399 | (ptrdiff_t nargs, Lisp_Object *args) | 1399 | (ptrdiff_t nargs, Lisp_Object *args) |
| 1400 | { | 1400 | { |
| 1401 | Lisp_Object buffer, name, command, program, proc, contact, current_dir, tem; | 1401 | Lisp_Object buffer, name, command, program, proc, contact, current_dir, tem; |
| 1402 | ptrdiff_t i; | ||
| 1403 | ptrdiff_t count = SPECPDL_INDEX (); | 1402 | ptrdiff_t count = SPECPDL_INDEX (); |
| 1404 | struct gcpro gcpro1; | 1403 | struct gcpro gcpro1; |
| 1405 | USE_SAFE_ALLOCA; | 1404 | USE_SAFE_ALLOCA; |
| @@ -1515,7 +1514,7 @@ usage: (make-process &rest ARGS) */) | |||
| 1515 | ptrdiff_t nargs2 = 3 + XINT (Flength (command)); | 1514 | ptrdiff_t nargs2 = 3 + XINT (Flength (command)); |
| 1516 | Lisp_Object tem2; | 1515 | Lisp_Object tem2; |
| 1517 | SAFE_ALLOCA_LISP (args2, nargs2); | 1516 | SAFE_ALLOCA_LISP (args2, nargs2); |
| 1518 | i = 0; | 1517 | ptrdiff_t i = 0; |
| 1519 | args2[i++] = Qstart_process; | 1518 | args2[i++] = Qstart_process; |
| 1520 | args2[i++] = name; | 1519 | args2[i++] = name; |
| 1521 | args2[i++] = buffer; | 1520 | args2[i++] = buffer; |
| @@ -1547,7 +1546,7 @@ usage: (make-process &rest ARGS) */) | |||
| 1547 | ptrdiff_t nargs2 = 3 + XINT (Flength (command)); | 1546 | ptrdiff_t nargs2 = 3 + XINT (Flength (command)); |
| 1548 | Lisp_Object tem2; | 1547 | Lisp_Object tem2; |
| 1549 | SAFE_ALLOCA_LISP (args2, nargs2); | 1548 | SAFE_ALLOCA_LISP (args2, nargs2); |
| 1550 | i = 0; | 1549 | ptrdiff_t i = 0; |
| 1551 | args2[i++] = Qstart_process; | 1550 | args2[i++] = Qstart_process; |
| 1552 | args2[i++] = name; | 1551 | args2[i++] = name; |
| 1553 | args2[i++] = buffer; | 1552 | args2[i++] = buffer; |
| @@ -1582,8 +1581,6 @@ usage: (make-process &rest ARGS) */) | |||
| 1582 | if (!NILP (program)) | 1581 | if (!NILP (program)) |
| 1583 | { | 1582 | { |
| 1584 | Lisp_Object program_args = XCDR (command); | 1583 | Lisp_Object program_args = XCDR (command); |
| 1585 | unsigned char **new_argv; | ||
| 1586 | ptrdiff_t new_argc; | ||
| 1587 | 1584 | ||
| 1588 | /* If program file name is not absolute, search our path for it. | 1585 | /* If program file name is not absolute, search our path for it. |
| 1589 | Put the name we will really use in TEM. */ | 1586 | Put the name we will really use in TEM. */ |
| @@ -1612,51 +1609,50 @@ usage: (make-process &rest ARGS) */) | |||
| 1612 | /* Remove "/:" from TEM. */ | 1609 | /* Remove "/:" from TEM. */ |
| 1613 | tem = remove_slash_colon (tem); | 1610 | tem = remove_slash_colon (tem); |
| 1614 | 1611 | ||
| 1615 | { | 1612 | Lisp_Object arg_encoding = Qnil; |
| 1616 | Lisp_Object arg_encoding = Qnil, tem2; | 1613 | struct gcpro gcpro1; |
| 1617 | struct gcpro gcpro1; | 1614 | GCPRO1 (tem); |
| 1618 | GCPRO1 (tem); | ||
| 1619 | 1615 | ||
| 1620 | /* Encode the file name and put it in NEW_ARGV. | 1616 | /* Encode the file name and put it in NEW_ARGV. |
| 1621 | That's where the child will use it to execute the program. */ | 1617 | That's where the child will use it to execute the program. */ |
| 1622 | tem = list1 (ENCODE_FILE (tem)); | 1618 | tem = list1 (ENCODE_FILE (tem)); |
| 1619 | ptrdiff_t new_argc = 1; | ||
| 1623 | 1620 | ||
| 1624 | /* Here we encode arguments by the coding system used for sending | 1621 | /* Here we encode arguments by the coding system used for sending |
| 1625 | data to the process. We don't support using different coding | 1622 | data to the process. We don't support using different coding |
| 1626 | systems for encoding arguments and for encoding data sent to the | 1623 | systems for encoding arguments and for encoding data sent to the |
| 1627 | process. */ | 1624 | process. */ |
| 1628 | 1625 | ||
| 1629 | for (tem2 = program_args; CONSP (tem2); tem2 = XCDR (tem2)) | 1626 | for (Lisp_Object tem2 = program_args; CONSP (tem2); tem2 = XCDR (tem2)) |
| 1630 | { | 1627 | { |
| 1631 | tem = Fcons (XCAR (tem2), tem); | 1628 | Lisp_Object arg = XCAR (tem2); |
| 1632 | CHECK_STRING (XCAR (tem)); | 1629 | CHECK_STRING (arg); |
| 1633 | if (STRING_MULTIBYTE (XCAR (tem))) | 1630 | if (STRING_MULTIBYTE (arg)) |
| 1634 | { | 1631 | { |
| 1635 | if (NILP (arg_encoding)) | 1632 | if (NILP (arg_encoding)) |
| 1636 | arg_encoding = (complement_process_encoding_system | 1633 | arg_encoding = (complement_process_encoding_system |
| 1637 | (XPROCESS (proc)->encode_coding_system)); | 1634 | (XPROCESS (proc)->encode_coding_system)); |
| 1638 | XSETCAR (tem, | 1635 | arg = code_convert_string_norecord (arg, arg_encoding, 1); |
| 1639 | code_convert_string_norecord | 1636 | } |
| 1640 | (XCAR (tem), arg_encoding, 1)); | 1637 | tem = Fcons (arg, tem); |
| 1641 | } | 1638 | new_argc++; |
| 1642 | } | 1639 | } |
| 1643 | 1640 | ||
| 1644 | UNGCPRO; | 1641 | UNGCPRO; |
| 1645 | } | ||
| 1646 | 1642 | ||
| 1647 | /* Now that everything is encoded we can collect the strings into | 1643 | /* Now that everything is encoded we can collect the strings into |
| 1648 | NEW_ARGV. */ | 1644 | NEW_ARGV. */ |
| 1649 | new_argc = XINT (Flength (tem)); | 1645 | char **new_argv; |
| 1650 | SAFE_NALLOCA (new_argv, 1, new_argc + 1); | 1646 | SAFE_NALLOCA (new_argv, 1, new_argc + 1); |
| 1651 | new_argv[new_argc] = 0; | 1647 | new_argv[new_argc] = 0; |
| 1652 | 1648 | ||
| 1653 | for (i = new_argc - 1; i >= 0; i--) | 1649 | for (ptrdiff_t i = new_argc - 1; i >= 0; i--) |
| 1654 | { | 1650 | { |
| 1655 | new_argv[i] = SDATA (XCAR (tem)); | 1651 | new_argv[i] = SSDATA (XCAR (tem)); |
| 1656 | tem = XCDR (tem); | 1652 | tem = XCDR (tem); |
| 1657 | } | 1653 | } |
| 1658 | 1654 | ||
| 1659 | create_process (proc, (char **) new_argv, current_dir); | 1655 | create_process (proc, new_argv, current_dir); |
| 1660 | } | 1656 | } |
| 1661 | else | 1657 | else |
| 1662 | create_pty (proc); | 1658 | create_pty (proc); |