Commit Graph

6062 Commits

Author SHA1 Message Date
Steve Shi
742ea0c4fa Reimpl Buffer Protocol and memoryview support ndarray with shape, stride and suboffset (#3340)
* Fix buffer protocol and memoryview

* Fix io and array the right way to use buffer protocol

* fix rebase

* fix memoryview and introduce VecBuffer

* fix deadlock

* fix memoryview avoid double release buffer

* impl ndim buffer support

* first implement nd array for buffer and memoryview

* fix slice adjust_indices

* fix adjust_indices introduct SaturatedSliceIterator

* fix memoryview cmp

* fix adjust_indices positive_order

* fix bug mark passed test

* fix clippy

* fix set_item_slice deadlock, optimize buffer

* Delete @test_113974_tmp

* Remove vec_buffer_type

* rusty names

* impl memoryview multi index

* add comments

Co-authored-by: Jeong YunWon <jeong@youknowone.org>
2021-11-13 07:17:11 +02:00
joohongpark
5ceb2be86e fixed set.{__ror__, __sub__} operator to behave according to type 2021-11-11 16:11:48 +09:00
Noa
96a9d55a62 Merge pull request #3399 from RustPython/custom-signals
Allow sending custom signals to a vm
2021-11-10 14:25:06 -06:00
Jeong YunWon
31f619510f Merge pull request #3425 from deantvv/os-getrandom
os: implement getrandom
2021-11-10 00:52:29 +09:00
Dean Li
b6f266d3b8 os: implement getrandom 2021-11-09 11:33:51 +00:00
jfh
f4030ab1f6 Enable settime for macos. 2021-11-08 18:28:02 +02:00
Jeong YunWon
b80cec7798 Merge pull request #3423 from deantvv/os-waitstatus-to-exitcode
os: implement `os.waitstatus_to_exitcode`
2021-11-07 00:00:28 +09:00
Jeong YunWon
820a67cb7e Merge pull request #3417 from moreal/as-mapping-str
Implement `AsMapping` for `PyStr`
2021-11-06 22:36:02 +09:00
Dean Li
a762ce5426 os: implement waitstatus_to_exitcode 2021-11-06 21:04:13 +08:00
Jim Fasarakis-Hilliard
625886f339 Merge pull request #3420 from zetwhite/pos_only_arg
fix error message for checking number of positional arguments
2021-11-06 12:10:57 +02:00
Jeong YunWon
98e3d26906 Use PyPathLike::into_cstring 2021-11-06 17:17:00 +09:00
zetwhite
0523a57195 fix error message for checking number of positional arguments 2021-11-06 17:00:20 +09:00
Moreal
276608233e Implement AsMapping for PyStr 2021-11-06 15:46:41 +09:00
Dean Li
04821ce730 os: fix posix_spawn exception 2021-11-06 14:40:54 +08:00
Jeong YunWon
40fd9c2683 Merge pull request #3406 from DimitrisJim/clean_time
Clean up monotonic/perf_counter invocations.
2021-11-06 14:26:21 +09:00
Jeong YunWon
8933c7bd1e Merge pull request #3414 from DimitrisJim/operator_classes_cleanup
Clean up slots in operator.
2021-11-06 14:22:55 +09:00
Jim Fasarakis-Hilliard
2c2656dc7a Raise value error on large precision values for float, int __format__ (#3415) 2021-11-05 21:15:49 +02:00
Daniel Watkins
14b4f0092f cformat.rs: fix remaining test_format.test_common_format failures (#3405)
* cformat.rs: refactor fill_string to take fill_with_precision

This allows it to be used with both self.min_field_width and
self.precision, which is necessary for padding out %ds with precision.

* cformat.rs: zero-pad %d entries using precision

This matches CPython's behaviour.

* cformat.rs: don't left-adjust when filling with precision

That will always be prepending 0s to %d arguments, the LEFT_ADJUST flag
will be used by a later call to `fill_string` with the 0-filled string
as the `string` param.

* floats: handle alternate form of general formatting

* cformat.rs: convert width/precision to i32

In CPython, width can be isize but precision can only be i32.  Our
implementation currently assumes the same type for both: as CPython's
tests assert on overflows for precision, but not for width, we use that
size for both.

* test_format: run test_common_format

Except for the line which raises an OverflowError in CPython, because
overflows in Rust (and therefore RustPython) abort the process
immediately.

* test_types: don't expect test_float_to_string to fail

Its string formatting usage now works as expected.
2021-11-05 12:06:58 +02:00
jfh
a3daca0108 Clean up slots in operator. 2021-11-04 22:29:10 +02:00
jfh
a8a3cae61f Remove slot_new for longrange_iterator. 2021-11-04 18:45:50 +02:00
Jeong YunWon
2309e59a72 Merge pull request #3404 from DimitrisJim/genericalias_no_kwargs
Disallow kwargs from genericalias `__new__`.
2021-11-04 19:16:36 +09:00
Jeong YunWon
95bb1a1ffb Merge pull request #3409 from DimitrisJim/check_wasi
Add wasi check to ci.
2021-11-04 16:01:16 +09:00
jfh
25c7d82a86 Add wasi check to ci. 2021-11-04 01:21:24 +02:00
Noa
2c70bf26c3 Move the cfg(debug_assertions) inside the quote!} 2021-11-03 13:29:52 -05:00
Noa
f01a7b17c4 Upgrade nix 2021-11-03 13:28:41 -05:00
Jim Fasarakis-Hilliard
b69cfafad8 Merge pull request #3398 from deantvv/os-error-str-2
os: implement os-error-str according to CPython
2021-11-03 16:53:49 +02:00
jfh
cc3708816f Clean up monotonic/perf_counter invocations. 2021-11-03 13:43:07 +02:00
jfh
ffd7e8cdb7 Disallow kwargs from genericalias new. 2021-11-03 13:35:28 +02:00
Dean Li
db212d80ff os: implement os-error-str according to CPython
As was: "FileNotFoundError: [Errno 2] No such file or directory (os
error 2)"
To be: "FileNotFoundError: [Errno 2] No such file or directory (os
error 2): 'filename' -> 'filename2'"

