~ps10gel/ubuntu/xenial/trafficserver/6.2.0

« back to all changes in this revision

Viewing changes to test/deft/test_interp_glue.i

  • Committer: Bazaar Package Importer
  • Author(s): Arno Toell
  • Date: 2011-01-13 11:49:18 UTC
  • Revision ID: james.westby@ubuntu.com-20110113114918-vu422h8dknrgkj15
Tags: upstream-2.1.5-unstable
ImportĀ upstreamĀ versionĀ 2.1.5-unstable

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/** @file
 
2
 
 
3
  A brief file description
 
4
 
 
5
  @section license License
 
6
 
 
7
  Licensed to the Apache Software Foundation (ASF) under one
 
8
  or more contributor license agreements.  See the NOTICE file
 
9
  distributed with this work for additional information
 
10
  regarding copyright ownership.  The ASF licenses this file
 
11
  to you under the Apache License, Version 2.0 (the
 
12
  "License"); you may not use this file except in compliance
 
13
  with the License.  You may obtain a copy of the License at
 
14
 
 
15
      http://www.apache.org/licenses/LICENSE-2.0
 
16
 
 
17
  Unless required by applicable law or agreed to in writing, software
 
18
  distributed under the License is distributed on an "AS IS" BASIS,
 
19
  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 
20
  See the License for the specific language governing permissions and
 
21
  limitations under the License.
 
22
 */
 
23
 
 
24
% module TestExec % {
 
25
#include "test_interp_glue.h"
 
26
%}
 
27
 
 
28
%include pointer.i % typemap(perl5, in)
 
29
char **
 
30
{
 
31
  AV *
 
32
    av = SvRV($input);
 
33
  char **
 
34
    result = NULL;
 
35
 
 
36
  if (SvTYPE(av) == SVt_PVAV)
 
37
{
 
38
int array_len = av_len(av);
 
39
 
 
40
if (array_len < 0)
 
41
{
 
42
  result = NULL;
 
43
} else
 
44
{
 
45
  int i;
 
46
  STRLEN str_len;
 
47
  char *str;
 
48
  SV **cur_sv;
 
49
  result = (char **) malloc((sizeof(char *) * (array_len + 2)));
 
50
 
 
51
  for (i = 0; i <= array_len; i++) {
 
52
    cur_sv = av_fetch(av, i, 0);
 
53
    str = SvPV(*cur_sv, str_len);
 
54
    result[i] = (char *) malloc(str_len + 1);
 
55
    strcpy(result[i], str);
 
56
  }
 
57
 
 
58
  result[array_len + 1] = NULL;
 
59
}
 
60
  } else {
 
61
    result = NULL;
 
62
  }
 
63
 
 
64
  $1 = result;
 
65
}
 
66
 
 
67
%typemap(perl5, out)
 
68
char **
 
69
{
 
70
  char **
 
71
    from_c = $1;
 
72
  char **
 
73
    tmp;
 
74
  int
 
75
    i;
 
76
  int
 
77
    num_el = 0;
 
78
 
 
79
  if (from_c)
 
80
  {
 
81
    tmp = from_c;
 
82
    while (*tmp != NULL)
 
83
    {
 
84
      num_el++;
 
85
      tmp++;
 
86
    }
 
87
 
 
88
    EXTEND(sp, num_el);
 
89
 
 
90
    tmp = from_c;
 
91
    for (i = 0; i < num_el; i++) {
 
92
      ST(argvi) = sv_newmortal();
 
93
      sv_setpv(ST(argvi++), tmp[i]);
 
94
      free(tmp[i]);
 
95
    }
 
96
    free(from_c);
 
97
  }
 
98
}
 
99
 
 
100
%typemap(perl5, out)
 
101
char *
 
102
{
 
103
  char *
 
104
    from_c = $1;
 
105
  int
 
106
    i;
 
107
  int
 
108
    num_el = 0;
 
109
 
 
110
  if (from_c)
 
111
  {
 
112
    ST(argvi) = sv_newmortal();
 
113
    sv_setpv(ST(argvi++), from_c);
 
114
    free(from_c);
 
115
  }
 
116
}
 
117
 
 
118
 %include test_interp_glue.h