2011-12-22 16:19:25 +01:00
|
|
|
/*
|
|
|
|
* \brief Test for using Python on Genode
|
|
|
|
* \author Sebastian Sumpf
|
|
|
|
* \date 2010-02-17
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
2017-02-20 13:23:52 +01:00
|
|
|
* Copyright (C) 2010-2017 Genode Labs GmbH
|
2011-12-22 16:19:25 +01:00
|
|
|
*
|
|
|
|
* This file is part of the Genode OS framework, which is distributed
|
2017-02-20 13:23:52 +01:00
|
|
|
* under the terms of the GNU Affero General Public License version 3.
|
2011-12-22 16:19:25 +01:00
|
|
|
*/
|
|
|
|
|
|
|
|
/* Python includes */
|
|
|
|
#include <python2.6/Python.h>
|
|
|
|
|
|
|
|
/* Genode includes */
|
base: avoid use of deprecated base/printf.h
Besides adapting the components to the use of base/log.h, the patch
cleans up a few base headers, i.e., it removes unused includes from
root/component.h, specifically base/heap.h and
ram_session/ram_session.h. Hence, components that relied on the implicit
inclusion of those headers have to manually include those headers now.
While adjusting the log messages, I repeatedly stumbled over the problem
that printing char * arguments is ambiguous. It is unclear whether to
print the argument as pointer or null-terminated string. To overcome
this problem, the patch introduces a new type 'Cstring' that allows the
caller to express that the argument should be handled as null-terminated
string. As a nice side effect, with this type in place, the optional len
argument of the 'String' class could be removed. Instead of supplying a
pair of (char const *, size_t), the constructor accepts a 'Cstring'.
This, in turn, clears the way let the 'String' constructor use the new
output mechanism to assemble a string from multiple arguments (and
thereby getting rid of snprintf within Genode in the near future).
To enforce the explicit resolution of the char * ambiguity, the 'char *'
overload of the 'print' function is marked as deleted.
Issue #1987
2016-07-13 19:07:09 +02:00
|
|
|
#include <base/log.h>
|
2011-12-22 16:19:25 +01:00
|
|
|
|
|
|
|
/* libc includes */
|
|
|
|
#include <fcntl.h>
|
|
|
|
|
|
|
|
|
|
|
|
extern "C" int __sread(void *, char *, int);
|
|
|
|
|
|
|
|
|
2017-05-29 14:52:24 +02:00
|
|
|
int main(int argc, char const ** args)
|
2011-12-22 16:19:25 +01:00
|
|
|
{
|
|
|
|
using namespace Genode;
|
|
|
|
|
2017-05-29 14:52:24 +02:00
|
|
|
if (argc < 1) {
|
|
|
|
Genode::error("Need <scriptname>.py as argument!");
|
|
|
|
return -1;
|
2011-12-22 16:19:25 +01:00
|
|
|
}
|
|
|
|
|
2017-05-29 14:52:24 +02:00
|
|
|
char * name = const_cast<char*>(args[0]);
|
|
|
|
FILE * fp = fopen(name, "r");
|
2017-01-04 15:16:39 +01:00
|
|
|
//fp._flags = __SRD;
|
2011-12-22 16:19:25 +01:00
|
|
|
Py_SetProgramName(name);
|
|
|
|
//don't need the 'site' module
|
|
|
|
Py_NoSiteFlag = 1;
|
|
|
|
//don't support interactive mode, yet
|
|
|
|
Py_InteractiveFlag = 0;
|
|
|
|
Py_Initialize();
|
|
|
|
|
base: avoid use of deprecated base/printf.h
Besides adapting the components to the use of base/log.h, the patch
cleans up a few base headers, i.e., it removes unused includes from
root/component.h, specifically base/heap.h and
ram_session/ram_session.h. Hence, components that relied on the implicit
inclusion of those headers have to manually include those headers now.
While adjusting the log messages, I repeatedly stumbled over the problem
that printing char * arguments is ambiguous. It is unclear whether to
print the argument as pointer or null-terminated string. To overcome
this problem, the patch introduces a new type 'Cstring' that allows the
caller to express that the argument should be handled as null-terminated
string. As a nice side effect, with this type in place, the optional len
argument of the 'String' class could be removed. Instead of supplying a
pair of (char const *, size_t), the constructor accepts a 'Cstring'.
This, in turn, clears the way let the 'String' constructor use the new
output mechanism to assemble a string from multiple arguments (and
thereby getting rid of snprintf within Genode in the near future).
To enforce the explicit resolution of the char * ambiguity, the 'char *'
overload of the 'print' function is marked as deleted.
Issue #1987
2016-07-13 19:07:09 +02:00
|
|
|
Genode::log("Starting python ...");
|
2017-01-04 15:16:39 +01:00
|
|
|
PyRun_SimpleFile(fp, name);
|
2011-12-22 16:19:25 +01:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|