Reference CPython implementation
```
if (self->filename) {
    if (self->filename2) {
        return PyUnicode_FromFormat("[Errno %S] %S: %R -> %R",
                                    OR_NONE(self->myerrno),
                                    OR_NONE(self->strerror),
                                    self->filename,
                                    self->filename2);
    } else {
        return PyUnicode_FromFormat("[Errno %S] %S: %R",
                                    OR_NONE(self->myerrno),
                                    OR_NONE(self->strerror),
                                    self->filename);
    }
}
if (self->myerrno && self->strerror)
    return PyUnicode_FromFormat("[Errno %S] %S",
                                self->myerrno, self->strerror);
```
2021-11-03 17:30:28 +08:00
Daniel Watkins
9dce9bf0b9 correctly set __module__ and __name__ for builtin exceptions
In CPython's PyErr_NewException[0], the dotted "module.name" passed in is
split on that dot: the content before the dot is set as __module__ in
the created exception class, and the content after it is set as
__name__.

This commit mirrors that behaviour, by introducing a `module` argument
to `PyContext.new_class`: if Some("module_name") is passed, it will be
set as `__module__`.  All exception-creating uses of `new_class` are
updated to pass in their module and class names separately.

[0] https://github.com/python/cpython/blob/main/Python/errors.c#L1082-L1087
2021-11-02 18:28:02 -04:00
Jim Fasarakis-Hilliard
612e943c6c Merge pull request #3394 from Snowapril/fix-ga-param-chaining
Fix `GenericAlias` parameter chaining
2021-11-02 23:37:38 +02:00
Jeong YunWon
93ef12e553 Merge pull request #3401 from coolreader18/stdlib-arrayiter
Don't create an intermediate map for rustpython_stdlib::stdlib_inits
2021-11-02 18:12:28 +09:00
Jeong YunWon
d78347e7ea Merge pull request #3390 from OddBloke/oddbloke/format
cformat.rs: fixes to get two test_format.py tests passing
2021-11-02 18:10:08 +09:00
Jeong YunWon
7b99d13f60 Merge pull request #3050 from RustPython/upd-deps
Run cargo update + upgrade
2021-11-02 17:58:02 +09:00
Noa
a4a1a154e2 Allow sending custom signals to a vm 2021-11-01 22:42:29 -05:00
Noa
a3723462ce Don't create an intermediate map for rustpython_stdlib::stdlib_inits 2021-11-01 22:37:32 -05:00
Noa
401789dbf1 Tidy up signals atomics and such 2021-11-01 21:44:04 -05:00
Daniel Watkins
655bfbc6cf cformat.rs: align exception text with CPython
test_format.py doesn't _fail_ if the text is different, but it does emit
a warning: this fixes those warnings.
2021-11-01 21:34:51 -04:00
Daniel Watkins
4d2747e4b8 cformat.rs: reject %c args > 255 when byte formatting
This matches CPython's behaviour.  Thanks to @DimitrisJim for the
improved implementation here.
2021-11-01 21:34:51 -04:00
Daniel Watkins
1ed3a6ca81 cformat.rs: emit correct "not all arguments" errors for byte formatting
Without this, the code would accept `b"eggs" % b"ham"` and `b"eggs" %
bytearray(b"ham")` because it would detect bytes and bytearray as
mappings (which _are_ permitted to have leftover, unprocessed
arguments).
2021-11-01 21:34:51 -04:00
Daniel Watkins
8594a656c7 cformat.rs: s/string/bytes/ in byte formatting error messages 2021-11-01 21:34:51 -04:00
Daniel Watkins
3e19da8331 cformat.rs: implement b'%a'/b'%r' correctly
Unlike strings, b'%a' and b'%r' are equivalent, and they match the '%a'
behaviour of strings, not '%r'.

