File: member.xs

package info (click to toggle)
libconvert-binary-c-perl 0.85-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, trixie
  • size: 13,260 kB
  • sloc: ansic: 47,820; perl: 4,980; yacc: 2,143; makefile: 61
file content (128 lines) | stat: -rw-r--r-- 2,982 bytes parent folder | download | duplicates (2)
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
################################################################################
#
# Copyright (c) 2002-2024 Marcus Holland-Moritz. All rights reserved.
# This program is free software; you can redistribute it and/or modify
# it under the same terms as Perl itself.
#
################################################################################


################################################################################
#
#   METHOD: member
#
#   WRITTEN BY: Marcus Holland-Moritz             ON: Jan 2002
#   CHANGED BY:                                   ON:
#
################################################################################

void
CBC::member(type, offset = NULL)
  const char *type
  SV *offset

  PREINIT:
    CBC_METHOD(member);
    MemberInfo mi;
    int have_offset, off;

  PPCODE:
    off = (have_offset = DEFINED(offset)) ? SvIV(offset) : 0;

    CT_DEBUG_METHOD2("'%s', %d", type, off);

    CHECK_PARSE_DATA;
    CHECK_VOID_CONTEXT;

    NEED_PARSE_DATA;

    if (!get_member_info(aTHX_ THIS, type, &mi, 0))
      Perl_croak(aTHX_ "Cannot find '%s'", type);

    check_allowed_types(aTHX_ &mi, method, ALLOW_STRUCTS
                                         | ALLOW_UNIONS
                                         | ALLOW_ARRAYS);

    if (mi.flags)
    {
      u_32 flags = mi.flags;

      /* bitfields are not a problem without offset given */
      if (!have_offset)
        flags &= ~T_HASBITFIELD;

      WARN_FLAGS(type, flags);
    }

    if (have_offset)
    {
      if (off < 0 || off >= (int) mi.size)
        Perl_croak(aTHX_ "Offset %d out of range (0 <= offset < %d)", off, mi.size);

      if (GIMME_V == G_ARRAY)
      {
        ListIterator li;
        GMSInfo info;
        SV     *member;
        int     count;

        info.hit = LL_new();
        info.off = LL_new();
        info.pad = LL_new();

        (void) get_member_string(aTHX_ &mi, off, &info);

        count = LL_count(info.hit)
              + LL_count(info.off)
              + LL_count(info.pad);

        EXTEND(SP, count);

        LL_foreach(member, li, info.hit)
          PUSHs(member);

        LL_foreach(member, li, info.off)
          PUSHs(member);

        LL_foreach(member, li, info.pad)
          PUSHs(member);

        LL_destroy(info.hit, NULL);
        LL_destroy(info.off, NULL);
        LL_destroy(info.pad, NULL);

        XSRETURN(count);
      }
      else
      {
        SV *member = get_member_string(aTHX_ &mi, off, NULL);
        PUSHs(member);
        XSRETURN(1);
      }
    }
    else
    {
      LinkedList list;
      SV *member;
      int count;

      list = GIMME_V == G_ARRAY ? LL_new() : NULL;
      count = get_all_member_strings(aTHX_ &mi, list);

      if (GIMME_V == G_ARRAY)
      {
        ListIterator li;

        EXTEND(SP, count);

        LL_foreach(member, li, list)
          PUSHs(member);

        LL_destroy(list, NULL);

        XSRETURN(count);
      }
      else
        XSRETURN_IV(count);
    }