Upstream version 7.35.144.0
[platform/framework/web/crosswalk.git] / src / chrome / test / pyautolib / argc_argv.i
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4 //
5 // Make functions using (int argc, char** argv) usable as (sys.argv) from python
6
7 %typemap(in) (int argc, char **argv) {
8   int i;
9   if (!PyList_Check($input)) {
10     PyErr_SetString(PyExc_ValueError, "Expecting a list");
11     return NULL;
12   }
13   $1 = PyList_Size($input);
14   $2 = (char **) malloc(($1+1)*sizeof(char *));
15   for (i = 0; i < $1; i++) {
16     PyObject *s = PyList_GetItem($input,i);
17     if (!PyString_Check(s)) {
18         free($2);
19         PyErr_SetString(PyExc_ValueError, "List items must be strings");
20         return NULL;
21     }
22     $2[i] = PyString_AsString(s);
23   }
24   $2[i] = 0;
25 }
26
27 %typemap(freearg) (int argc, char **argv) {
28    if ($2) free($2);
29 }
30