Thanks to @youknowone for improving this implementation.
2021-11-01 21:34:51 -04:00
Daniel Watkins
dcc0973b03 cformat.rs: handle bytearrays when formatting b'%c' 2021-11-01 21:34:51 -04:00
Daniel Watkins
380653b6cb cformat.rs: implement %a correctly, using builtins::ascii
The repr() of Unicode strings is the Unicode string, so the previous
code was incorrect for that case (at least).
2021-11-01 21:34:51 -04:00
Daniel Watkins
916f39c2b5 cformat.rs: address memory allocation error with %*s / %.*f
The previous code assumed that, after parsing was complete, both the
padding and the precision integers would always be positive: it
therefore cast them to usize unconditionally.  This meant that when a
negative integer was encountered, it would underflow and attempt to
generate a padded string of around usize::MAX, or a float representation
of that precision: unsurprisingly, these fail to allocate.

For simple format strings (e.g. `%-3s`), this works fine: `-` is
detected as a separate token during parsing, so only the positive
integer (3) is passed through.

However, `%*s` expresses "take the first value as the padding integer,
and the second as the string to be padded" (`"%*s" % (-3, ...)` is
analogous to the previous example).  In this codepath, the parsing does
not handle the padding integer, so it can't strip the leading `-`: the
padding integer is negative.  A negative precision can also be given in
similar fashion, with `"%.*f" % (-3, ...)`.

N.B. This commit does not cause the code to produce the correct _output_
for negative padding integers or precisions provided this way, it
addresses only the crash.
2021-11-01 21:32:48 -04:00
snowapril
ac7bb4bdf4 Add monotonic, perf_counter, get_clock_info for windows
Signed-off-by: snowapril <sinjihng@gmail.com>
2021-11-01 15:20:55 +09:00
Daniel Watkins
34950fdd2a stdlib/posix.rs: fix mknod for MacOS
mknod at isn't available in their libc.
2021-10-31 09:10:35 -04:00
Daniel Watkins
156cf6bc86 stdlib/posix.rs: implement mknod 2021-10-31 09:04:56 -04:00
Jim Fasarakis-Hilliard
1442dd69b4 Merge pull request #3393 from devnexen/netbsd_build_fix
netbsd build fix proposal
2021-10-31 13:35:59 +02:00
snowapril
77cd095b59 fix subs_tvars to working on nested GenericAlias
Signed-off-by: snowapril <sinjihng@gmail.com>
2021-10-31 20:02:10 +09:00