Skip to content
This repository has been archived by the owner on Mar 23, 2023. It is now read-only.

Commit

Permalink
Merge branch 'master' into 290-print-stdout
Browse files Browse the repository at this point in the history
Conflicts:
	lib/sys.py
  • Loading branch information
alanjds committed Jun 10, 2017
2 parents c4bfdf4 + 16b7b4a commit 51164d9
Show file tree
Hide file tree
Showing 48 changed files with 3,999 additions and 249 deletions.
16 changes: 10 additions & 6 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -93,16 +93,20 @@ STDLIB_TESTS := \
re_tests \
sys_test \
tempfile_test \
test/test_tuple \
test/test_bisect \
test/test_colorsys \
test/test_datetime \
test/test_dict \
test/test_list \
test/test_slice \
test/test_string \
test/test_md5 \
test/test_bisect \
test/test_datetime \
test/test_mimetools \
test/test_operator \
test/test_colorsys \
test/test_quopri \
test/test_rfc822 \
test/test_slice \
test/test_string \
test/test_tuple \
test/test_uu \
threading_test \
time_test \
types_test \
Expand Down
8 changes: 4 additions & 4 deletions compiler/expr_visitor_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -188,10 +188,10 @@ def foo():
'12345678901234567890L')
testNumFloat = _MakeLiteralTest('102.1')
testNumFloatOnlyDecimal = _MakeLiteralTest('.5', '0.5')
testNumFloatNoDecimal = _MakeLiteralTest('5.', '5')
testNumFloatSci = _MakeLiteralTest('1e6', '1e+06')
testNumFloatSciCap = _MakeLiteralTest('1E6', '1e+06')
testNumFloatSciCapPlus = _MakeLiteralTest('1E+6', '1e+06')
testNumFloatNoDecimal = _MakeLiteralTest('5.', '5.0')
testNumFloatSci = _MakeLiteralTest('1e6', '1000000.0')
testNumFloatSciCap = _MakeLiteralTest('1E6', '1000000.0')
testNumFloatSciCapPlus = _MakeLiteralTest('1E+6', '1000000.0')
testNumFloatSciMinus = _MakeLiteralTest('1e-06')
testNumComplex = _MakeLiteralTest('3j')

Expand Down
1 change: 1 addition & 0 deletions lib/cStringIO.py
11 changes: 9 additions & 2 deletions lib/os/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,19 @@
import stat as stat_module
import sys
from __go__.io.ioutil import ReadDir
from __go__.os import Chdir, Chmod, Environ, Getwd, Remove, Stat
from __go__.os import (
Chdir, Chmod, Environ, Getpid as getpid, Getwd, Remove, Stat)
from __go__.path.filepath import Separator
from __go__.grumpy import NewFileFromFD
from __go__.runtime import GOOS
from __go__.syscall import Close, SYS_FCNTL, Syscall, F_GETFD
from __go__.time import Second


sep = chr(Separator)
error = OSError # pylint: disable=invalid-name
curdir = "."
curdir = '.'
name = 'posix'


environ = {}
Expand Down Expand Up @@ -120,3 +124,6 @@ def stat(filepath):
if err:
raise OSError(err.Error())
return StatResult(info)


unlink = remove
7 changes: 6 additions & 1 deletion lib/sys.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

from __go__.os import Args
from __go__.grumpy import SysmoduleDict, SysModules, MaxInt, Stdin, Stdout, Stderr # pylint: disable=g-multiple-import
from __go__.runtime import Version
from __go__.runtime import (GOOS as platform, Version)
from __go__.unicode import MaxRune


Expand Down Expand Up @@ -44,6 +44,7 @@
warnoptions = []
# TODO: Support actual byteorder
byteorder = 'little'
version = '2.7.13'


class _Flags(object):
Expand All @@ -69,6 +70,10 @@ class _Flags(object):
flags = _Flags()


def exc_clear():
__frame__().__exc_clear__()


def exc_info():
e, tb = __frame__().__exc_info__() # pylint: disable=undefined-variable
t = None
Expand Down
11 changes: 11 additions & 0 deletions lib/sys_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,17 @@ def TestSysModules():
assert sys.modules['sys'] is not None


def TestExcClear():
try:
raise RuntimeError
except:
assert all(sys.exc_info()), sys.exc_info()
sys.exc_clear()
assert not any(sys.exc_info())
else:
assert False


def TestExcInfoNoException():
assert sys.exc_info() == (None, None, None)

Expand Down
18 changes: 12 additions & 6 deletions lib/threading.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,10 @@ def __init__(self):
self._is_set = False

def set(self):
self._mutex.Lock()
try:
self._is_set = True
finally:
self._mutex.Unlock()
self._cond.Broadcast()
self._set(True)

def clear(self):
self._set(False)

# TODO: Support timeout param.
def wait(self):
Expand All @@ -44,6 +42,14 @@ def wait(self):
self._mutex.Unlock()
return True

def _set(self, is_set):
self._mutex.Lock()
try:
self._is_set = is_set
finally:
self._mutex.Unlock()
self._cond.Broadcast()


class Thread(object):
"""Thread is an activity to be executed concurrently."""
Expand Down
14 changes: 14 additions & 0 deletions lib/threading_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,20 @@ def Target():
e.set()
t.join()
assert target_result == ['ready']
target_result[:] = []
t = threading.Thread(target=Target)
t.start()
t.join()
assert target_result == ['ready']
target_result[:] = []
e.clear()
t = threading.Thread(target=Target)
t.start()
time.sleep(0.1)
assert not target_result
e.set()
t.join()
assert target_result == ['ready']


def TestThread():
Expand Down
5 changes: 3 additions & 2 deletions runtime/builtin_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,7 @@ var builtinTypes = map[*Type]*builtinTypeInfo{
IndexErrorType: {global: true},
IntType: {init: initIntType, global: true},
IOErrorType: {global: true},
KeyboardInterruptType: {global: true},
KeyErrorType: {global: true},
listIteratorType: {init: initListIteratorType},
ListType: {init: initListType, global: true},
Expand Down Expand Up @@ -732,9 +733,9 @@ Outer:
elem, raised := Next(f, iter)
if raised != nil {
if raised.isInstance(StopIterationType) {
f.RestoreExc(nil, nil)
break Outer
}
f.RestoreExc(nil, nil)
return nil, raised
}
elems[i] = elem
Expand Down Expand Up @@ -929,9 +930,9 @@ func zipLongest(f *Frame, args Args) ([][]*Object, *BaseException) {
if raised.isInstance(StopIterationType) {
iters[i] = nil
elems[i] = None
f.RestoreExc(nil, nil)
continue
}
f.RestoreExc(nil, nil)
return nil, raised
}
noItems = false
Expand Down
6 changes: 5 additions & 1 deletion runtime/code.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,11 @@ func (c *Code) Eval(f *Frame, globals *Dict, args Args, kwargs KWArgs) (*Object,
}
} else {
_, tb := f.ExcInfo()
tb = newTraceback(f, tb)
if f.code != nil {
// The root frame has no code object so don't include it
// in the traceback.
tb = newTraceback(f, tb)
}
f.RestoreExc(raised, tb)
}
return ret, raised
Expand Down
Loading

0 comments on commit 51164d9

Please sign in to comment.