texinfo-commits
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[no subject]


From: Patrice Dumas
Date: Mon, 27 Mar 2023 12:00:59 -0400 (EDT)

branch: master
commit a829837e16c58f00151243bf95c17d44291ce30d
Author: Patrice Dumas <pertusus@free.fr>
AuthorDate: Mon Mar 27 18:00:50 2023 +0200

    * tp/Texinfo/ParserNonXS.pm (_parse_def),
    tp/Texinfo/XS/parsetexi/def.c (parse_def),
    tp/Texinfo/XS/parsetexi/end_line.c (end_line_def_line): handle
    linemacro without argument, by correct memory initialization, checking
    that there is a last argument and avoiding destroying element if
    it was not initialized.
    
    * tp/Texinfo/ParserNonXS.pm (_parse_def): do not increase results
    index, similar to XS parser.
    
    * tp/Makefile.tres, t/65linemacro.t: add missing_formal_arg and
    no_arguments tests.
---
 ChangeLog                                    |  15 ++
 tp/Makefile.tres                             |   2 +
 tp/Texinfo/ParserNonXS.pm                    |   4 +-
 tp/Texinfo/XS/parsetexi/def.c                |   7 +-
 tp/Texinfo/XS/parsetexi/end_line.c           |   3 +-
 tp/t/65linemacro.t                           |  22 +-
 tp/t/results/linemacro/missing_formal_arg.pl | 146 +++++++++++++
 tp/t/results/linemacro/no_arguments.pl       | 302 +++++++++++++++++++++++++++
 8 files changed, 493 insertions(+), 8 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index da29cb8e21..81963512ce 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,18 @@
+2023-03-27  Patrice Dumas  <pertusus@free.fr>
+
+       * tp/Texinfo/ParserNonXS.pm (_parse_def),
+       tp/Texinfo/XS/parsetexi/def.c (parse_def),
+       tp/Texinfo/XS/parsetexi/end_line.c (end_line_def_line): handle
+       linemacro without argument, by correct memory initialization, checking
+       that there is a last argument and avoiding destroying element if
+       it was not initialized.
+
+       * tp/Texinfo/ParserNonXS.pm (_parse_def): do not increase results
+       index, similar to XS parser.
+
+       * tp/Makefile.tres, t/65linemacro.t: add missing_formal_arg and
+       no_arguments tests.
+
 2023-03-27  Patrice Dumas  <pertusus@free.fr>
 
        * tp/Texinfo/XS/parsetexi/def.c (parse_def): do not increase the
diff --git a/tp/Makefile.tres b/tp/Makefile.tres
index bb9e88b1a7..ad5bb39cf4 100644
--- a/tp/Makefile.tres
+++ b/tp/Makefile.tres
@@ -1209,7 +1209,9 @@ test_files_generated_list = 
$(test_tap_files_generated_list) \
   t/results/linemacro/braces_after_text.pl \
   t/results/linemacro/empty_last_argument.pl \
   t/results/linemacro/last_argument_with_braces.pl \
+  t/results/linemacro/missing_formal_arg.pl \
   t/results/linemacro/newline_and_continuation_in_brace.pl \
+  t/results/linemacro/no_arguments.pl \
   t/results/linemacro/protected_spaces_on_line.pl \
   t/results/linemacro/spaces_after_command_in_call.pl \
   t/results/linemacro/spaces_in_args.pl \
diff --git a/tp/Texinfo/ParserNonXS.pm b/tp/Texinfo/ParserNonXS.pm
index 222185a36d..572a8cf715 100644
--- a/tp/Texinfo/ParserNonXS.pm
+++ b/tp/Texinfo/ParserNonXS.pm
@@ -3105,7 +3105,6 @@ sub _parse_def($$$$)
     if ($element) {
       $result{$args[$i]} = $element;
     } else {
-      $i++;
       last;
     }
   }
@@ -3115,7 +3114,8 @@ sub _parse_def($$$$)
            and $current->{'contents'}->[$contents_idx]->{'type'} eq 'spaces') {
       $contents_idx++;
     }
