blob: e35058106e7792dce84427c4bbf7d0afcec54cb5 [file] [log] [blame]
diff --git a/Include/datetime.h b/Include/datetime.h
--- a/Include/datetime.h
+++ b/Include/datetime.h
@@ -169,6 +169,8 @@ typedef struct {
#ifdef Py_BUILD_CORE
+#define PyDataTime_STATIC 1
+
/* Macros for type checking when building the Python core. */
#define PyDate_Check(op) PyObject_TypeCheck(op, &PyDateTime_DateType)
#define PyDate_CheckExact(op) (Py_TYPE(op) == &PyDateTime_DateType)
diff --git a/Makefile.pre.in b/Makefile.pre.in
--- a/Makefile.pre.in
+++ b/Makefile.pre.in
@@ -747,14 +747,18 @@ $(IO_OBJS): $(IO_H)
$(GRAMMAR_H): $(GRAMMAR_INPUT) $(PGENSRCS)
@$(MKDIR_P) Include
+ifndef CROSS_COMPILE
$(MAKE) $(PGEN)
+endif
$(PGEN) $(GRAMMAR_INPUT) $(GRAMMAR_H) $(GRAMMAR_C)
$(GRAMMAR_C): $(GRAMMAR_H) $(GRAMMAR_INPUT) $(PGENSRCS)
$(MAKE) $(GRAMMAR_H)
touch $(GRAMMAR_C)
+ifndef CROSS_COMPILE
$(PGEN): $(PGENOBJS)
$(CC) $(OPT) $(PY_LDFLAGS) $(PGENOBJS) $(LIBS) -o $(PGEN)
+endif
Parser/grammar.o: $(srcdir)/Parser/grammar.c \
$(srcdir)/Include/token.h \
@@ -1539,9 +1543,12 @@ profile-removal:
rm -rf $(COVERAGE_REPORT)
clobber: clean profile-removal
- -rm -f $(BUILDPYTHON) $(PGEN) $(LIBRARY) $(LDLIBRARY) $(DLLLIBRARY) \
+ -rm -f $(BUILDPYTHON) $(LIBRARY) $(LDLIBRARY) $(DLLLIBRARY) \
tags TAGS \
config.cache config.log pyconfig.h Modules/config.c
+ifndef CROSS_COMPILE
+ -rm -f $(PGEN)
+endif
-rm -rf build platform
-rm -rf $(PYTHONFRAMEWORKDIR)
-rm -f python-config.py python-config
diff --git a/Modules/_ctypes/libffi/configure b/Modules/_ctypes/libffi/configure
--- a/Modules/_ctypes/libffi/configure
+++ b/Modules/_ctypes/libffi/configure
@@ -17261,7 +17261,7 @@ case "$host" in
TARGETDIR=x86
if test $ac_cv_sizeof_size_t = 4; then
case "$host" in
- *-gnux32)
+ *-gnux32 | *-nacl)
TARGET=X86_64
;;
*)
diff --git a/Modules/_datetimemodule.c b/Modules/_datetimemodule.c
--- a/Modules/_datetimemodule.c
+++ b/Modules/_datetimemodule.c
@@ -7,6 +7,14 @@
#include <time.h>
+#if defined(__native_client__) && !defined(__GLIBC__)
+/* TODO(sbc): remove once this gets fixed:
+ * https://code.google.com/p/nativeclient/issues/detail?id=3737
+ */
+#define timezone _timezone
+#define daylight _daylight
+#endif
+
/* Differentiate between building the core module and building extension
* modules.
*/
diff --git a/Modules/_testcapimodule.c b/Modules/_testcapimodule.c
--- a/Modules/_testcapimodule.c
+++ b/Modules/_testcapimodule.c
@@ -1810,6 +1810,9 @@ static int test_run_counter = 0;
static PyObject *
test_datetime_capi(PyObject *self, PyObject *args) {
+#ifdef PyDataTime_STATIC
+ Py_RETURN_NONE;
+#else
if (PyDateTimeAPI) {
if (test_run_counter) {
/* Probably regrtest.py -R */
@@ -1827,6 +1830,7 @@ test_datetime_capi(PyObject *self, PyObject *args) {
Py_RETURN_NONE;
else
return NULL;
+#endif
}
diff --git a/Modules/faulthandler.c b/Modules/faulthandler.c
--- a/Modules/faulthandler.c
+++ b/Modules/faulthandler.c
@@ -15,6 +15,15 @@
# define FAULTHANDLER_LATER
#endif
+#ifdef __native_client__
+# ifndef SA_RESTART
+# define SA_RESTART 0
+# endif
+# ifndef SA_NODEFER
+# define SA_NODEFER 0
+# endif
+#endif
+
#ifndef MS_WINDOWS
/* register() is useless on Windows, because only SIGSEGV, SIGABRT and
SIGILL can be handled by the process, and these signals can only be used
diff --git a/Modules/pwdmodule.c b/Modules/pwdmodule.c
--- a/Modules/pwdmodule.c
+++ b/Modules/pwdmodule.c
@@ -87,6 +87,29 @@ mkpwent(struct passwd *p)
return v;
}
+#ifdef __native_client__
+// python relies on a working version of getpwuid(3)
+// which Native Client does not yet provide.
+// TODO(sbc): This should only really be needed when
+// building for the sel_ldr. It should be possible to
+// use the C-library version (which tries of open files
+// under /etc) when using nacl_io.
+static struct passwd *my_getpwuid(uid_t uid)
+{
+ static struct passwd dummy = {
+ "nacl_user",
+ "nacl_pass",
+ 1,
+ 1,
+ "NaCl User",
+ "/home/nacl_user",
+ "/bin/sh",
+ };
+ return &dummy;
+}
+#define getpwuid my_getpwuid
+#endif
+
PyDoc_STRVAR(pwd_getpwuid__doc__,
"getpwuid(uid) -> (pw_name,pw_passwd,pw_uid,\n\
pw_gid,pw_gecos,pw_dir,pw_shell)\n\
diff --git a/Modules/python.c b/Modules/python.c
--- a/Modules/python.c
+++ b/Modules/python.c
@@ -15,6 +15,19 @@ wmain(int argc, wchar_t **argv)
}
#else
+#ifdef __native_client__
+#include <stdio.h>
+#include <sys/utsname.h>
+
+// Dummy implementation of uname. This is only needed for the sel_ldr
+// version of python. Otherwise it gets provided by nacl_io.
+int uname(struct utsname *buf)
+{
+ sprintf(buf->sysname, "NaCl");
+ return 0;
+}
+#endif
+
int
main(int argc, char **argv)
{
diff --git a/Modules/readline.c b/Modules/readline.c
--- a/Modules/readline.c
+++ b/Modules/readline.c
@@ -1051,8 +1051,12 @@ setup_readline(readlinestate *mod_state)
/* Wrapper around GNU readline that handles signals differently. */
-
-#if defined(HAVE_RL_CALLBACK) && defined(HAVE_SELECT)
+/*
+ * Don't use the select()-based readline under Native Client. While select()
+ * is available and compile and link time it will fail at runtime under sel_ldr
+ * since there is no IRT/syscall implemenation of select().
+ */
+#if defined(HAVE_RL_CALLBACK) && defined(HAVE_SELECT) && !defined(__native_client__)
static char *completed_input_string;
static void
diff --git a/Modules/signalmodule.c b/Modules/signalmodule.c
--- a/Modules/signalmodule.c
+++ b/Modules/signalmodule.c
@@ -29,7 +29,7 @@
# define PYPTHREAD_SIGMASK
#endif
-#if defined(PYPTHREAD_SIGMASK) && defined(HAVE_PTHREAD_H)
+#if (defined(PYPTHREAD_SIGMASK) || defined(HAVE_PTHREAD_KILL)) && defined(HAVE_PTHREAD_H)
# include <pthread.h>
#endif
diff --git a/Modules/socketmodule.c b/Modules/socketmodule.c
--- a/Modules/socketmodule.c
+++ b/Modules/socketmodule.c
@@ -310,6 +310,14 @@ if_indextoname(index) -- return the corresponding interface name\n\
# include "addrinfo.h"
#endif
+#if defined(__native_client__) && !defined(__GLIBC__)
+struct iovec {
+ void *iov_base;
+ size_t iov_len;
+};
+#undef CMSG_LEN
+#endif
+
#ifndef HAVE_INET_PTON
#if !defined(NTDDI_VERSION) || (NTDDI_VERSION < NTDDI_LONGHORN)
int inet_pton(int af, const char *src, void *dst);
diff --git a/Modules/timemodule.c b/Modules/timemodule.c
--- a/Modules/timemodule.c
+++ b/Modules/timemodule.c
@@ -2,6 +2,7 @@
#include "Python.h"
+
#include <ctype.h>
#ifdef HAVE_SYS_TIMES_H
@@ -20,6 +21,11 @@
#include <io.h>
#endif
+#if defined(__native_client__) && !defined(__GLIBC__)
+#define timezone _timezone
+#define daylight _daylight
+#endif
+
#if defined(__WATCOMC__) && !defined(__QNX__)
#include <i86.h>
#else
@@ -41,6 +47,13 @@
#include <mach/mach_time.h>
#endif
+#if defined(__native_client__) && !defined(__GLIBC__)
+int clock_settime(clockid_t clk_id, const struct timespec *tp) {
+ errno = EPERM;
+ return -1;
+}
+#endif
+
/* Forward declarations */
static int floatsleep(double);
static PyObject* floattime(_Py_clock_info_t *info);
diff --git a/Python/dynload_shlib.c b/Python/dynload_shlib.c
--- a/Python/dynload_shlib.c
+++ b/Python/dynload_shlib.c
@@ -69,6 +69,11 @@ dl_funcptr _PyImport_GetDynLoadFunc(const char *shortname,
PyOS_snprintf(funcname, sizeof(funcname),
LEAD_UNDERSCORE "PyInit_%.200s", shortname);
+
+/* Native Client's fstat() imlemenation doesn't set st_dev
+ * and st_ino correctly so disable the dlopen handle cache.
+ * TODO(sbc): fix NaCl's fstat() */
+#ifndef __native_client__
if (fp != NULL) {
int i;
struct stat statb;
@@ -89,6 +94,7 @@ dl_funcptr _PyImport_GetDynLoadFunc(const char *shortname,
handles[nhandles].ino = statb.st_ino;
}
}
+#endif
dlopenflags = PyThreadState_GET()->interp->dlopenflags;
diff --git a/Python/fileutils.c b/Python/fileutils.c
--- a/Python/fileutils.c
+++ b/Python/fileutils.c
@@ -599,6 +599,12 @@ get_inheritable(int fd, int raise)
flags = fcntl(fd, F_GETFD, 0);
if (flags == -1) {
+#if defined(__native_client__) && !defined(__GLIBC__)
+ /* When running under NaCl within the sel_ldr this fcntl() will always
+ fail. However we don't want to completely remove this block since
+ fcntl() is emulated using nacl_io when running within chrome. */
+ return 0;
+#endif
if (raise)
PyErr_SetFromErrno(PyExc_OSError);
return -1;
@@ -707,6 +713,12 @@ set_inheritable(int fd, int inheritable, int raise, int *atomic_flag_works)
/* slow-path: fcntl() requires two syscalls */
flags = fcntl(fd, F_GETFD);
if (flags < 0) {
+#if defined(__native_client__) && !defined(__GLIBC__)
+ /* When running under NaCl within the sel_ldr this fcntl() will always
+ fail. However we don't want to completely remove this block since
+ fcntl() is emulated using nacl_io when running within chrome. */
+ return 0;
+#endif
if (raise)
PyErr_SetFromErrno(PyExc_OSError);
return -1;
diff --git a/Python/getversion.c b/Python/getversion.c
--- a/Python/getversion.c
+++ b/Python/getversion.c
@@ -8,8 +8,8 @@
const char *
Py_GetVersion(void)
{
- static char version[250];
- PyOS_snprintf(version, sizeof(version), "%.80s (%.80s) %.80s",
+ static char version[270];
+ PyOS_snprintf(version, sizeof(version), "%.80s (%.80s) %.100s",
PY_VERSION, Py_GetBuildInfo(), Py_GetCompiler());
return version;
}
diff --git a/Python/thread.c b/Python/thread.c
--- a/Python/thread.c
+++ b/Python/thread.c
@@ -13,9 +13,19 @@
library (e.g. gnu pth in pthread emulation) */
# ifdef HAVE_PTHREAD_H
# include <pthread.h> /* _POSIX_THREADS */
+# if defined __native_client__ && !defined _POSIX_THREADS
+ /* Under NaCl newlib neither pthread.h nor unistd.h defines _POSIX_THREADS.
+ However this file expects it to be defined if pthreads are present so we
+ define it here after including pthread.h
+ TODO(sbc): remove this hack once newlib is fixed:
+ https://code.google.com/p/nativeclient/issues/detail?id=3551
+ */
+# define _POSIX_THREADS
+# endif
# endif
#endif
+
#ifndef DONT_HAVE_STDIO_H
#include <stdio.h>
#endif
diff --git a/configure b/configure
--- a/configure
+++ b/configure
@@ -2969,7 +2969,7 @@ $as_echo_n "checking for python interpreter for cross build... " >&6; }
fi
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $interp" >&5
$as_echo "$interp" >&6; }
- PYTHON_FOR_BUILD='_PYTHON_PROJECT_BASE=$(abs_builddir) _PYTHON_HOST_PLATFORM=$(_PYTHON_HOST_PLATFORM) PYTHONPATH=$(shell test -f pybuilddir.txt && echo $(abs_builddir)/`cat pybuilddir.txt`:)$(srcdir)/Lib:$(srcdir)/Lib/$(PLATDIR) '$interp
+ PYTHON_FOR_BUILD='_PYTHON_PROJECT_BASE=$(abs_builddir) _PYTHON_HOST_PLATFORM=$(_PYTHON_HOST_PLATFORM) PYTHONPATH=$(srcdir)/Lib:$(srcdir)/Lib/$(PLATDIR) '$interp
fi
elif test "$cross_compiling" = maybe; then
as_fn_error $? "Cross compiling required --host=HOST-TUPLE and --build=ARCH" "$LINENO" 5
@@ -3284,6 +3284,9 @@ then
# a lot of different things including 'define_xopen_source'
# in the case statement below.
case "$host" in
+ *-*-nacl*)
+ ac_sys_system=NaCl
+ ;;
*-*-linux*)
ac_sys_system=Linux
;;
@@ -3332,6 +3335,15 @@ if test "$cross_compiling" = yes; then
_host_cpu=$host_cpu
esac
;;
+ *-*-nacl*)
+ case "$host_cpu" in
+ arm*)
+ _host_cpu=arm
+ ;;
+ *)
+ _host_cpu=$host_cpu
+ esac
+ ;;
*-*-cygwin*)
_host_cpu=
;;
@@ -5376,7 +5388,11 @@ if test -d casesensitivetestdir
then
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: yes" >&5
$as_echo "yes" >&6; }
- BUILDEXEEXT=.exe
+ if [ -z $EXEEXT ]; then
+ BUILDEXEEXT=.exe
+ else
+ BUILDEXEEXT=$EXEEXT
+ fi
else
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
$as_echo "no" >&6; }
@@ -8579,7 +8595,7 @@ then
BLDSHARED="$LDSHARED"
fi
;;
- Linux*|GNU*|QNX*)
+ Linux*|GNU*|QNX*|NaCl*)
LDSHARED='$(CC) -shared'
LDCXXSHARED='$(CXX) -shared';;
BSD/OS*/4*)
@@ -8650,7 +8666,7 @@ then
then CCSHARED="-fPIC";
else CCSHARED="+z";
fi;;
- Linux*|GNU*) CCSHARED="-fPIC";;
+ Linux*|GNU*|NaCl*) CCSHARED="-fPIC";;
BSD/OS*/4*) CCSHARED="-fpic";;
FreeBSD*|NetBSD*|OpenBSD*|DragonFly*) CCSHARED="-fPIC";;
OpenUNIX*|UnixWare*)
@@ -8683,7 +8699,7 @@ then
LINKFORSHARED="-Wl,-E -Wl,+s";;
# LINKFORSHARED="-Wl,-E -Wl,+s -Wl,+b\$(BINLIBDEST)/lib-dynload";;
BSD/OS/4*) LINKFORSHARED="-Xlinker -export-dynamic";;
- Linux*|GNU*) LINKFORSHARED="-Xlinker -export-dynamic";;
+ Linux*|GNU*|NaCl*) LINKFORSHARED="-Xlinker -export-dynamic";;
# -u libsys_s pulls in all symbols in libsys
Darwin/*)
LINKFORSHARED="$extra_undefs -framework CoreFoundation"
diff --git a/configure.ac b/configure.ac
--- a/configure.ac
+++ b/configure.ac
@@ -373,6 +373,9 @@ then
*-*-cygwin*)
ac_sys_system=Cygwin
;;
+ *-*-nacl*)
+ ac_sys_system=NaCl
+ ;;
*)
# for now, limit cross builds to known configurations
MACHDEP="unknown"
@@ -415,6 +418,15 @@ if test "$cross_compiling" = yes; then
_host_cpu=$host_cpu
esac
;;
+ *-*-nacl*)
+ case "$host_cpu" in
+ arm*)
+ _host_cpu=arm
+ ;;
+ *)
+ _host_cpu=$host_cpu
+ esac
+ ;;
*-*-cygwin*)
_host_cpu=
;;
@@ -2055,7 +2067,7 @@ then
BLDSHARED="$LDSHARED"
fi
;;
- Linux*|GNU*|QNX*)
+ Linux*|GNU*|QNX*|NaCl*)
LDSHARED='$(CC) -shared'
LDCXXSHARED='$(CXX) -shared';;
BSD/OS*/4*)
@@ -2124,7 +2136,7 @@ then
then CCSHARED="-fPIC";
else CCSHARED="+z";
fi;;
- Linux*|GNU*) CCSHARED="-fPIC";;
+ Linux*|GNU*|NaCl*) CCSHARED="-fPIC";;
BSD/OS*/4*) CCSHARED="-fpic";;
FreeBSD*|NetBSD*|OpenBSD*|DragonFly*) CCSHARED="-fPIC";;
OpenUNIX*|UnixWare*)
@@ -2155,7 +2167,7 @@ then
LINKFORSHARED="-Wl,-E -Wl,+s";;
# LINKFORSHARED="-Wl,-E -Wl,+s -Wl,+b\$(BINLIBDEST)/lib-dynload";;
BSD/OS/4*) LINKFORSHARED="-Xlinker -export-dynamic";;
- Linux*|GNU*) LINKFORSHARED="-Xlinker -export-dynamic";;
+ Linux*|GNU*|NaCl*) LINKFORSHARED="-Xlinker -export-dynamic";;
# -u libsys_s pulls in all symbols in libsys
Darwin/*)
LINKFORSHARED="$extra_undefs -framework CoreFoundation"