| diff --git a/Include/datetime.h b/Include/datetime.h |
| --- a/Include/datetime.h |
| +++ b/Include/datetime.h |
| @@ -166,6 +166,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/Lib/platform.py b/Lib/platform.py |
| --- a/Lib/platform.py |
| +++ b/Lib/platform.py |
| @@ -1001,7 +1001,7 @@ def _syscmd_uname(option,default=''): |
| |
| """ Interface to the system's uname command. |
| """ |
| - if sys.platform in ('dos','win32','win16','os2'): |
| + if sys.platform in ('dos','win32','win16','os2','nacl'): |
| # XXX Others too ? |
| return default |
| try: |
| diff --git a/Lib/subprocess.py b/Lib/subprocess.py |
| --- a/Lib/subprocess.py |
| +++ b/Lib/subprocess.py |
| @@ -388,6 +388,7 @@ except that: |
| |
| import sys |
| mswindows = (sys.platform == "win32") |
| +nacl = (sys.platform == "nacl") |
| |
| import os |
| import types |
| @@ -1206,7 +1207,10 @@ class Popen(object): |
| args = list(args) |
| |
| if shell: |
| - args = ["/bin/sh", "-c"] + args |
| + if nacl: |
| + args = ["bash", "-c"] + args |
| + else: |
| + args = ["/bin/sh", "-c"] + args |
| if executable: |
| args[0] = executable |
| |
| @@ -1217,6 +1221,15 @@ class Popen(object): |
| os.close(fd) |
| to_close.remove(fd) |
| |
| + # TODO(bradnelson,sbc): Add support for pipes. |
| + if nacl: |
| + if env is None: |
| + self.pid = os.spawnv(os.P_NOWAIT, executable, args) |
| + else: |
| + self.pid = os.spawnve(os.P_NOWAIT, executable, args, env) |
| + self._child_created = True |
| + return |
| + |
| # For transferring possible exec failure from child to parent |
| # The first char specifies the exception type: 0 means |
| # OSError, 1 means some other error. |
| diff --git a/Makefile.pre.in b/Makefile.pre.in |
| --- a/Makefile.pre.in |
| +++ b/Makefile.pre.in |
| @@ -610,14 +610,18 @@ Modules/pwdmodule.o: $(srcdir)/Modules/pwdmodule.c $(srcdir)/Modules/posixmodule |
| |
| $(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) $(LDFLAGS) $(PGENOBJS) $(LIBS) -o $(PGEN) |
| +endif |
| |
| Parser/grammar.o: $(srcdir)/Parser/grammar.c \ |
| $(srcdir)/Include/token.h \ |
| @@ -1042,6 +1046,7 @@ libinstall: build_all $(srcdir)/Lib/$(PLATDIR) $(srcdir)/Modules/xxmodule.c |
| $(INSTALL_DATA) $(srcdir)/Modules/xxmodule.c \ |
| $(DESTDIR)$(LIBDEST)/distutils/tests ; \ |
| fi |
| +ifndef CROSS_COMPILE |
| PYTHONPATH=$(DESTDIR)$(LIBDEST) $(RUNSHARED) \ |
| $(PYTHON_FOR_BUILD) -Wi -tt $(DESTDIR)$(LIBDEST)/compileall.py \ |
| -d $(LIBDEST) -f \ |
| @@ -1060,6 +1065,7 @@ libinstall: build_all $(srcdir)/Lib/$(PLATDIR) $(srcdir)/Modules/xxmodule.c |
| $(PYTHON_FOR_BUILD) -Wi -t -O $(DESTDIR)$(LIBDEST)/compileall.py \ |
| -d $(LIBDEST)/site-packages -f \ |
| -x badsyntax $(DESTDIR)$(LIBDEST)/site-packages |
| +endif |
| -PYTHONPATH=$(DESTDIR)$(LIBDEST) $(RUNSHARED) \ |
| $(PYTHON_FOR_BUILD) -m lib2to3.pgen2.driver $(DESTDIR)$(LIBDEST)/lib2to3/Grammar.txt |
| -PYTHONPATH=$(DESTDIR)$(LIBDEST) $(RUNSHARED) \ |
| 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/_ctypes/libffi/src/x86/unix64.S b/Modules/_ctypes/libffi/src/x86/unix64.S |
| --- a/Modules/_ctypes/libffi/src/x86/unix64.S |
| +++ b/Modules/_ctypes/libffi/src/x86/unix64.S |
| @@ -1,5 +1,6 @@ |
| /* ----------------------------------------------------------------------- |
| - unix64.S - Copyright (c) 2013 The Written Word, Inc. |
| + unix64.S - Copyright (c) 2015 Georgia Institute of Technology |
| + - Copyright (c) 2013 The Written Word, Inc. |
| - Copyright (c) 2008 Red Hat, Inc |
| - Copyright (c) 2002 Bo Thorsen <bo@suse.de> |
| |
| @@ -31,6 +32,24 @@ |
| #include <fficonfig.h> |
| #include <ffi.h> |
| |
| +.section .rodata |
| +.Lstore_table: |
| + .long .Lst_void-.Lstore_table /* FFI_TYPE_VOID */ |
| + .long .Lst_sint32-.Lstore_table /* FFI_TYPE_INT */ |
| + .long .Lst_float-.Lstore_table /* FFI_TYPE_FLOAT */ |
| + .long .Lst_double-.Lstore_table /* FFI_TYPE_DOUBLE */ |
| + .long .Lst_ldouble-.Lstore_table /* FFI_TYPE_LONGDOUBLE */ |
| + .long .Lst_uint8-.Lstore_table /* FFI_TYPE_UINT8 */ |
| + .long .Lst_sint8-.Lstore_table /* FFI_TYPE_SINT8 */ |
| + .long .Lst_uint16-.Lstore_table /* FFI_TYPE_UINT16 */ |
| + .long .Lst_sint16-.Lstore_table /* FFI_TYPE_SINT16 */ |
| + .long .Lst_uint32-.Lstore_table /* FFI_TYPE_UINT32 */ |
| + .long .Lst_sint32-.Lstore_table /* FFI_TYPE_SINT32 */ |
| + .long .Lst_int64-.Lstore_table /* FFI_TYPE_UINT64 */ |
| + .long .Lst_int64-.Lstore_table /* FFI_TYPE_SINT64 */ |
| + .long .Lst_struct-.Lstore_table /* FFI_TYPE_STRUCT */ |
| + .long .Lst_int64-.Lstore_table /* FFI_TYPE_POINTER */ |
| + |
| .text |
| |
| /* ffi_call_unix64 (void *args, unsigned long bytes, unsigned flags, |
| @@ -48,115 +67,122 @@ ffi_call_unix64: |
| .LUW0: |
| movq (%rsp), %r10 /* Load return address. */ |
| leaq (%rdi, %rsi), %rax /* Find local stack base. */ |
| - movq %rdx, (%rax) /* Save flags. */ |
| - movq %rcx, 8(%rax) /* Save raddr. */ |
| - movq %rbp, 16(%rax) /* Save old frame pointer. */ |
| - movq %r10, 24(%rax) /* Relocate return address. */ |
| - movq %rax, %rbp /* Finalize local stack frame. */ |
| + movq %rdx, %nacl:0(%r15, %rax) /* Save flags. */ |
| + movq %rcx, %nacl:8(%r15, %rax) /* Save raddr. */ |
| + movq %rbp, %nacl:16(%r15, %rax) /* Save old frame pointer. */ |
| + movq %r10, %nacl:24(%r15, %rax) /* Relocate return address. */ |
| + naclrestbp %eax, %r15 /* Finalize local stack frame. */ |
| .LUW1: |
| - movq %rdi, %r10 /* Save a copy of the register area. */ |
| - movq %r8, %r11 /* Save a copy of the target fn. */ |
| + movl %edi, %r10d /* Save a copy of the register area. */ |
| + movl %r8d, %r11d /* Save a copy of the target fn. */ |
| movl %r9d, %eax /* Set number of SSE registers. */ |
| |
| /* Load up all argument registers. */ |
| - movq (%r10), %rdi |
| - movq 8(%r10), %rsi |
| - movq 16(%r10), %rdx |
| - movq 24(%r10), %rcx |
| - movq 32(%r10), %r8 |
| - movq 40(%r10), %r9 |
| + movq %nacl:0(%r15, %r10), %rdi |
| + movq %nacl:8(%r15, %r10), %rsi |
| + movq %nacl:16(%r15, %r10), %rdx |
| + movq %nacl:24(%r15, %r10), %rcx |
| + movq %nacl:32(%r15, %r10), %r8 |
| + movq %nacl:40(%r15, %r10), %r9 |
| testl %eax, %eax |
| jnz .Lload_sse |
| .Lret_from_load_sse: |
| |
| /* Deallocate the reg arg area. */ |
| - leaq 176(%r10), %rsp |
| + .bundle_lock |
| + leal 176(%r10), %esp |
| + addq %r15, %rsp |
| + .bundle_unlock |
| |
| /* Call the user function. */ |
| - call *%r11 |
| + naclcall %r11d, %r15 |
| |
| /* Deallocate stack arg area; local stack frame in redzone. */ |
| - leaq 24(%rbp), %rsp |
| + .bundle_lock |
| + leal 24(%rbp), %esp |
| + addq %r15, %rsp |
| + .bundle_unlock |
| |
| movq 0(%rbp), %rcx /* Reload flags. */ |
| movq 8(%rbp), %rdi /* Reload raddr. */ |
| - movq 16(%rbp), %rbp /* Reload old frame pointer. */ |
| + naclrestbp 16(%rbp), %r15 /* Reload old frame pointer. */ |
| .LUW2: |
| |
| /* The first byte of the flags contains the FFI_TYPE. */ |
| movzbl %cl, %r10d |
| - leaq .Lstore_table(%rip), %r11 |
| - movslq (%r11, %r10, 4), %r10 |
| - addq %r11, %r10 |
| - jmp *%r10 |
| - |
| -.Lstore_table: |
| - .long .Lst_void-.Lstore_table /* FFI_TYPE_VOID */ |
| - .long .Lst_sint32-.Lstore_table /* FFI_TYPE_INT */ |
| - .long .Lst_float-.Lstore_table /* FFI_TYPE_FLOAT */ |
| - .long .Lst_double-.Lstore_table /* FFI_TYPE_DOUBLE */ |
| - .long .Lst_ldouble-.Lstore_table /* FFI_TYPE_LONGDOUBLE */ |
| - .long .Lst_uint8-.Lstore_table /* FFI_TYPE_UINT8 */ |
| - .long .Lst_sint8-.Lstore_table /* FFI_TYPE_SINT8 */ |
| - .long .Lst_uint16-.Lstore_table /* FFI_TYPE_UINT16 */ |
| - .long .Lst_sint16-.Lstore_table /* FFI_TYPE_SINT16 */ |
| - .long .Lst_uint32-.Lstore_table /* FFI_TYPE_UINT32 */ |
| - .long .Lst_sint32-.Lstore_table /* FFI_TYPE_SINT32 */ |
| - .long .Lst_int64-.Lstore_table /* FFI_TYPE_UINT64 */ |
| - .long .Lst_int64-.Lstore_table /* FFI_TYPE_SINT64 */ |
| - .long .Lst_struct-.Lstore_table /* FFI_TYPE_STRUCT */ |
| - .long .Lst_int64-.Lstore_table /* FFI_TYPE_POINTER */ |
| + leal .Lstore_table(%rip), %r11d |
| + leal (%r11, %r10, 4), %r10d |
| + movl %nacl:(%r15, %r10), %r10d |
| + addl %r11d, %r10d |
| + nacljmp %r10d, %r15 |
| |
| - .align 2 |
| + .align 32 |
| .Lst_void: |
| - ret |
| - .align 2 |
| + pop %r11 |
| + nacljmp %r11d, %r15 |
| |
| + .align 32 |
| .Lst_uint8: |
| movzbq %al, %rax |
| - movq %rax, (%rdi) |
| - ret |
| - .align 2 |
| + movq %rax, %nacl:0(%r15, %rdi) |
| + pop %r11 |
| + nacljmp %r11d, %r15 |
| + |
| + .align 32 |
| .Lst_sint8: |
| movsbq %al, %rax |
| - movq %rax, (%rdi) |
| - ret |
| - .align 2 |
| + movq %rax, %nacl:0(%r15, %rdi) |
| + pop %r11 |
| + nacljmp %r11d, %r15 |
| + |
| + .align 32 |
| .Lst_uint16: |
| movzwq %ax, %rax |
| - movq %rax, (%rdi) |
| - .align 2 |
| + movq %rax, %nacl:0(%r15, %rdi) |
| + pop %r11 |
| + nacljmp %r11d, %r15 |
| + |
| + .align 32 |
| .Lst_sint16: |
| movswq %ax, %rax |
| - movq %rax, (%rdi) |
| - ret |
| - .align 2 |
| + movq %rax, %nacl:0(%r15, %rdi) |
| + pop %r11 |
| + nacljmp %r11d, %r15 |
| + |
| + .align 32 |
| .Lst_uint32: |
| movl %eax, %eax |
| - movq %rax, (%rdi) |
| - .align 2 |
| + movq %rax, %nacl:0(%r15, %rdi) |
| + pop %r11 |
| + nacljmp %r11d, %r15 |
| + |
| + .align 32 |
| .Lst_sint32: |
| cltq |
| - movq %rax, (%rdi) |
| - ret |
| - .align 2 |
| + movq %rax, %nacl:0(%r15, %rdi) |
| + pop %r11 |
| + nacljmp %r11d, %r15 |
| + |
| + .align 32 |
| .Lst_int64: |
| - movq %rax, (%rdi) |
| - ret |
| + movq %rax, %nacl:0(%r15, %rdi) |
| + pop %r11 |
| + nacljmp %r11d, %r15 |
| |
| - .align 2 |
| + .align 32 |
| .Lst_float: |
| - movss %xmm0, (%rdi) |
| - ret |
| - .align 2 |
| + movss %xmm0, %nacl:0(%r15, %rdi) |
| + pop %r11 |
| + nacljmp %r11d, %r15 |
| + |
| + .align 32 |
| .Lst_double: |
| - movsd %xmm0, (%rdi) |
| - ret |
| .Lst_ldouble: |
| - fstpt (%rdi) |
| - ret |
| + movsd %xmm0, %nacl:0(%r15, %rdi) |
| + pop %r11 |
| + nacljmp %r11d, %r15 |
| |
| - .align 2 |
| + .align 32 |
| .Lst_struct: |
| leaq -20(%rsp), %rsi /* Scratch area in redzone. */ |
| |
| @@ -175,14 +201,15 @@ ffi_call_unix64: |
| testl $0x400, %ecx |
| cmovnz %r10, %rax |
| cmovnz %r11, %rdx |
| - movq %rax, (%rsi) |
| - movq %rdx, 8(%rsi) |
| + movq %rax, %nacl:0(%r15, %rsi) |
| + movq %rdx, %nacl:8(%r15, %rsi) |
| |
| /* Bits 12-31 contain the true size of the structure. Copy from |
| the scratch area to the true destination. */ |
| shrl $12, %ecx |
| - rep movsb |
| - ret |
| + rep movs %nacl:(%rsi), %nacl:(%rdi), %r15 |
| + pop %r11 |
| + nacljmp %r11d, %r15 |
| |
| /* Many times we can avoid loading any SSE registers at all. |
| It's not worth an indirect jump to load the exact set of |
| @@ -190,14 +217,14 @@ ffi_call_unix64: |
| .align 2 |
| .LUW3: |
| .Lload_sse: |
| - movdqa 48(%r10), %xmm0 |
| - movdqa 64(%r10), %xmm1 |
| - movdqa 80(%r10), %xmm2 |
| - movdqa 96(%r10), %xmm3 |
| - movdqa 112(%r10), %xmm4 |
| - movdqa 128(%r10), %xmm5 |
| - movdqa 144(%r10), %xmm6 |
| - movdqa 160(%r10), %xmm7 |
| + movdqa %nacl:48(%r15, %r10), %xmm0 |
| + movdqa %nacl:64(%r15, %r10), %xmm1 |
| + movdqa %nacl:80(%r15, %r10), %xmm2 |
| + movdqa %nacl:96(%r15, %r10), %xmm3 |
| + movdqa %nacl:112(%r15, %r10), %xmm4 |
| + movdqa %nacl:128(%r15, %r10), %xmm5 |
| + movdqa %nacl:144(%r15, %r10), %xmm6 |
| + movdqa %nacl:160(%r15, %r10), %xmm7 |
| jmp .Lret_from_load_sse |
| |
| .LUW4: |
| @@ -208,6 +235,10 @@ ffi_call_unix64: |
| .type ffi_closure_unix64,@function |
| |
| ffi_closure_unix64: |
| +#ifdef __native_client__ |
| + hlt |
| +#else |
| + /* THIS IMPLEMENTATION VIOLATES NATIVE CLIENT SFI MODEL */ |
| .LUW5: |
| /* The carry flag is set by the trampoline iff SSE registers |
| are used. Don't clobber it before the branch instruction. */ |
| @@ -422,9 +453,10 @@ ffi_closure_unix64: |
| |
| .align 8 |
| .LEFDE3: |
| - |
| #endif /* __GNUC__ */ |
| |
| +#endif /* __native_client__ */ |
| + |
| #endif /* __x86_64__ */ |
| |
| #if defined __ELF__ && defined __linux__ |
| diff --git a/Modules/_testcapimodule.c b/Modules/_testcapimodule.c |
| --- a/Modules/_testcapimodule.c |
| +++ b/Modules/_testcapimodule.c |
| @@ -1378,6 +1378,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 */ |
| @@ -1395,6 +1398,7 @@ test_datetime_capi(PyObject *self, PyObject *args) { |
| Py_RETURN_NONE; |
| else |
| return NULL; |
| +#endif |
| } |
| |
| |
| diff --git a/Modules/mmapmodule.c b/Modules/mmapmodule.c |
| --- a/Modules/mmapmodule.c |
| +++ b/Modules/mmapmodule.c |
| @@ -78,6 +78,12 @@ my_getpagesize(void) |
| # define MAP_ANONYMOUS MAP_ANON |
| #endif |
| |
| +#if defined(__native_client__) && defined(_NEWLIB_VERSION) |
| +#define MS_SYNC 0 |
| +/* Defined in glibc-compat */ |
| +int msync(void *addr, size_t length, int flags); |
| +#endif |
| + |
| static PyObject *mmap_module_error; |
| |
| typedef enum |
| diff --git a/Modules/posixmodule.c b/Modules/posixmodule.c |
| --- a/Modules/posixmodule.c |
| +++ b/Modules/posixmodule.c |
| @@ -216,6 +216,13 @@ extern int lstat(const char *, struct stat *); |
| |
| #endif /* !_MSC_VER */ |
| |
| +#if defined(__native_client__) |
| +#include <spawn.h> |
| +#if !defined(HAVE_SPAWNV) |
| +#define HAVE_SPAWNV 1 |
| +#endif /* !defined(HAVE_SPAWNV) */ |
| +#endif /* defined(__native_client__) */ |
| + |
| #ifdef HAVE_UTIME_H |
| #include <utime.h> |
| #endif /* HAVE_UTIME_H */ |
| @@ -718,9 +725,13 @@ posix_error_with_unicode_filename(Py_UNICODE* name) |
| |
| |
| static PyObject * |
| -posix_error_with_allocated_filename(char* name) |
| +posix_error_with_allocated_filename(const char* func, char* name) |
| { |
| - PyObject *rc = PyErr_SetFromErrnoWithFilename(PyExc_OSError, name); |
| + PyObject *rc; |
| + if (errno == ENOSYS) |
| + rc = PyErr_SetFromErrnoWithFilename(PyExc_OSError, func); |
| + else |
| + rc = PyErr_SetFromErrnoWithFilename(PyExc_OSError, name); |
| PyMem_Free(name); |
| return rc; |
| } |
| @@ -881,7 +892,7 @@ posix_1str(PyObject *args, char *format, int (*func)(const char*)) |
| res = (*func)(path1); |
| Py_END_ALLOW_THREADS |
| if (res < 0) |
| - return posix_error_with_allocated_filename(path1); |
| + return posix_error_with_allocated_filename(format, path1); |
| PyMem_Free(path1); |
| Py_INCREF(Py_None); |
| return Py_None; |
| @@ -1913,7 +1924,7 @@ posix_chmod(PyObject *self, PyObject *args) |
| res = chmod(path, i); |
| Py_END_ALLOW_THREADS |
| if (res < 0) |
| - return posix_error_with_allocated_filename(path); |
| + return posix_error_with_allocated_filename("chmod", path); |
| PyMem_Free(path); |
| Py_INCREF(Py_None); |
| return Py_None; |
| @@ -1960,7 +1971,7 @@ posix_lchmod(PyObject *self, PyObject *args) |
| res = lchmod(path, i); |
| Py_END_ALLOW_THREADS |
| if (res < 0) |
| - return posix_error_with_allocated_filename(path); |
| + return posix_error_with_allocated_filename("lchmod", path); |
| PyMem_Free(path); |
| Py_RETURN_NONE; |
| } |
| @@ -1985,7 +1996,7 @@ posix_chflags(PyObject *self, PyObject *args) |
| res = chflags(path, flags); |
| Py_END_ALLOW_THREADS |
| if (res < 0) |
| - return posix_error_with_allocated_filename(path); |
| + return posix_error_with_allocated_filename("chflags", path); |
| PyMem_Free(path); |
| Py_INCREF(Py_None); |
| return Py_None; |
| @@ -2011,7 +2022,7 @@ posix_lchflags(PyObject *self, PyObject *args) |
| res = lchflags(path, flags); |
| Py_END_ALLOW_THREADS |
| if (res < 0) |
| - return posix_error_with_allocated_filename(path); |
| + return posix_error_with_allocated_filename("lchflags", path); |
| PyMem_Free(path); |
| Py_INCREF(Py_None); |
| return Py_None; |
| @@ -2082,7 +2093,7 @@ posix_chown(PyObject *self, PyObject *args) |
| res = chown(path, uid, gid); |
| Py_END_ALLOW_THREADS |
| if (res < 0) |
| - return posix_error_with_allocated_filename(path); |
| + return posix_error_with_allocated_filename("chown", path); |
| PyMem_Free(path); |
| Py_INCREF(Py_None); |
| return Py_None; |
| @@ -2137,7 +2148,7 @@ posix_lchown(PyObject *self, PyObject *args) |
| res = lchown(path, uid, gid); |
| Py_END_ALLOW_THREADS |
| if (res < 0) |
| - return posix_error_with_allocated_filename(path); |
| + return posix_error_with_allocated_filename("lchown", path); |
| PyMem_Free(path); |
| Py_INCREF(Py_None); |
| return Py_None; |
| @@ -2532,7 +2543,7 @@ posix_listdir(PyObject *self, PyObject *args) |
| dirp = opendir(name); |
| Py_END_ALLOW_THREADS |
| if (dirp == NULL) { |
| - return posix_error_with_allocated_filename(name); |
| + return posix_error_with_allocated_filename("listdir", name); |
| } |
| if ((d = PyList_New(0)) == NULL) { |
| Py_BEGIN_ALLOW_THREADS |
| @@ -2554,7 +2565,7 @@ posix_listdir(PyObject *self, PyObject *args) |
| closedir(dirp); |
| Py_END_ALLOW_THREADS |
| Py_DECREF(d); |
| - return posix_error_with_allocated_filename(name); |
| + return posix_error_with_allocated_filename("listdir", name); |
| } |
| } |
| if (ep->d_name[0] == '.' && |
| @@ -2714,7 +2725,7 @@ posix_mkdir(PyObject *self, PyObject *args) |
| #endif |
| Py_END_ALLOW_THREADS |
| if (res < 0) |
| - return posix_error_with_allocated_filename(path); |
| + return posix_error_with_allocated_filename("mkdir", path); |
| PyMem_Free(path); |
| Py_INCREF(Py_None); |
| return Py_None; |
| @@ -3113,7 +3124,7 @@ done: |
| #endif /* HAVE_UTIMES */ |
| } |
| if (res < 0) { |
| - return posix_error_with_allocated_filename(path); |
| + return posix_error_with_allocated_filename("utime", path); |
| } |
| PyMem_Free(path); |
| Py_INCREF(Py_None); |
| @@ -3430,7 +3441,7 @@ posix_spawnv(PyObject *self, PyObject *args) |
| } |
| argvlist[argc] = NULL; |
| |
| -#if defined(PYOS_OS2) && defined(PYCC_GCC) |
| +#if (defined(PYOS_OS2) && defined(PYCC_GCC)) || defined(__native_client__) |
| Py_BEGIN_ALLOW_THREADS |
| spawnval = spawnv(mode, path, argvlist); |
| Py_END_ALLOW_THREADS |
| @@ -3575,7 +3586,7 @@ posix_spawnve(PyObject *self, PyObject *args) |
| } |
| envlist[envc] = 0; |
| |
| -#if defined(PYOS_OS2) && defined(PYCC_GCC) |
| +#if (defined(PYOS_OS2) && defined(PYCC_GCC)) || defined(__native_client__) |
| Py_BEGIN_ALLOW_THREADS |
| spawnval = spawnve(mode, path, argvlist, envlist); |
| Py_END_ALLOW_THREADS |
| @@ -6370,7 +6381,7 @@ posix_readlink(PyObject *self, PyObject *args) |
| n = readlink(path, buf, (int) sizeof buf); |
| Py_END_ALLOW_THREADS |
| if (n < 0) |
| - return posix_error_with_allocated_filename(path); |
| + return posix_error_with_allocated_filename("readlink", path); |
| |
| PyMem_Free(path); |
| v = PyString_FromStringAndSize(buf, n); |
| @@ -6616,7 +6627,7 @@ posix_open(PyObject *self, PyObject *args) |
| PyErr_Clear(); |
| #endif |
| |
| - if (!PyArg_ParseTuple(args, "eti|i", |
| + if (!PyArg_ParseTuple(args, "eti|i:open", |
| Py_FileSystemDefaultEncoding, &file, |
| &flag, &mode)) |
| return NULL; |
| @@ -6625,7 +6636,7 @@ posix_open(PyObject *self, PyObject *args) |
| fd = open(file, flag, mode); |
| Py_END_ALLOW_THREADS |
| if (fd < 0) |
| - return posix_error_with_allocated_filename(file); |
| + return posix_error_with_allocated_filename("open", file); |
| PyMem_Free(file); |
| return PyInt_FromLong((long)fd); |
| } |
| @@ -9431,6 +9442,11 @@ all_ins(PyObject *d) |
| if (ins(d, "P_TILDE", (long)P_TILDE)) return -1; |
| if (ins(d, "P_UNRELATED", (long)P_UNRELATED)) return -1; |
| if (ins(d, "P_DEBUGDESC", (long)P_DEBUGDESC)) return -1; |
| +#elif defined(__native_client__) |
| + if (ins(d, "P_WAIT", (long)P_WAIT)) return -1; |
| + if (ins(d, "P_NOWAIT", (long)P_NOWAIT)) return -1; |
| + if (ins(d, "P_OVERLAY", (long)P_OVERLAY)) return -1; |
| + if (ins(d, "P_NOWAITO", (long)P_NOWAITO)) return -1; |
| #else |
| if (ins(d, "P_WAIT", (long)_P_WAIT)) return -1; |
| if (ins(d, "P_NOWAIT", (long)_P_NOWAIT)) return -1; |
| diff --git a/Modules/pwdmodule.c b/Modules/pwdmodule.c |
| --- a/Modules/pwdmodule.c |
| +++ b/Modules/pwdmodule.c |
| @@ -94,6 +94,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 |
| @@ -6,6 +6,20 @@ |
| #include <floatingpoint.h> |
| #endif |
| |
| +#ifdef __native_client__ |
| +#ifdef __arm__ |
| +#define DATA_FILE "_platform_specific/arm/pydata.tar" |
| +#elif defined __i386__ |
| +#define DATA_FILE "_platform_specific/i686/pydata.tar" |
| +#elif defined __x86_64__ |
| +#define DATA_FILE "_platform_specific/x86_64/pydata.tar" |
| +#elif defined __pnacl__ |
| +#define DATA_FILE "pydata.tar" |
| +#else |
| +#error "Unknown arch" |
| +#endif |
| +#endif |
| + |
| int |
| main(int argc, char **argv) |
| { |
| @@ -20,5 +34,11 @@ main(int argc, char **argv) |
| m = fpgetmask(); |
| fpsetmask(m & ~FP_X_OFL); |
| #endif |
| +#ifdef __native_client__ |
| + setvbuf(stdout, NULL, _IOLBF, 0); |
| + setvbuf(stdin, NULL, _IOLBF, 0); |
| + if (nacl_startup_untar(argv[0], DATA_FILE, "/")) |
| + return -1; |
| +#endif |
| return Py_Main(argc, argv); |
| } |
| diff --git a/Modules/readline.c b/Modules/readline.c |
| --- a/Modules/readline.c |
| +++ b/Modules/readline.c |
| @@ -965,7 +965,12 @@ setup_readline(void) |
| /* 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/timemodule.c b/Modules/timemodule.c |
| --- a/Modules/timemodule.c |
| +++ b/Modules/timemodule.c |
| @@ -34,6 +34,11 @@ extern int ftime(struct timeb *); |
| #endif /* MS_WINDOWS */ |
| #endif /* HAVE_FTIME */ |
| |
| +#if defined(__native_client__) && !defined(__GLIBC__) |
| +#define timezone _timezone |
| +#define daylight _daylight |
| +#endif |
| + |
| #if defined(__WATCOMC__) && !defined(__QNX__) |
| #include <i86.h> |
| #else |
| diff --git a/Python/dynload_shlib.c b/Python/dynload_shlib.c |
| --- a/Python/dynload_shlib.c |
| +++ b/Python/dynload_shlib.c |
| @@ -84,6 +84,11 @@ dl_funcptr _PyImport_GetDynLoadFunc(const char *fqname, const char *shortname, |
| PyOS_snprintf(funcname, sizeof(funcname), |
| LEAD_UNDERSCORE "init%.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; |
| @@ -107,6 +112,7 @@ dl_funcptr _PyImport_GetDynLoadFunc(const char *fqname, const char *shortname, |
| #endif |
| } |
| } |
| +#endif |
| |
| #if !(defined(PYOS_OS2) && defined(PYCC_GCC)) |
| dlopenflags = PyThreadState_GET()->interp->dlopenflags; |
| 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/configure b/configure |
| --- a/configure |
| +++ b/configure |
| @@ -2880,6 +2880,12 @@ if test "$cross_compiling" = yes; then |
| { $as_echo "$as_me:${as_lineno-$LINENO}: checking for python interpreter for cross build" >&5 |
| $as_echo_n "checking for python interpreter for cross build... " >&6; } |
| if test -z "$PYTHON_FOR_BUILD"; then |
| + case "$host" in |
| + *-*-nacl*) |
| + interp=$(cd ../../python-host/build_host && pwd)/python.exe |
| + if [ ! -f $interp ]; then interp=$(cd ../../python-host/build_host && pwd)/python; fi |
| + ;; |
| + *) |
| for interp in python$PACKAGE_VERSION python2 python; do |
| which $interp >/dev/null 2>&1 || continue |
| if $interp -c 'import sys;sys.exit(not (sys.version_info[:2] >= (2,7) and sys.version_info[0] < 3))'; then |
| @@ -2887,12 +2893,13 @@ $as_echo_n "checking for python interpreter for cross build... " >&6; } |
| fi |
| interp= |
| done |
| + esac |
| if test x$interp = x; then |
| as_fn_error $? "python$PACKAGE_VERSION interpreter not found" "$LINENO" 5 |
| 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=$(shell test -f pybuilddir.txt && echo $(abs_builddir)/`cat pybuilddir.txt`:)$(abs_srcdir)/Lib:$(abs_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 |
| @@ -3196,6 +3203,9 @@ then |
| # `define_xopen_source' in the case statement below. For the |
| # current supported cross builds, this macro is not adjusted. |
| case "$host" in |
| + *-*-nacl*) |
| + ac_sys_system=NaCl |
| + ;; |
| *-*-linux*) |
| ac_sys_system=Linux |
| ;; |
| @@ -3245,6 +3255,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= |
| ;; |
| @@ -5168,7 +5187,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; } |
| @@ -5966,11 +5989,11 @@ then |
| # debug builds. |
| OPT="-g -O0 -Wall $STRICT_PROTO" |
| else |
| - OPT="-g $WRAP -O3 -Wall $STRICT_PROTO" |
| + OPT="-g $WRAP -O2 -Wall $STRICT_PROTO" |
| fi |
| ;; |
| *) |
| - OPT="-O3 -Wall $STRICT_PROTO" |
| + OPT="-O2 -Wall $STRICT_PROTO" |
| ;; |
| esac |
| case $ac_sys_system in |
| @@ -8270,7 +8293,7 @@ then |
| BLDSHARED="$LDSHARED" |
| fi |
| ;; |
| - Linux*|GNU*|QNX*) |
| + Linux*|GNU*|QNX*|NaCl*) |
| LDSHARED='$(CC) -shared' |
| LDCXXSHARED='$(CXX) -shared';; |
| BSD/OS*/4*) |
| @@ -8344,7 +8367,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*) |
| @@ -8378,7 +8401,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/*) |
| # -u _PyMac_Error is needed to pull in the mac toolbox glue, |
| diff --git a/configure.ac b/configure.ac |
| --- a/configure.ac |
| +++ b/configure.ac |
| @@ -22,6 +22,12 @@ rm -f pybuilddir.txt |
| if test "$cross_compiling" = yes; then |
| AC_MSG_CHECKING([for python interpreter for cross build]) |
| if test -z "$PYTHON_FOR_BUILD"; then |
| + case "$host" in |
| + *-*-nacl*) |
| + interp=$(cd ../../python-host/build_host && pwd)/python.exe |
| + if [ ! -f $interp ]; then interp=$(cd ../../python-host/build_host && pwd)/python; fi |
| + ;; |
| + *) |
| for interp in python$PACKAGE_VERSION python2 python; do |
| which $interp >/dev/null 2>&1 || continue |
| if $interp -c 'import sys;sys.exit(not (sys.version_info@<:@:2@:>@ >= (2,7) and sys.version_info@<:@0@:>@ < 3))'; then |
| @@ -29,11 +35,12 @@ if test "$cross_compiling" = yes; then |
| fi |
| interp= |
| done |
| + esac |
| if test x$interp = x; then |
| AC_MSG_ERROR([python$PACKAGE_VERSION interpreter not found]) |
| fi |
| AC_MSG_RESULT($interp) |
| - 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=$(shell test -f pybuilddir.txt && echo $(abs_builddir)/`cat pybuilddir.txt`:)$(abs_srcdir)/Lib:$(abs_srcdir)/Lib/$(PLATDIR) '$interp |
| fi |
| elif test "$cross_compiling" = maybe; then |
| AC_MSG_ERROR([Cross compiling required --host=HOST-TUPLE and --build=ARCH]) |
| @@ -322,6 +329,9 @@ then |
| *-*-cygwin*) |
| ac_sys_system=Cygwin |
| ;; |
| + *-*-nacl*) |
| + ac_sys_system=NaCl |
| + ;; |
| *) |
| # for now, limit cross builds to known configurations |
| MACHDEP="unknown" |
| @@ -365,6 +375,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= |
| ;; |
| @@ -2036,7 +2055,7 @@ then |
| BLDSHARED="$LDSHARED" |
| fi |
| ;; |
| - Linux*|GNU*|QNX*) |
| + Linux*|GNU*|QNX*|NaCl*) |
| LDSHARED='$(CC) -shared' |
| LDCXXSHARED='$(CXX) -shared';; |
| BSD/OS*/4*) |
| @@ -2108,7 +2127,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*) |
| @@ -2140,7 +2159,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/*) |
| # -u _PyMac_Error is needed to pull in the mac toolbox glue, |