-    if ($contents_idx < scalar(@{$current->{'contents'}})) {
+    if ($contents_idx < scalar(@{$current->{'contents'}})
+        and $i < scalar(@args)) {
       my $contents_nr = scalar(@{$current->{'contents'}}) - $contents_idx;
       if ($contents_nr == 1) {
         $result{$args[$i]} = $current->{'contents'}->[$contents_idx];
diff --git a/tp/Texinfo/XS/parsetexi/def.c b/tp/Texinfo/XS/parsetexi/def.c
index e3a7bd20b6..1ca3035b9c 100644
--- a/tp/Texinfo/XS/parsetexi/def.c
+++ b/tp/Texinfo/XS/parsetexi/def.c
@@ -399,9 +399,8 @@ parse_def (enum command_id command, ELEMENT *current)
             }
           /* remove one for the rest of the line argument */
           arg_types_nr--;
-
-          result = malloc ((args_number+1) * sizeof (DEF_ARG *));
         }
+      result = malloc ((args_number+1) * sizeof (DEF_ARG *));
     }
   else
     {
@@ -455,7 +454,9 @@ parse_def (enum command_id command, ELEMENT *current)
              && current->contents.list[contents_idx]->type == ET_spaces)
         contents_idx++;
       /* note that element at contents_idx is not collected at that point */
-      if (contents_idx < current->contents.number)
+      /* arguments_list[i] NULL should only happen if there is no
+         argument at all for the linemacro */
+      if (contents_idx < current->contents.number && arguments_list[i])
         {
           DEF_ARG *def_arg = malloc (sizeof (DEF_ARG));
           int contents_nr = current->contents.number - contents_idx;
diff --git a/tp/Texinfo/XS/parsetexi/end_line.c 
b/tp/Texinfo/XS/parsetexi/end_line.c
index deed106d50..d43ef7a6c5 100644
--- a/tp/Texinfo/XS/parsetexi/end_line.c
+++ b/tp/Texinfo/XS/parsetexi/end_line.c
@@ -790,7 +790,8 @@ end_line_def_line (ELEMENT *current)
       register_source_mark (current, macro_source_mark);
       set_input_source_mark (macro_source_mark);
 
-      destroy_element_and_children (macro_args);
+      if (macro_args)
+        destroy_element_and_children (macro_args);
 
       return current;
     }
