summaryrefslogtreecommitdiff
path: root/gobject/tests/genmarshal.py
blob: 1062dfe625c1fa34e294f096aa6fac20bfc5a660 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
#!/usr/bin/python3
# -*- coding: utf-8 -*-
#
# Copyright © 2019 Endless Mobile, Inc.
#
# SPDX-License-Identifier: LGPL-2.1-or-later
#
# This library is free software; you can redistribute it and/or
# modify it under the terms of the GNU Lesser General Public
# License as published by the Free Software Foundation; either
# version 2.1 of the License, or (at your option) any later version.
#
# This library is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
# Lesser General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public
# License along with this library; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
# MA  02110-1301  USA

"""Integration tests for glib-genmarshal utility."""

import collections
import os
import shutil
import subprocess
import sys
import tempfile
from textwrap import dedent
import unittest

import taptestrunner


# Disable line length warnings as wrapping the C code templates would be hard
# flake8: noqa: E501


Result = collections.namedtuple("Result", ("info", "out", "err", "subs"))


class TestGenmarshal(unittest.TestCase):
    """Integration test for running glib-genmarshal.

    This can be run when installed or uninstalled. When uninstalled, it
    requires G_TEST_BUILDDIR and G_TEST_SRCDIR to be set.

    The idea with this test harness is to test the glib-genmarshal utility, its
    handling of command line arguments, its exit statuses, and its handling of
    various marshaller lists. In future we could split the core glib-genmarshal
    parsing and generation code out into a library and unit test that, and
    convert this test to just check command line behaviour.
    """

    # Track the cwd, we want to back out to that to clean up our tempdir
    cwd = ""

    def setUp(self):
        self.timeout_seconds = 10  # seconds per test
        self.tmpdir = tempfile.TemporaryDirectory()
        self.cwd = os.getcwd()
        os.chdir(self.tmpdir.name)
        print("tmpdir:", self.tmpdir.name)
        if "G_TEST_BUILDDIR" in os.environ:
            self.__genmarshal = os.path.join(
                os.environ["G_TEST_BUILDDIR"], "..", "glib-genmarshal"
            )
        else:
            self.__genmarshal = shutil.which("glib-genmarshal")
        print("genmarshal:", self.__genmarshal)

    def tearDown(self):
        os.chdir(self.cwd)
        self.tmpdir.cleanup()

    def runGenmarshal(self, *args):
        argv = [self.__genmarshal]

        # shebang lines are not supported on native
        # Windows consoles
        if os.name == "nt":
            argv.insert(0, sys.executable)

        argv.extend(args)
        print("Running:", argv)

        env = os.environ.copy()
        env["LC_ALL"] = "C.UTF-8"
        print("Environment:", env)

        # We want to ensure consistent line endings...
        info = subprocess.run(
            argv,
            timeout=self.timeout_seconds,
            stdout=subprocess.PIPE,
            stderr=subprocess.PIPE,
            env=env,
            universal_newlines=True,
        )
        info.check_returncode()
        out = info.stdout.strip()
        err = info.stderr.strip()

        # Known substitutions for standard boilerplate
        subs = {
            "standard_top_comment": "This file is generated by glib-genmarshal, do not modify "
            "it. This code is licensed under the same license as the "
            "containing project. Note that it links to GLib, so must "
            "comply with the LGPL linking clauses.",
            "standard_top_pragma": dedent(
                """
                #ifndef __G_CCLOSURE_USER_MARSHAL_MARSHAL_H__
                #define __G_CCLOSURE_USER_MARSHAL_MARSHAL_H__
                """
            ).strip(),
            "standard_bottom_pragma": dedent(
                """
                #endif /* __G_CCLOSURE_USER_MARSHAL_MARSHAL_H__ */
                """
            ).strip(),
            "standard_includes": dedent(
                """
                #include <glib-object.h>
                """
            ).strip(),
            "standard_marshal_peek_defines": dedent(
                """
                #ifdef G_ENABLE_DEBUG
                #define g_marshal_value_peek_boolean(v)  g_value_get_boolean (v)
                #define g_marshal_value_peek_char(v)     g_value_get_schar (v)
                #define g_marshal_value_peek_uchar(v)    g_value_get_uchar (v)
                #define g_marshal_value_peek_int(v)      g_value_get_int (v)
                #define g_marshal_value_peek_uint(v)     g_value_get_uint (v)
                #define g_marshal_value_peek_long(v)     g_value_get_long (v)
                #define g_marshal_value_peek_ulong(v)    g_value_get_ulong (v)
                #define g_marshal_value_peek_int64(v)    g_value_get_int64 (v)
                #define g_marshal_value_peek_uint64(v)   g_value_get_uint64 (v)
                #define g_marshal_value_peek_enum(v)     g_value_get_enum (v)
                #define g_marshal_value_peek_flags(v)    g_value_get_flags (v)
                #define g_marshal_value_peek_float(v)    g_value_get_float (v)
                #define g_marshal_value_peek_double(v)   g_value_get_double (v)
                #define g_marshal_value_peek_string(v)   (char*) g_value_get_string (v)
                #define g_marshal_value_peek_param(v)    g_value_get_param (v)
                #define g_marshal_value_peek_boxed(v)    g_value_get_boxed (v)
                #define g_marshal_value_peek_pointer(v)  g_value_get_pointer (v)
                #define g_marshal_value_peek_object(v)   g_value_get_object (v)
                #define g_marshal_value_peek_variant(v)  g_value_get_variant (v)
                #else /* !G_ENABLE_DEBUG */
                /* WARNING: This code accesses GValues directly, which is UNSUPPORTED API.
                 *          Do not access GValues directly in your code. Instead, use the
                 *          g_value_get_*() functions
                 */
                #define g_marshal_value_peek_boolean(v)  (v)->data[0].v_int
                #define g_marshal_value_peek_char(v)     (v)->data[0].v_int
                #define g_marshal_value_peek_uchar(v)    (v)->data[0].v_uint
                #define g_marshal_value_peek_int(v)      (v)->data[0].v_int
                #define g_marshal_value_peek_uint(v)     (v)->data[0].v_uint
                #define g_marshal_value_peek_long(v)     (v)->data[0].v_long
                #define g_marshal_value_peek_ulong(v)    (v)->data[0].v_ulong
                #define g_marshal_value_peek_int64(v)    (v)->data[0].v_int64
                #define g_marshal_value_peek_uint64(v)   (v)->data[0].v_uint64
                #define g_marshal_value_peek_enum(v)     (v)->data[0].v_long
                #define g_marshal_value_peek_flags(v)    (v)->data[0].v_ulong
                #define g_marshal_value_peek_float(v)    (v)->data[0].v_float
                #define g_marshal_value_peek_double(v)   (v)->data[0].v_double
                #define g_marshal_value_peek_string(v)   (v)->data[0].v_pointer
                #define g_marshal_value_peek_param(v)    (v)->data[0].v_pointer
                #define g_marshal_value_peek_boxed(v)    (v)->data[0].v_pointer
                #define g_marshal_value_peek_pointer(v)  (v)->data[0].v_pointer
                #define g_marshal_value_peek_object(v)   (v)->data[0].v_pointer
                #define g_marshal_value_peek_variant(v)  (v)->data[0].v_pointer
                #endif /* !G_ENABLE_DEBUG */
                """
            ).strip(),
        }

        result = Result(info, out, err, subs)

        print("Output:", result.out)
        return result

    def runGenmarshalWithList(self, list_contents, *args):
        with tempfile.NamedTemporaryFile(
            dir=self.tmpdir.name, suffix=".list", delete=False
        ) as list_file:
            # Write out the list.
            list_file.write(list_contents.encode("utf-8"))
            print(list_file.name + ":", list_contents)
            list_file.flush()

            header_result = self.runGenmarshal(list_file.name, "--header", *args)
            body_result = self.runGenmarshal(list_file.name, "--body", *args)

            header_result.subs["list_path"] = list_file.name
            body_result.subs["list_path"] = list_file.name

            return (header_result, body_result)

    def test_help(self):
        """Test the --help argument."""
        result = self.runGenmarshal("--help")
        self.assertIn("usage: glib-genmarshal", result.out)

    def test_no_args(self):
        """Test running with no arguments at all."""
        result = self.runGenmarshal()
        self.assertEqual("", result.err)
        self.assertEqual("", result.out)

    def test_empty_list(self):
        """Test running with an empty list."""
        (header_result, body_result) = self.runGenmarshalWithList("", "--quiet")

        self.assertEqual("", header_result.err)
        self.assertEqual("", body_result.err)

        self.assertEqual(
            dedent(
                """
            /* {standard_top_comment} */
            {standard_top_pragma}

            {standard_includes}

            G_BEGIN_DECLS


            G_END_DECLS

            {standard_bottom_pragma}
            """
            )
            .strip()
            .format(**header_result.subs),
            header_result.out.strip(),
        )

        self.assertEqual(
            dedent(
                """
            /* {standard_top_comment} */
            {standard_includes}

            {standard_marshal_peek_defines}
            """
            )
            .strip()
            .format(**body_result.subs),
            body_result.out.strip(),
        )

    def test_void_boolean(self):
        """Test running with a basic VOID:BOOLEAN list."""
        (header_result, body_result) = self.runGenmarshalWithList(
            "VOID:BOOLEAN", "--quiet"
        )

        self.assertEqual("", header_result.err)
        self.assertEqual("", body_result.err)

        self.assertEqual(
            dedent(
                """
            /* {standard_top_comment} */
            {standard_top_pragma}

            {standard_includes}

            G_BEGIN_DECLS

            /* VOID:BOOLEAN ({list_path}:1) */
            #define g_cclosure_user_marshal_VOID__BOOLEAN	g_cclosure_marshal_VOID__BOOLEAN


            G_END_DECLS

            {standard_bottom_pragma}
            """
            )
            .strip()
            .format(**header_result.subs),
            header_result.out.strip(),
        )

        self.assertEqual(
            dedent(
                """
            /* {standard_top_comment} */
            {standard_includes}

            {standard_marshal_peek_defines}
            """
            )
            .strip()
            .format(**body_result.subs),
            body_result.out.strip(),
        )

    def test_void_boolean_int64(self):
        """Test running with a non-trivial VOID:BOOLEAN,INT64 list."""
        (header_result, body_result) = self.runGenmarshalWithList(
            "VOID:BOOLEAN,INT64", "--quiet"
        )

        self.assertEqual("", header_result.err)
        self.assertEqual("", body_result.err)

        self.assertEqual(
            dedent(
                """
            /* {standard_top_comment} */
            {standard_top_pragma}

            {standard_includes}

            G_BEGIN_DECLS

            /* VOID:BOOLEAN,INT64 ({list_path}:1) */
            extern
            void g_cclosure_user_marshal_VOID__BOOLEAN_INT64 (GClosure     *closure,
                                                              GValue       *return_value,
                                                              guint         n_param_values,
                                                              const GValue *param_values,
                                                              gpointer      invocation_hint,
                                                              gpointer      marshal_data);


            G_END_DECLS

            {standard_bottom_pragma}
            """
            )
            .strip()
            .format(**header_result.subs),
            header_result.out.strip(),
        )

        self.assertEqual(
            dedent(
                """
            /* {standard_top_comment} */
            {standard_includes}

            {standard_marshal_peek_defines}

            /* VOID:BOOLEAN,INT64 ({list_path}:1) */
            void
            g_cclosure_user_marshal_VOID__BOOLEAN_INT64 (GClosure     *closure,
                                                         GValue       *return_value G_GNUC_UNUSED,
                                                         guint         n_param_values,
                                                         const GValue *param_values,
                                                         gpointer      invocation_hint G_GNUC_UNUSED,
                                                         gpointer      marshal_data)
            {{
              typedef void (*GMarshalFunc_VOID__BOOLEAN_INT64) (gpointer data1,
                                                                gboolean arg1,
                                                                gint64 arg2,
                                                                gpointer data2);
              GCClosure *cc = (GCClosure *) closure;
              gpointer data1, data2;
              GMarshalFunc_VOID__BOOLEAN_INT64 callback;

              g_return_if_fail (n_param_values == 3);

              if (G_CCLOSURE_SWAP_DATA (closure))
                {{
                  data1 = closure->data;
                  data2 = g_value_peek_pointer (param_values + 0);
                }}
              else
                {{
                  data1 = g_value_peek_pointer (param_values + 0);
                  data2 = closure->data;
                }}
              callback = (GMarshalFunc_VOID__BOOLEAN_INT64) (marshal_data ? marshal_data : cc->callback);

              callback (data1,
                        g_marshal_value_peek_boolean (param_values + 1),
                        g_marshal_value_peek_int64 (param_values + 2),
                        data2);
            }}
            """
            )
            .strip()
            .format(**body_result.subs),
            body_result.out.strip(),
        )

    def test_void_variant_nostdinc_valist_marshaller(self):
        """Test running with a basic VOID:VARIANT list, but without the
        standard marshallers, and with valist support enabled. This checks that
        the valist marshaller for VARIANT correctly sinks floating variants.

        See issue #1793.
        """
        (header_result, body_result) = self.runGenmarshalWithList(
            "VOID:VARIANT", "--quiet", "--nostdinc", "--valist-marshaller"
        )

        self.assertEqual("", header_result.err)
        self.assertEqual("", body_result.err)

        self.assertEqual(
            dedent(
                """
            /* {standard_top_comment} */
            {standard_top_pragma}

            G_BEGIN_DECLS

            /* VOID:VARIANT ({list_path}:1) */
            extern
            void g_cclosure_user_marshal_VOID__VARIANT (GClosure     *closure,
                                                        GValue       *return_value,
                                                        guint         n_param_values,
                                                        const GValue *param_values,
                                                        gpointer      invocation_hint,
                                                        gpointer      marshal_data);
            extern
            void g_cclosure_user_marshal_VOID__VARIANTv (GClosure *closure,
                                                         GValue   *return_value,
                                                         gpointer  instance,
                                                         va_list   args,
                                                         gpointer  marshal_data,
                                                         int       n_params,
                                                         GType    *param_types);


            G_END_DECLS

            {standard_bottom_pragma}
            """
            )
            .strip()
            .format(**header_result.subs),
            header_result.out.strip(),
        )

        self.assertEqual(
            dedent(
                """
            /* {standard_top_comment} */
            {standard_marshal_peek_defines}

            /* VOID:VARIANT ({list_path}:1) */
            void
            g_cclosure_user_marshal_VOID__VARIANT (GClosure     *closure,
                                                   GValue       *return_value G_GNUC_UNUSED,
                                                   guint         n_param_values,
                                                   const GValue *param_values,
                                                   gpointer      invocation_hint G_GNUC_UNUSED,
                                                   gpointer      marshal_data)
            {{
              typedef void (*GMarshalFunc_VOID__VARIANT) (gpointer data1,
                                                          gpointer arg1,
                                                          gpointer data2);
              GCClosure *cc = (GCClosure *) closure;
              gpointer data1, data2;
              GMarshalFunc_VOID__VARIANT callback;

              g_return_if_fail (n_param_values == 2);

              if (G_CCLOSURE_SWAP_DATA (closure))
                {{
                  data1 = closure->data;
                  data2 = g_value_peek_pointer (param_values + 0);
                }}
              else
                {{
                  data1 = g_value_peek_pointer (param_values + 0);
                  data2 = closure->data;
                }}
              callback = (GMarshalFunc_VOID__VARIANT) (marshal_data ? marshal_data : cc->callback);

              callback (data1,
                        g_marshal_value_peek_variant (param_values + 1),
                        data2);
            }}

            void
            g_cclosure_user_marshal_VOID__VARIANTv (GClosure *closure,
                                                    GValue   *return_value G_GNUC_UNUSED,
                                                    gpointer  instance,
                                                    va_list   args,
                                                    gpointer  marshal_data,
                                                    int       n_params,
                                                    GType    *param_types)
            {{
              typedef void (*GMarshalFunc_VOID__VARIANT) (gpointer data1,
                                                          gpointer arg1,
                                                          gpointer data2);
              GCClosure *cc = (GCClosure *) closure;
              gpointer data1, data2;
              GMarshalFunc_VOID__VARIANT callback;
              gpointer arg0;
              va_list args_copy;

              va_copy (args_copy, args);
              arg0 = (gpointer) va_arg (args_copy, gpointer);
              if ((param_types[0] & G_SIGNAL_TYPE_STATIC_SCOPE) == 0 && arg0 != NULL)
                arg0 = g_variant_ref_sink (arg0);
              va_end (args_copy);


              if (G_CCLOSURE_SWAP_DATA (closure))
                {{
                  data1 = closure->data;
                  data2 = instance;
                }}
              else
                {{
                  data1 = instance;
                  data2 = closure->data;
                }}
              callback = (GMarshalFunc_VOID__VARIANT) (marshal_data ? marshal_data : cc->callback);

              callback (data1,
                        arg0,
                        data2);
              if ((param_types[0] & G_SIGNAL_TYPE_STATIC_SCOPE) == 0 && arg0 != NULL)
                g_variant_unref (arg0);
            }}
            """
            )
            .strip()
            .format(**body_result.subs),
            body_result.out.strip(),
        )

    def test_void_string_nostdinc(self):
        """Test running with a basic VOID:STRING list, but without the
        standard marshallers, and with valist support enabled. This checks that
        the valist marshaller for STRING correctly skips a string copy if the
        argument is static.

        See issue #1792.
        """
        (header_result, body_result) = self.runGenmarshalWithList(
            "VOID:STRING", "--quiet", "--nostdinc", "--valist-marshaller"
        )

        self.assertEqual("", header_result.err)
        self.assertEqual("", body_result.err)

        self.assertEqual(
            dedent(
                """
            /* {standard_top_comment} */
            {standard_top_pragma}

            G_BEGIN_DECLS

            /* VOID:STRING ({list_path}:1) */
            extern
            void g_cclosure_user_marshal_VOID__STRING (GClosure     *closure,
                                                       GValue       *return_value,
                                                       guint         n_param_values,
                                                       const GValue *param_values,
                                                       gpointer      invocation_hint,
                                                       gpointer      marshal_data);
            extern
            void g_cclosure_user_marshal_VOID__STRINGv (GClosure *closure,
                                                        GValue   *return_value,
                                                        gpointer  instance,
                                                        va_list   args,
                                                        gpointer  marshal_data,
                                                        int       n_params,
                                                        GType    *param_types);


            G_END_DECLS

            {standard_bottom_pragma}
            """
            )
            .strip()
            .format(**header_result.subs),
            header_result.out.strip(),
        )

        self.assertEqual(
            dedent(
                """
            /* {standard_top_comment} */
            {standard_marshal_peek_defines}

            /* VOID:STRING ({list_path}:1) */
            void
            g_cclosure_user_marshal_VOID__STRING (GClosure     *closure,
                                                  GValue       *return_value G_GNUC_UNUSED,
                                                  guint         n_param_values,
                                                  const GValue *param_values,
                                                  gpointer      invocation_hint G_GNUC_UNUSED,
                                                  gpointer      marshal_data)
            {{
              typedef void (*GMarshalFunc_VOID__STRING) (gpointer data1,
                                                         gpointer arg1,
                                                         gpointer data2);
              GCClosure *cc = (GCClosure *) closure;
              gpointer data1, data2;
              GMarshalFunc_VOID__STRING callback;

              g_return_if_fail (n_param_values == 2);

              if (G_CCLOSURE_SWAP_DATA (closure))
                {{
                  data1 = closure->data;
                  data2 = g_value_peek_pointer (param_values + 0);
                }}
              else
                {{
                  data1 = g_value_peek_pointer (param_values + 0);
                  data2 = closure->data;
                }}
              callback = (GMarshalFunc_VOID__STRING) (marshal_data ? marshal_data : cc->callback);

              callback (data1,
                        g_marshal_value_peek_string (param_values + 1),
                        data2);
            }}

            void
            g_cclosure_user_marshal_VOID__STRINGv (GClosure *closure,
                                                   GValue   *return_value G_GNUC_UNUSED,
                                                   gpointer  instance,
                                                   va_list   args,
                                                   gpointer  marshal_data,
                                                   int       n_params,
                                                   GType    *param_types)
            {{
              typedef void (*GMarshalFunc_VOID__STRING) (gpointer data1,
                                                         gpointer arg1,
                                                         gpointer data2);
              GCClosure *cc = (GCClosure *) closure;
              gpointer data1, data2;
              GMarshalFunc_VOID__STRING callback;
              gpointer arg0;
              va_list args_copy;

              va_copy (args_copy, args);
              arg0 = (gpointer) va_arg (args_copy, gpointer);
              if ((param_types[0] & G_SIGNAL_TYPE_STATIC_SCOPE) == 0 && arg0 != NULL)
                arg0 = g_strdup (arg0);
              va_end (args_copy);


              if (G_CCLOSURE_SWAP_DATA (closure))
                {{
                  data1 = closure->data;
                  data2 = instance;
                }}
              else
                {{
                  data1 = instance;
                  data2 = closure->data;
                }}
              callback = (GMarshalFunc_VOID__STRING) (marshal_data ? marshal_data : cc->callback);

              callback (data1,
                        arg0,
                        data2);
              if ((param_types[0] & G_SIGNAL_TYPE_STATIC_SCOPE) == 0 && arg0 != NULL)
                g_free (arg0);
            }}
            """
            )
            .strip()
            .format(**body_result.subs),
            body_result.out.strip(),
        )

    def test_void_param_nostdinc(self):
        """Test running with a basic VOID:PARAM list, but without the
        standard marshallers, and with valist support enabled. This checks that
        the valist marshaller for PARAM correctly skips a param copy if the
        argument is static.

        See issue #1792.
        """
        self.maxDiff = None  # TODO
        (header_result, body_result) = self.runGenmarshalWithList(
            "VOID:PARAM", "--quiet", "--nostdinc", "--valist-marshaller"
        )

        self.assertEqual("", header_result.err)
        self.assertEqual("", body_result.err)

        self.assertEqual(
            dedent(
                """
            /* {standard_top_comment} */
            {standard_top_pragma}

            G_BEGIN_DECLS

            /* VOID:PARAM ({list_path}:1) */
            extern
            void g_cclosure_user_marshal_VOID__PARAM (GClosure     *closure,
                                                      GValue       *return_value,
                                                      guint         n_param_values,
                                                      const GValue *param_values,
                                                      gpointer      invocation_hint,
                                                      gpointer      marshal_data);
            extern
            void g_cclosure_user_marshal_VOID__PARAMv (GClosure *closure,
                                                       GValue   *return_value,
                                                       gpointer  instance,
                                                       va_list   args,
                                                       gpointer  marshal_data,
                                                       int       n_params,
                                                       GType    *param_types);


            G_END_DECLS

            {standard_bottom_pragma}
            """
            )
            .strip()
            .format(**header_result.subs),
            header_result.out.strip(),
        )

        self.assertEqual(
            dedent(
                """
            /* {standard_top_comment} */
            {standard_marshal_peek_defines}

            /* VOID:PARAM ({list_path}:1) */
            void
            g_cclosure_user_marshal_VOID__PARAM (GClosure     *closure,
                                                 GValue       *return_value G_GNUC_UNUSED,
                                                 guint         n_param_values,
                                                 const GValue *param_values,
                                                 gpointer      invocation_hint G_GNUC_UNUSED,
                                                 gpointer      marshal_data)
            {{
              typedef void (*GMarshalFunc_VOID__PARAM) (gpointer data1,
                                                        gpointer arg1,
                                                        gpointer data2);
              GCClosure *cc = (GCClosure *) closure;
              gpointer data1, data2;
              GMarshalFunc_VOID__PARAM callback;

              g_return_if_fail (n_param_values == 2);

              if (G_CCLOSURE_SWAP_DATA (closure))
                {{
                  data1 = closure->data;
                  data2 = g_value_peek_pointer (param_values + 0);
                }}
              else
                {{
                  data1 = g_value_peek_pointer (param_values + 0);
                  data2 = closure->data;
                }}
              callback = (GMarshalFunc_VOID__PARAM) (marshal_data ? marshal_data : cc->callback);

              callback (data1,
                        g_marshal_value_peek_param (param_values + 1),
                        data2);
            }}

            void
            g_cclosure_user_marshal_VOID__PARAMv (GClosure *closure,
                                                  GValue   *return_value G_GNUC_UNUSED,
                                                  gpointer  instance,
                                                  va_list   args,
                                                  gpointer  marshal_data,
                                                  int       n_params,
                                                  GType    *param_types)
            {{
              typedef void (*GMarshalFunc_VOID__PARAM) (gpointer data1,
                                                        gpointer arg1,
                                                        gpointer data2);
              GCClosure *cc = (GCClosure *) closure;
              gpointer data1, data2;
              GMarshalFunc_VOID__PARAM callback;
              gpointer arg0;
              va_list args_copy;

              va_copy (args_copy, args);
              arg0 = (gpointer) va_arg (args_copy, gpointer);
              if ((param_types[0] & G_SIGNAL_TYPE_STATIC_SCOPE) == 0 && arg0 != NULL)
                arg0 = g_param_spec_ref (arg0);
              va_end (args_copy);


              if (G_CCLOSURE_SWAP_DATA (closure))
                {{
                  data1 = closure->data;
                  data2 = instance;
                }}
              else
                {{
                  data1 = instance;
                  data2 = closure->data;
                }}
              callback = (GMarshalFunc_VOID__PARAM) (marshal_data ? marshal_data : cc->callback);

              callback (data1,
                        arg0,
                        data2);
              if ((param_types[0] & G_SIGNAL_TYPE_STATIC_SCOPE) == 0 && arg0 != NULL)
                g_param_spec_unref (arg0);
            }}
            """
            )
            .strip()
            .format(**body_result.subs),
            body_result.out.strip(),
        )


if __name__ == "__main__":
    unittest.main(testRunner=taptestrunner.TAPTestRunner())