diff --git a/tp/t/65linemacro.t b/tp/t/65linemacro.t
index c496259520..ba1f6c9f19 100644
--- a/tp/t/65linemacro.t
+++ b/tp/t/65linemacro.t
@@ -13,6 +13,24 @@ my @test_cases = (
 
 @nospace X Y Z
 '],
+['missing_formal_arg',
+'@linemacro mymacro {a, , b}
+\a\ and \b\.
+@end linemacro
+
+@mymacro one two three
+'],
+['no_arguments',
+'@linemacro noarg
+Body.
+@end linemacro
+
+@noarg
+
+@noarg A B
+
+@noarg {in brace}
+'],
 ['empty_last_argument',
 '@defcodeindex BI
 @linemacro defbuiltin {symbol, rest}
@@ -28,7 +46,7 @@ my @test_cases = (
 @defbuiltin foo {{}}
 @end defblock
 '],
-# arguments should 'my foo' 'a last {} arg{ument}'
+# arguments should be 'my foo' 'a last {} arg{ument}'
 # 'my foo' '{} {}'
 # 'my foo' '{second arg} remaining on {line}'
 ['last_argument_with_braces',
@@ -154,7 +172,7 @@ If @var{axis} is not a valid axis of @var{a}.
 @end defblock
 ']
 # TODO add linemacro call in linemacro
-# add recurrsive linemacro call
+# add recursive linemacro call
 # add macro call in linemacro
 );
 
diff --git a/tp/t/results/linemacro/missing_formal_arg.pl 
b/tp/t/results/linemacro/missing_formal_arg.pl
new file mode 100644
index 0000000000..a48a18c2b9
--- /dev/null
+++ b/tp/t/results/linemacro/missing_formal_arg.pl
@@ -0,0 +1,146 @@
+use vars qw(%result_texis %result_texts %result_trees %result_errors 
+   %result_indices %result_sectioning %result_nodes %result_menus
+   %result_floats %result_converted %result_converted_errors 
+   %result_elements %result_directions_text %result_indices_sort_strings);
+
+use utf8;
+
+$result_trees{'missing_formal_arg'} = {
+  'contents' => [
+    {
+      'contents' => [
+        {
+          'args' => [
+            {
+              'text' => 'mymacro',
+              'type' => 'macro_name'
+            },
+            {
+              'text' => 'a',
+              'type' => 'macro_arg'
+            },
+            {
+              'text' => '',
+              'type' => 'macro_arg'
+            },
+            {
+              'text' => 'b',
+              'type' => 'macro_arg'
+            }
+          ],
+          'cmdname' => 'linemacro',
+          'contents' => [
+            {
+              'text' => '\\a\\ and \\b\\.
+',
+              'type' => 'raw'
+            },
+            {
+              'args' => [
+                {
+                  'contents' => [
+                    {
+                      'text' => 'linemacro'
+                    }
+                  ],
+                  'info' => {
+                    'spaces_after_argument' => {
+                      'text' => '
+'
+                    }
+                  },
+                  'type' => 'line_arg'
+                }
+              ],
+              'cmdname' => 'end',
+              'extra' => {
+                'text_arg' => 'linemacro'
+              },
+              'info' => {
+                'spaces_before_argument' => {
+                  'text' => ' '
+                }
+              },
+              'source_info' => {
+                'file_name' => '',
+                'line_nr' => 3,
+                'macro' => ''
+              }
+            }
+          ],
+          'extra' => {
+            'invalid_syntax' => 1
+          },
+          'info' => {
+            'arg_line' => ' mymacro {a, , b}
+'
+          },
+          'source_info' => {
+            'file_name' => '',
+            'line_nr' => 1,
+            'macro' => ''
+          }
+        },
+        {
+          'text' => '
+',
+          'type' => 'empty_line'
+        },
+        {
+          'text' => ' ',
+          'type' => 'spaces_before_paragraph'
+        },
+        {
+          'contents' => [
+            {
+              'text' => 'one two three
+'
+            }
+          ],
+          'type' => 'paragraph'
+        }
+      ],
+      'type' => 'before_node_section'
+    }
+  ],
+  'type' => 'document_root'
+};
+
+$result_texis{'missing_formal_arg'} = '@linemacro mymacro {a, , b}
+\\a\\ and \\b\\.
+@end linemacro
+
+ one two three
+';
+
+
+$result_texts{'missing_formal_arg'} = '
+one two three
+';
+
+$result_errors{'missing_formal_arg'} = [
+  {
+    'error_line' => 'bad or empty @linemacro formal argument: 
+',
+    'file_name' => '',
+    'line_nr' => 1,
+    'macro' => '',
+    'text' => 'bad or empty @linemacro formal argument: ',
+    'type' => 'error'
+  },
+  {
+    'error_line' => 'unknown command `mymacro\'
+',
+    'file_name' => '',
+    'line_nr' => 5,
+    'macro' => '',
+    'text' => 'unknown command `mymacro\'',
+    'type' => 'error'
+  }
+];
+
+
+$result_floats{'missing_formal_arg'} = {};
+
+
+1;
diff --git a/tp/t/results/linemacro/no_arguments.pl 
b/tp/t/results/linemacro/no_arguments.pl
new file mode 100644
index 0000000000..8de6a6e00e
--- /dev/null
+++ b/tp/t/results/linemacro/no_arguments.pl
@@ -0,0 +1,302 @@
+use vars qw(%result_texis %result_texts %result_trees %result_errors 
+   %result_indices %result_sectioning %result_nodes %result_menus
+   %result_floats %result_converted %result_converted_errors 
+   %result_elements %result_directions_text %result_indices_sort_strings);
+
+use utf8;
+
+$result_trees{'no_arguments'} = {
+  'contents' => [
+    {
+      'contents' => [
+        {
+          'args' => [
+            {
+              'text' => 'noarg',
+              'type' => 'macro_name'
+            }
+          ],
+          'cmdname' => 'linemacro',
+          'contents' => [
+            {
+              'text' => 'Body.
+',
+              'type' => 'raw'
+            },
+            {
+              'args' => [
+                {
+                  'contents' => [
+                    {
+                      'text' => 'linemacro'
+                    }
+                  ],
+                  'info' => {
+                    'spaces_after_argument' => {
+                      'text' => '
+'
+                    }
+                  },
+                  'type' => 'line_arg'
+                }
+              ],
+              'cmdname' => 'end',
+              'extra' => {
+                'text_arg' => 'linemacro'
+              },
+              'info' => {
+                'spaces_before_argument' => {
+                  'text' => ' '
+                }
+              },
+              'source_info' => {
+                'file_name' => '',
+                'line_nr' => 3,
+                'macro' => ''
+              }
+            }
+          ],
+          'info' => {
+            'arg_line' => ' noarg
+'
+          },
+          'source_info' => {
+            'file_name' => '',
+            'line_nr' => 1,
+            'macro' => ''
+          }
+        },
+        {
+          'text' => '
+',
+          'type' => 'empty_line'
+        },
+        {
+          'source_marks' => [
+            {
+              'counter' => 1,
+              'element' => {
+                'args' => [
+                  {
+                    'info' => {
+                      'spaces_after_argument' => {
+                        'text' => '
+'
+                      }
+                    },
+                    'type' => 'line_arg'
+                  }
+                ],
+                'extra' => {
+                  'name' => 'noarg'
+                },
+                'source_info' => {
+                  'file_name' => '',
+                  'line_nr' => 5,
+                  'macro' => ''
+                },
+                'type' => 'linemacro_call'
+              },
+              'sourcemark_type' => 'linemacro_expansion',
+              'status' => 'start'
+            }
+          ],
+          'text' => '',
+          'type' => 'empty_line'
+        },
+        {
+          'contents' => [
+            {
+              'source_marks' => [
+                {
+                  'counter' => 1,
+                  'position' => 6,
+                  'sourcemark_type' => 'linemacro_expansion',
+                  'status' => 'end'
+                }
+              ],
+              'text' => 'Body.
+'
+            }
+          ],
+          'type' => 'paragraph'
+        },
+        {
+          'text' => '
+',
+          'type' => 'empty_line'
+        },
+        {
+          'source_marks' => [
+            {
+              'counter' => 2,
+              'element' => {
+                'args' => [
+                  {
+                    'contents' => [
+                      {
+                        'text' => 'A'
+                      },
+                      {
+                        'extra' => {
+                          'def_role' => 'spaces'
+                        },
+                        'text' => ' ',
+                        'type' => 'spaces'
+                      },
+                      {
+                        'text' => 'B'
+                      }
+                    ],
+                    'info' => {
+                      'spaces_after_argument' => {
+                        'text' => '
+'
+                      }
+                    },
+                    'type' => 'line_arg'
+                  }
+                ],
+                'extra' => {
+                  'name' => 'noarg'
+                },
+                'info' => {
+                  'spaces_before_argument' => {
+                    'text' => ' '
+                  }
+                },
+                'source_info' => {
+                  'file_name' => '',
+                  'line_nr' => 7,
+                  'macro' => ''
+                },
+                'type' => 'linemacro_call'
+              },
+              'sourcemark_type' => 'linemacro_expansion',
+              'status' => 'start'
+            }
+          ],
+          'text' => '',
+          'type' => 'empty_line'
+        },
+        {
+          'contents' => [
+            {
+              'source_marks' => [
+                {
+                  'counter' => 2,
+                  'position' => 6,
+                  'sourcemark_type' => 'linemacro_expansion',
+                  'status' => 'end'
+                }
+              ],
+              'text' => 'Body.
+'
+            }
+          ],
+          'type' => 'paragraph'
+        },
+        {
+          'text' => '
+',
+          'type' => 'empty_line'
+        },
+        {
+          'source_marks' => [
+            {
+              'counter' => 3,
+              'element' => {
+                'args' => [
+                  {
+                    'contents' => [
+                      {
+                        'contents' => [
+                          {
+                            'text' => 'in brace'
+                          }
+                        ],
+                        'type' => 'bracketed_arg'
+                      }
+                    ],
+                    'info' => {
+                      'spaces_after_argument' => {
+                        'text' => '
+'
+                      }
+                    },
+                    'type' => 'line_arg'
+                  }
+                ],
+                'extra' => {
+                  'name' => 'noarg'
+                },
+                'info' => {
+                  'spaces_before_argument' => {
+                    'text' => ' '
+                  }
+                },
+                'source_info' => {
+                  'file_name' => '',
+                  'line_nr' => 9,
+                  'macro' => ''
+                },
+                'type' => 'linemacro_call'
+              },
+              'sourcemark_type' => 'linemacro_expansion',
+              'status' => 'start'
+            }
+          ],
+          'text' => '',
+          'type' => 'empty_line'
+        },
+        {
+          'contents' => [
+            {
+              'source_marks' => [
+                {
+                  'counter' => 3,
+                  'position' => 6,
+                  'sourcemark_type' => 'linemacro_expansion',
+                  'status' => 'end'
+                }
+              ],
+              'text' => 'Body.
+'
+            }
+          ],
+          'type' => 'paragraph'
+        }
+      ],
+      'type' => 'before_node_section'
+    }
+  ],
+  'type' => 'document_root'
+};
+
+$result_texis{'no_arguments'} = '@linemacro noarg
+Body.
+@end linemacro
+
+Body.
+
+Body.
+
+Body.
+';
+
+
+$result_texts{'no_arguments'} = '
+Body.
+
+Body.
+
+Body.
+';
+
+$result_errors{'no_arguments'} = [];
+
+
+$result_floats{'no_arguments'} = {};
+
+
+1;



reply via email to

[Prev in Thread] Current Thread [Next in Thread]