SlideShare a Scribd company logo
RustPython Sprint
How to find & fix a bug?
Example
➜ ~ cd ~/Projects/RustPython
(RustPython) ➜ RustPython git:(master) ✗ RUSTPYTHONPATH=Lib cargo run
Finished dev [unoptimized + debuginfo] target(s) in 0.10s
Running `target/debug/rustpython`
Welcome to the magnificent Rust Python 0.1.0 interpreter 😱 🖖
>>>>> import datetime
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "Lib/datetime.py", line 2100, in <module>
File "Lib/datetime.py", line 2194, in timezone
_maxoffset = timedelta(hours=23, minutes=59)
File "Lib/datetime.py", line 654, in __neg__
-self._microseconds)
File "Lib/datetime.py", line 564, in __new__
assert isinstance(s, int) and 0 <= s < 24*3600
AssertionError
>>>>>
•
Debug
timedelta.__new__ 0 -86340 0 0 0 0 0
divmod in: -86340 86400
divmod out: 0 -86340
<class 'int'> -86340
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "Lib/datetime.py", line 2100, in <module>
File "Lib/datetime.py", line 2194, in timezone
_maxoffset = timedelta(hours=23, minutes=59)
File "Lib/datetime.py", line 654, in __neg__
-self._microseconds)
File "Lib/datetime.py", line 564, in __new__
assert isinstance(s, int) and 0 <= s < 24*3600
AssertionError
>>>>>
•
Add a test case
diff --git a/tests/snippets/builtin_divmod.py b/tests/snippets/
builtin_divmod.py
index 939e1d2d..ce9bdfba 100644
--- a/tests/snippets/builtin_divmod.py
+++ b/tests/snippets/builtin_divmod.py
@@ -3,6 +3,7 @@ from testutils import assert_raises
assert divmod(11, 3) == (3, 2)
assert divmod(8,11) == (0, 8)
assert divmod(0.873, 0.252) == (3.0, 0.11699999999999999)
+assert divmod(-86340, 86400) == (-1, 60)
assert_raises(ZeroDivisionError, lambda: divmod(5, 0), 'divmod
by zero')
assert_raises(ZeroDivisionError, lambda: divmod(5.0, 0.0),
'divmod by zero')
Run test
(RustPython) ➜ RustPython git:(master) ✗ python tests/snippets/
builtin_divmod.py
(RustPython) ➜ RustPython git:(master) ✗ cargo run tests/snippets/
builtin_divmod.py
Finished dev [unoptimized + debuginfo] target(s) in 0.11s
Running `target/debug/rustpython tests/snippets/
builtin_divmod.py`
Traceback (most recent call last):
File "tests/snippets/builtin_divmod.py", line 6, in <module>
assert divmod(-86340, 86400) == (-1, 60)
AssertionError
Watch code
(RustPython) ➜ RustPython git:(master) ✗ vi ./vm/src/obj/objint.rs
…
#[pymethod(name = "__divmod__")]
fn divmod(&self, other: PyObjectRef, vm: &VirtualMachine) -> PyResult {
if objtype::isinstance(&other, &vm.ctx.int_type()) {
let v2 = get_value(&other);
if *v2 != BigInt::zero() {
let (r1, r2) = self.value.div_rem(v2);
Ok(vm
.ctx
.new_tuple(vec![vm.ctx.new_int(r1), vm.ctx.new_int(r2)]))
} else {
Err(vm.new_zero_division_error("integer divmod by zero".to_str
ing()))
}
} else {
Ok(vm.ctx.not_implemented())
}
}
…
Fix - Add divmod()
@@ -739,6 +735,17 @@ fn truediv_ints(vm: &VirtualMachine, i1: &BigInt, i2: &BigInt) -> PyResult
{
}
}
+#[inline]
+fn divmod(vm: &VirtualMachine, i1: &BigInt, i2: &BigInt) -> PyResult<(BigInt, BigInt)> {
+ if i2.is_zero() {
+ Err(vm.new_zero_division_error("integer division by zero".to_string()))
+ } else {
+ let modulo = (i1 % i2 + i2) % i2;
+ let division = (i1 - &modulo) / i2;
+ Ok((division, modulo))
+ }
+}
+
pub fn init(context: &PyContext) {
PyInt::extend_class(context, &context.int_type);
extend_class!(context, &context.int_type, {
Fix - bugfix
diff --git a/vm/src/obj/objint.rs b/vm/src/obj/objint.rs
index 000dcafd..f90d069a 100644
--- a/vm/src/obj/objint.rs
+++ b/vm/src/obj/objint.rs
@@ -405,14 +405,10 @@ impl PyInt {
fn divmod(&self, other: PyObjectRef, vm: &VirtualMachine) -> PyResult {
if objtype::isinstance(&other, &vm.ctx.int_type()) {
let v2 = get_value(&other);
- if *v2 != BigInt::zero() {
- let (r1, r2) = self.value.div_rem(v2);
- Ok(vm
- .ctx
- .new_tuple(vec![vm.ctx.new_int(r1), vm.ctx.new_int(r2)]))
- } else {
- Err(vm.new_zero_division_error("integer divmod by zero".to_string()))
- }
+ let (div, modulo) = divmod(vm, &self.value, v2)?;
+ Ok(vm
+ .ctx
+ .new_tuple(vec![vm.ctx.new_int(div), vm.ctx.new_int(modulo)]))
} else {
Ok(vm.ctx.not_implemented())
}
Pull request
(RustPython) ➜ RustPython git:(master) ✗ git push origin master:fix-divmod
Enumerating objects: 36, done.
Counting objects: 100% (36/36), done.
Delta compression using up to 12 threads.
Compressing objects: 100% (27/27), done.
Writing objects: 100% (27/27), 2.50 KiB | 2.50 MiB/s, done.
Total 27 (delta 24), reused 0 (delta 0)
remote: Resolving deltas: 100% (24/24), completed with 9 local objects.
remote:
remote: Create a pull request for 'fix-divmod' on GitHub by visiting:
remote: https://github.com/youknowone/RustPython/pull/new/fix-divmod
remote:
To https://github.com/youknowone/RustPython.git
* [new branch] master -> fix-divmod
Pull request
(RustPython) ➜ RustPython git:(master) ✗ git push origin master:fix-divmod
Enumerating objects: 36, done.
Counting objects: 100% (36/36), done.
Delta compression using up to 12 threads.
Compressing objects: 100% (27/27), done.
Writing objects: 100% (27/27), 2.50 KiB | 2.50 MiB/s, done.
Total 27 (delta 24), reused 0 (delta 0)
remote: Resolving deltas: 100% (24/24), completed with 9 local objects.
remote:
remote: Create a pull request for 'fix-divmod' on GitHub by visiting:
remote: https://github.com/youknowone/RustPython/pull/new/fix-divmod
remote:
To https://github.com/youknowone/RustPython.git
* [new branch] master -> fix-divmod
Pull request
Original issue
(RustPython) ➜ RustPython git:(master) ✗ RUSTPYTHONPATH=Lib cargo run
Compiling rustpython-vm v0.1.0 (/Users/youknowone/Projects/
RustPython/vm)
Compiling rustpython v0.1.0 (/Users/youknowone/Projects/RustPython)
Finished dev [unoptimized + debuginfo] target(s) in 15.14s
Running `target/debug/rustpython`
Welcome to the magnificent Rust Python 0.1.0 interpreter 😱 🖖
>>>>> import datetime
divmod in: 0 86400
divmod out: 0 0
divmod in: 86399 86400
divmod out: 0 86399
divmod in: 86340 86400
divmod out: 0 86340
divmod in: -86340 86400
divmod out: -1 60
divmod in: 0 86400
divmod out: 0 0
>>>>>
😱 해결!
보통 이런 일은 잘 없으니

기대하지 맙시다 ㅋㅋㅋㅋ

More Related Content

What's hot

Go memory
Go memoryGo memory
Go memory
jgrahamc
 
Cluj Big Data Meetup - Big Data in Practice
Cluj Big Data Meetup - Big Data in PracticeCluj Big Data Meetup - Big Data in Practice
Cluj Big Data Meetup - Big Data in Practice
Steffen Wenz
 
Cluj.py Meetup: Extending Python in C
Cluj.py Meetup: Extending Python in CCluj.py Meetup: Extending Python in C
Cluj.py Meetup: Extending Python in C
Steffen Wenz
 
Go debugging and troubleshooting tips - from real life lessons at SignalFx
Go debugging and troubleshooting tips - from real life lessons at SignalFxGo debugging and troubleshooting tips - from real life lessons at SignalFx
Go debugging and troubleshooting tips - from real life lessons at SignalFx
SignalFx
 
Go Profiling - John Graham-Cumming
Go Profiling - John Graham-Cumming Go Profiling - John Graham-Cumming
Go Profiling - John Graham-Cumming Cloudflare
 
"Metrics: Where and How", Vsevolod Polyakov
"Metrics: Where and How", Vsevolod Polyakov"Metrics: Where and How", Vsevolod Polyakov
"Metrics: Where and How", Vsevolod Polyakov
Yulia Shcherbachova
 
RestMQ - HTTP/Redis based Message Queue
RestMQ - HTTP/Redis based Message QueueRestMQ - HTTP/Redis based Message Queue
RestMQ - HTTP/Redis based Message Queue
Gleicon Moraes
 
Building a DSL with GraalVM (VoxxedDays Luxembourg)
Building a DSL with GraalVM (VoxxedDays Luxembourg)Building a DSL with GraalVM (VoxxedDays Luxembourg)
Building a DSL with GraalVM (VoxxedDays Luxembourg)
Maarten Mulders
 
Why learn Internals?
Why learn Internals?Why learn Internals?
Why learn Internals?
Shaul Rosenzwieg
 
Deep dumpster diving 2010
Deep dumpster diving 2010Deep dumpster diving 2010
Deep dumpster diving 2010RonnBlack
 
Developing High Performance Application with Aerospike & Go
Developing High Performance Application with Aerospike & GoDeveloping High Performance Application with Aerospike & Go
Developing High Performance Application with Aerospike & Go
Chris Stivers
 
NS2: Binding C++ and OTcl variables
NS2: Binding C++ and OTcl variablesNS2: Binding C++ and OTcl variables
NS2: Binding C++ and OTcl variablesTeerawat Issariyakul
 
Timur Shemsedinov "Пишу на колбеках, а что... (Асинхронное программирование)"
Timur Shemsedinov "Пишу на колбеках, а что... (Асинхронное программирование)"Timur Shemsedinov "Пишу на колбеках, а что... (Асинхронное программирование)"
Timur Shemsedinov "Пишу на колбеках, а что... (Асинхронное программирование)"
OdessaJS Conf
 
Ntp cheat sheet
Ntp cheat sheetNtp cheat sheet
Ntp cheat sheet
csystemltd
 
Nginx-lua
Nginx-luaNginx-lua
Yurii Shevtsov "V8 + libuv = Node.js. Under the hood"
Yurii Shevtsov "V8 + libuv = Node.js. Under the hood"Yurii Shevtsov "V8 + libuv = Node.js. Under the hood"
Yurii Shevtsov "V8 + libuv = Node.js. Under the hood"
OdessaJS Conf
 
C c++-meetup-1nov2017-autofdo
C c++-meetup-1nov2017-autofdoC c++-meetup-1nov2017-autofdo
C c++-meetup-1nov2017-autofdo
Kim Phillips
 
Virtual machine and javascript engine
Virtual machine and javascript engineVirtual machine and javascript engine
Virtual machine and javascript engine
Duoyi Wu
 
Go Concurrency
Go ConcurrencyGo Concurrency
Go Concurrency
jgrahamc
 
Full Stack Clojure
Full Stack ClojureFull Stack Clojure
Full Stack Clojure
Michiel Borkent
 

What's hot (20)

Go memory
Go memoryGo memory
Go memory
 
Cluj Big Data Meetup - Big Data in Practice
Cluj Big Data Meetup - Big Data in PracticeCluj Big Data Meetup - Big Data in Practice
Cluj Big Data Meetup - Big Data in Practice
 
Cluj.py Meetup: Extending Python in C
Cluj.py Meetup: Extending Python in CCluj.py Meetup: Extending Python in C
Cluj.py Meetup: Extending Python in C
 
Go debugging and troubleshooting tips - from real life lessons at SignalFx
Go debugging and troubleshooting tips - from real life lessons at SignalFxGo debugging and troubleshooting tips - from real life lessons at SignalFx
Go debugging and troubleshooting tips - from real life lessons at SignalFx
 
Go Profiling - John Graham-Cumming
Go Profiling - John Graham-Cumming Go Profiling - John Graham-Cumming
Go Profiling - John Graham-Cumming
 
"Metrics: Where and How", Vsevolod Polyakov
"Metrics: Where and How", Vsevolod Polyakov"Metrics: Where and How", Vsevolod Polyakov
"Metrics: Where and How", Vsevolod Polyakov
 
RestMQ - HTTP/Redis based Message Queue
RestMQ - HTTP/Redis based Message QueueRestMQ - HTTP/Redis based Message Queue
RestMQ - HTTP/Redis based Message Queue
 
Building a DSL with GraalVM (VoxxedDays Luxembourg)
Building a DSL with GraalVM (VoxxedDays Luxembourg)Building a DSL with GraalVM (VoxxedDays Luxembourg)
Building a DSL with GraalVM (VoxxedDays Luxembourg)
 
Why learn Internals?
Why learn Internals?Why learn Internals?
Why learn Internals?
 
Deep dumpster diving 2010
Deep dumpster diving 2010Deep dumpster diving 2010
Deep dumpster diving 2010
 
Developing High Performance Application with Aerospike & Go
Developing High Performance Application with Aerospike & GoDeveloping High Performance Application with Aerospike & Go
Developing High Performance Application with Aerospike & Go
 
NS2: Binding C++ and OTcl variables
NS2: Binding C++ and OTcl variablesNS2: Binding C++ and OTcl variables
NS2: Binding C++ and OTcl variables
 
Timur Shemsedinov "Пишу на колбеках, а что... (Асинхронное программирование)"
Timur Shemsedinov "Пишу на колбеках, а что... (Асинхронное программирование)"Timur Shemsedinov "Пишу на колбеках, а что... (Асинхронное программирование)"
Timur Shemsedinov "Пишу на колбеках, а что... (Асинхронное программирование)"
 
Ntp cheat sheet
Ntp cheat sheetNtp cheat sheet
Ntp cheat sheet
 
Nginx-lua
Nginx-luaNginx-lua
Nginx-lua
 
Yurii Shevtsov "V8 + libuv = Node.js. Under the hood"
Yurii Shevtsov "V8 + libuv = Node.js. Under the hood"Yurii Shevtsov "V8 + libuv = Node.js. Under the hood"
Yurii Shevtsov "V8 + libuv = Node.js. Under the hood"
 
C c++-meetup-1nov2017-autofdo
C c++-meetup-1nov2017-autofdoC c++-meetup-1nov2017-autofdo
C c++-meetup-1nov2017-autofdo
 
Virtual machine and javascript engine
Virtual machine and javascript engineVirtual machine and javascript engine
Virtual machine and javascript engine
 
Go Concurrency
Go ConcurrencyGo Concurrency
Go Concurrency
 
Full Stack Clojure
Full Stack ClojureFull Stack Clojure
Full Stack Clojure
 

Similar to PyCon KR 2019 sprint - RustPython by example

Rubinius @ RubyAndRails2010
Rubinius @ RubyAndRails2010Rubinius @ RubyAndRails2010
Rubinius @ RubyAndRails2010Dirkjan Bussink
 
DevOps(4) : Ansible(2) - (MOSG)
DevOps(4) : Ansible(2) - (MOSG)DevOps(4) : Ansible(2) - (MOSG)
DevOps(4) : Ansible(2) - (MOSG)
Soshi Nemoto
 
Goptuna Distributed Bayesian Optimization Framework at Go Conference 2019 Autumn
Goptuna Distributed Bayesian Optimization Framework at Go Conference 2019 AutumnGoptuna Distributed Bayesian Optimization Framework at Go Conference 2019 Autumn
Goptuna Distributed Bayesian Optimization Framework at Go Conference 2019 Autumn
Masashi Shibata
 
Python GTK (Hacking Camp)
Python GTK (Hacking Camp)Python GTK (Hacking Camp)
Python GTK (Hacking Camp)Yuren Ju
 
PythonBrasil[8] - CPython for dummies
PythonBrasil[8] - CPython for dummiesPythonBrasil[8] - CPython for dummies
PythonBrasil[8] - CPython for dummies
Tatiana Al-Chueyr
 
What's new in Python 3.11
What's new in Python 3.11What's new in Python 3.11
What's new in Python 3.11
Henry Schreiner
 
Python-GTK
Python-GTKPython-GTK
Python-GTKYuren Ju
 
Improving go-git performance
Improving go-git performanceImproving go-git performance
Improving go-git performance
source{d}
 
Bytes in the Machine: Inside the CPython interpreter
Bytes in the Machine: Inside the CPython interpreterBytes in the Machine: Inside the CPython interpreter
Bytes in the Machine: Inside the CPython interpreter
akaptur
 
Pledge in OpenBSD
Pledge in OpenBSDPledge in OpenBSD
Pledge in OpenBSD
Giovanni Bechis
 
Silicon Valley JUG: JVM Mechanics
Silicon Valley JUG: JVM MechanicsSilicon Valley JUG: JVM Mechanics
Silicon Valley JUG: JVM Mechanics
Azul Systems, Inc.
 
Python for Penetration testers
Python for Penetration testersPython for Penetration testers
Python for Penetration testers
Christian Martorella
 
Puppet at Opera Sofware - PuppetCamp Oslo 2013
Puppet at Opera Sofware - PuppetCamp Oslo 2013Puppet at Opera Sofware - PuppetCamp Oslo 2013
Puppet at Opera Sofware - PuppetCamp Oslo 2013
Cosimo Streppone
 
Using Puppet to Create a Dynamic Network - PuppetConf 2013
Using Puppet to Create a Dynamic Network - PuppetConf 2013Using Puppet to Create a Dynamic Network - PuppetConf 2013
Using Puppet to Create a Dynamic Network - PuppetConf 2013
Puppet
 
Building a DSL with GraalVM (CodeOne)
Building a DSL with GraalVM (CodeOne)Building a DSL with GraalVM (CodeOne)
Building a DSL with GraalVM (CodeOne)
Maarten Mulders
 
JVM Mechanics: When Does the JVM JIT & Deoptimize?
JVM Mechanics: When Does the JVM JIT & Deoptimize?JVM Mechanics: When Does the JVM JIT & Deoptimize?
JVM Mechanics: When Does the JVM JIT & Deoptimize?
Doug Hawkins
 
Start Wrap Episode 11: A New Rope
Start Wrap Episode 11: A New RopeStart Wrap Episode 11: A New Rope
Start Wrap Episode 11: A New Rope
Yung-Yu Chen
 
Yevhen Tatarynov "From POC to High-Performance .NET applications"
Yevhen Tatarynov "From POC to High-Performance .NET applications"Yevhen Tatarynov "From POC to High-Performance .NET applications"
Yevhen Tatarynov "From POC to High-Performance .NET applications"
LogeekNightUkraine
 
RR & Docker @ MuensteR Meetup (Sep 2017)
RR & Docker @ MuensteR Meetup (Sep 2017)RR & Docker @ MuensteR Meetup (Sep 2017)
RR & Docker @ MuensteR Meetup (Sep 2017)
Daniel Nüst
 

Similar to PyCon KR 2019 sprint - RustPython by example (20)

Rubinius @ RubyAndRails2010
Rubinius @ RubyAndRails2010Rubinius @ RubyAndRails2010
Rubinius @ RubyAndRails2010
 
Intro django
Intro djangoIntro django
Intro django
 
DevOps(4) : Ansible(2) - (MOSG)
DevOps(4) : Ansible(2) - (MOSG)DevOps(4) : Ansible(2) - (MOSG)
DevOps(4) : Ansible(2) - (MOSG)
 
Goptuna Distributed Bayesian Optimization Framework at Go Conference 2019 Autumn
Goptuna Distributed Bayesian Optimization Framework at Go Conference 2019 AutumnGoptuna Distributed Bayesian Optimization Framework at Go Conference 2019 Autumn
Goptuna Distributed Bayesian Optimization Framework at Go Conference 2019 Autumn
 
Python GTK (Hacking Camp)
Python GTK (Hacking Camp)Python GTK (Hacking Camp)
Python GTK (Hacking Camp)
 
PythonBrasil[8] - CPython for dummies
PythonBrasil[8] - CPython for dummiesPythonBrasil[8] - CPython for dummies
PythonBrasil[8] - CPython for dummies
 
What's new in Python 3.11
What's new in Python 3.11What's new in Python 3.11
What's new in Python 3.11
 
Python-GTK
Python-GTKPython-GTK
Python-GTK
 
Improving go-git performance
Improving go-git performanceImproving go-git performance
Improving go-git performance
 
Bytes in the Machine: Inside the CPython interpreter
Bytes in the Machine: Inside the CPython interpreterBytes in the Machine: Inside the CPython interpreter
Bytes in the Machine: Inside the CPython interpreter
 
Pledge in OpenBSD
Pledge in OpenBSDPledge in OpenBSD
Pledge in OpenBSD
 
Silicon Valley JUG: JVM Mechanics
Silicon Valley JUG: JVM MechanicsSilicon Valley JUG: JVM Mechanics
Silicon Valley JUG: JVM Mechanics
 
Python for Penetration testers
Python for Penetration testersPython for Penetration testers
Python for Penetration testers
 
Puppet at Opera Sofware - PuppetCamp Oslo 2013
Puppet at Opera Sofware - PuppetCamp Oslo 2013Puppet at Opera Sofware - PuppetCamp Oslo 2013
Puppet at Opera Sofware - PuppetCamp Oslo 2013
 
Using Puppet to Create a Dynamic Network - PuppetConf 2013
Using Puppet to Create a Dynamic Network - PuppetConf 2013Using Puppet to Create a Dynamic Network - PuppetConf 2013
Using Puppet to Create a Dynamic Network - PuppetConf 2013
 
Building a DSL with GraalVM (CodeOne)
Building a DSL with GraalVM (CodeOne)Building a DSL with GraalVM (CodeOne)
Building a DSL with GraalVM (CodeOne)
 
JVM Mechanics: When Does the JVM JIT & Deoptimize?
JVM Mechanics: When Does the JVM JIT & Deoptimize?JVM Mechanics: When Does the JVM JIT & Deoptimize?
JVM Mechanics: When Does the JVM JIT & Deoptimize?
 
Start Wrap Episode 11: A New Rope
Start Wrap Episode 11: A New RopeStart Wrap Episode 11: A New Rope
Start Wrap Episode 11: A New Rope
 
Yevhen Tatarynov "From POC to High-Performance .NET applications"
Yevhen Tatarynov "From POC to High-Performance .NET applications"Yevhen Tatarynov "From POC to High-Performance .NET applications"
Yevhen Tatarynov "From POC to High-Performance .NET applications"
 
RR & Docker @ MuensteR Meetup (Sep 2017)
RR & Docker @ MuensteR Meetup (Sep 2017)RR & Docker @ MuensteR Meetup (Sep 2017)
RR & Docker @ MuensteR Meetup (Sep 2017)
 

Recently uploaded

CFD Simulation of By-pass Flow in a HRSG module by R&R Consult.pptx
CFD Simulation of By-pass Flow in a HRSG module by R&R Consult.pptxCFD Simulation of By-pass Flow in a HRSG module by R&R Consult.pptx
CFD Simulation of By-pass Flow in a HRSG module by R&R Consult.pptx
R&R Consult
 
block diagram and signal flow graph representation
block diagram and signal flow graph representationblock diagram and signal flow graph representation
block diagram and signal flow graph representation
Divya Somashekar
 
ethical hacking-mobile hacking methods.ppt
ethical hacking-mobile hacking methods.pptethical hacking-mobile hacking methods.ppt
ethical hacking-mobile hacking methods.ppt
Jayaprasanna4
 
weather web application report.pdf
weather web application report.pdfweather web application report.pdf
weather web application report.pdf
Pratik Pawar
 
Quality defects in TMT Bars, Possible causes and Potential Solutions.
Quality defects in TMT Bars, Possible causes and Potential Solutions.Quality defects in TMT Bars, Possible causes and Potential Solutions.
Quality defects in TMT Bars, Possible causes and Potential Solutions.
PrashantGoswami42
 
WATER CRISIS and its solutions-pptx 1234
WATER CRISIS and its solutions-pptx 1234WATER CRISIS and its solutions-pptx 1234
WATER CRISIS and its solutions-pptx 1234
AafreenAbuthahir2
 
COLLEGE BUS MANAGEMENT SYSTEM PROJECT REPORT.pdf
COLLEGE BUS MANAGEMENT SYSTEM PROJECT REPORT.pdfCOLLEGE BUS MANAGEMENT SYSTEM PROJECT REPORT.pdf
COLLEGE BUS MANAGEMENT SYSTEM PROJECT REPORT.pdf
Kamal Acharya
 
在线办理(ANU毕业证书)澳洲国立大学毕业证录取通知书一模一样
在线办理(ANU毕业证书)澳洲国立大学毕业证录取通知书一模一样在线办理(ANU毕业证书)澳洲国立大学毕业证录取通知书一模一样
在线办理(ANU毕业证书)澳洲国立大学毕业证录取通知书一模一样
obonagu
 
ethical hacking in wireless-hacking1.ppt
ethical hacking in wireless-hacking1.pptethical hacking in wireless-hacking1.ppt
ethical hacking in wireless-hacking1.ppt
Jayaprasanna4
 
Industrial Training at Shahjalal Fertilizer Company Limited (SFCL)
Industrial Training at Shahjalal Fertilizer Company Limited (SFCL)Industrial Training at Shahjalal Fertilizer Company Limited (SFCL)
Industrial Training at Shahjalal Fertilizer Company Limited (SFCL)
MdTanvirMahtab2
 
Courier management system project report.pdf
Courier management system project report.pdfCourier management system project report.pdf
Courier management system project report.pdf
Kamal Acharya
 
Automobile Management System Project Report.pdf
Automobile Management System Project Report.pdfAutomobile Management System Project Report.pdf
Automobile Management System Project Report.pdf
Kamal Acharya
 
ASME IX(9) 2007 Full Version .pdf
ASME IX(9)  2007 Full Version       .pdfASME IX(9)  2007 Full Version       .pdf
ASME IX(9) 2007 Full Version .pdf
AhmedHussein950959
 
NO1 Uk best vashikaran specialist in delhi vashikaran baba near me online vas...
NO1 Uk best vashikaran specialist in delhi vashikaran baba near me online vas...NO1 Uk best vashikaran specialist in delhi vashikaran baba near me online vas...
NO1 Uk best vashikaran specialist in delhi vashikaran baba near me online vas...
Amil Baba Dawood bangali
 
Pile Foundation by Venkatesh Taduvai (Sub Geotechnical Engineering II)-conver...
Pile Foundation by Venkatesh Taduvai (Sub Geotechnical Engineering II)-conver...Pile Foundation by Venkatesh Taduvai (Sub Geotechnical Engineering II)-conver...
Pile Foundation by Venkatesh Taduvai (Sub Geotechnical Engineering II)-conver...
AJAYKUMARPUND1
 
Event Management System Vb Net Project Report.pdf
Event Management System Vb Net  Project Report.pdfEvent Management System Vb Net  Project Report.pdf
Event Management System Vb Net Project Report.pdf
Kamal Acharya
 
Design and Analysis of Algorithms-DP,Backtracking,Graphs,B&B
Design and Analysis of Algorithms-DP,Backtracking,Graphs,B&BDesign and Analysis of Algorithms-DP,Backtracking,Graphs,B&B
Design and Analysis of Algorithms-DP,Backtracking,Graphs,B&B
Sreedhar Chowdam
 
power quality voltage fluctuation UNIT - I.pptx
power quality voltage fluctuation UNIT - I.pptxpower quality voltage fluctuation UNIT - I.pptx
power quality voltage fluctuation UNIT - I.pptx
ViniHema
 
Water Industry Process Automation and Control Monthly - May 2024.pdf
Water Industry Process Automation and Control Monthly - May 2024.pdfWater Industry Process Automation and Control Monthly - May 2024.pdf
Water Industry Process Automation and Control Monthly - May 2024.pdf
Water Industry Process Automation & Control
 
Halogenation process of chemical process industries
Halogenation process of chemical process industriesHalogenation process of chemical process industries
Halogenation process of chemical process industries
MuhammadTufail242431
 

Recently uploaded (20)

CFD Simulation of By-pass Flow in a HRSG module by R&R Consult.pptx
CFD Simulation of By-pass Flow in a HRSG module by R&R Consult.pptxCFD Simulation of By-pass Flow in a HRSG module by R&R Consult.pptx
CFD Simulation of By-pass Flow in a HRSG module by R&R Consult.pptx
 
block diagram and signal flow graph representation
block diagram and signal flow graph representationblock diagram and signal flow graph representation
block diagram and signal flow graph representation
 
ethical hacking-mobile hacking methods.ppt
ethical hacking-mobile hacking methods.pptethical hacking-mobile hacking methods.ppt
ethical hacking-mobile hacking methods.ppt
 
weather web application report.pdf
weather web application report.pdfweather web application report.pdf
weather web application report.pdf
 
Quality defects in TMT Bars, Possible causes and Potential Solutions.
Quality defects in TMT Bars, Possible causes and Potential Solutions.Quality defects in TMT Bars, Possible causes and Potential Solutions.
Quality defects in TMT Bars, Possible causes and Potential Solutions.
 
WATER CRISIS and its solutions-pptx 1234
WATER CRISIS and its solutions-pptx 1234WATER CRISIS and its solutions-pptx 1234
WATER CRISIS and its solutions-pptx 1234
 
COLLEGE BUS MANAGEMENT SYSTEM PROJECT REPORT.pdf
COLLEGE BUS MANAGEMENT SYSTEM PROJECT REPORT.pdfCOLLEGE BUS MANAGEMENT SYSTEM PROJECT REPORT.pdf
COLLEGE BUS MANAGEMENT SYSTEM PROJECT REPORT.pdf
 
在线办理(ANU毕业证书)澳洲国立大学毕业证录取通知书一模一样
在线办理(ANU毕业证书)澳洲国立大学毕业证录取通知书一模一样在线办理(ANU毕业证书)澳洲国立大学毕业证录取通知书一模一样
在线办理(ANU毕业证书)澳洲国立大学毕业证录取通知书一模一样
 
ethical hacking in wireless-hacking1.ppt
ethical hacking in wireless-hacking1.pptethical hacking in wireless-hacking1.ppt
ethical hacking in wireless-hacking1.ppt
 
Industrial Training at Shahjalal Fertilizer Company Limited (SFCL)
Industrial Training at Shahjalal Fertilizer Company Limited (SFCL)Industrial Training at Shahjalal Fertilizer Company Limited (SFCL)
Industrial Training at Shahjalal Fertilizer Company Limited (SFCL)
 
Courier management system project report.pdf
Courier management system project report.pdfCourier management system project report.pdf
Courier management system project report.pdf
 
Automobile Management System Project Report.pdf
Automobile Management System Project Report.pdfAutomobile Management System Project Report.pdf
Automobile Management System Project Report.pdf
 
ASME IX(9) 2007 Full Version .pdf
ASME IX(9)  2007 Full Version       .pdfASME IX(9)  2007 Full Version       .pdf
ASME IX(9) 2007 Full Version .pdf
 
NO1 Uk best vashikaran specialist in delhi vashikaran baba near me online vas...
NO1 Uk best vashikaran specialist in delhi vashikaran baba near me online vas...NO1 Uk best vashikaran specialist in delhi vashikaran baba near me online vas...
NO1 Uk best vashikaran specialist in delhi vashikaran baba near me online vas...
 
Pile Foundation by Venkatesh Taduvai (Sub Geotechnical Engineering II)-conver...
Pile Foundation by Venkatesh Taduvai (Sub Geotechnical Engineering II)-conver...Pile Foundation by Venkatesh Taduvai (Sub Geotechnical Engineering II)-conver...
Pile Foundation by Venkatesh Taduvai (Sub Geotechnical Engineering II)-conver...
 
Event Management System Vb Net Project Report.pdf
Event Management System Vb Net  Project Report.pdfEvent Management System Vb Net  Project Report.pdf
Event Management System Vb Net Project Report.pdf
 
Design and Analysis of Algorithms-DP,Backtracking,Graphs,B&B
Design and Analysis of Algorithms-DP,Backtracking,Graphs,B&BDesign and Analysis of Algorithms-DP,Backtracking,Graphs,B&B
Design and Analysis of Algorithms-DP,Backtracking,Graphs,B&B
 
power quality voltage fluctuation UNIT - I.pptx
power quality voltage fluctuation UNIT - I.pptxpower quality voltage fluctuation UNIT - I.pptx
power quality voltage fluctuation UNIT - I.pptx
 
Water Industry Process Automation and Control Monthly - May 2024.pdf
Water Industry Process Automation and Control Monthly - May 2024.pdfWater Industry Process Automation and Control Monthly - May 2024.pdf
Water Industry Process Automation and Control Monthly - May 2024.pdf
 
Halogenation process of chemical process industries
Halogenation process of chemical process industriesHalogenation process of chemical process industries
Halogenation process of chemical process industries
 

PyCon KR 2019 sprint - RustPython by example

  • 1. RustPython Sprint How to find & fix a bug?
  • 2. Example ➜ ~ cd ~/Projects/RustPython (RustPython) ➜ RustPython git:(master) ✗ RUSTPYTHONPATH=Lib cargo run Finished dev [unoptimized + debuginfo] target(s) in 0.10s Running `target/debug/rustpython` Welcome to the magnificent Rust Python 0.1.0 interpreter 😱 🖖 >>>>> import datetime Traceback (most recent call last): File "<stdin>", line 1, in <module> File "Lib/datetime.py", line 2100, in <module> File "Lib/datetime.py", line 2194, in timezone _maxoffset = timedelta(hours=23, minutes=59) File "Lib/datetime.py", line 654, in __neg__ -self._microseconds) File "Lib/datetime.py", line 564, in __new__ assert isinstance(s, int) and 0 <= s < 24*3600 AssertionError >>>>> •
  • 3. Debug timedelta.__new__ 0 -86340 0 0 0 0 0 divmod in: -86340 86400 divmod out: 0 -86340 <class 'int'> -86340 Traceback (most recent call last): File "<stdin>", line 1, in <module> File "Lib/datetime.py", line 2100, in <module> File "Lib/datetime.py", line 2194, in timezone _maxoffset = timedelta(hours=23, minutes=59) File "Lib/datetime.py", line 654, in __neg__ -self._microseconds) File "Lib/datetime.py", line 564, in __new__ assert isinstance(s, int) and 0 <= s < 24*3600 AssertionError >>>>> •
  • 4. Add a test case diff --git a/tests/snippets/builtin_divmod.py b/tests/snippets/ builtin_divmod.py index 939e1d2d..ce9bdfba 100644 --- a/tests/snippets/builtin_divmod.py +++ b/tests/snippets/builtin_divmod.py @@ -3,6 +3,7 @@ from testutils import assert_raises assert divmod(11, 3) == (3, 2) assert divmod(8,11) == (0, 8) assert divmod(0.873, 0.252) == (3.0, 0.11699999999999999) +assert divmod(-86340, 86400) == (-1, 60) assert_raises(ZeroDivisionError, lambda: divmod(5, 0), 'divmod by zero') assert_raises(ZeroDivisionError, lambda: divmod(5.0, 0.0), 'divmod by zero')
  • 5. Run test (RustPython) ➜ RustPython git:(master) ✗ python tests/snippets/ builtin_divmod.py (RustPython) ➜ RustPython git:(master) ✗ cargo run tests/snippets/ builtin_divmod.py Finished dev [unoptimized + debuginfo] target(s) in 0.11s Running `target/debug/rustpython tests/snippets/ builtin_divmod.py` Traceback (most recent call last): File "tests/snippets/builtin_divmod.py", line 6, in <module> assert divmod(-86340, 86400) == (-1, 60) AssertionError
  • 6. Watch code (RustPython) ➜ RustPython git:(master) ✗ vi ./vm/src/obj/objint.rs … #[pymethod(name = "__divmod__")] fn divmod(&self, other: PyObjectRef, vm: &VirtualMachine) -> PyResult { if objtype::isinstance(&other, &vm.ctx.int_type()) { let v2 = get_value(&other); if *v2 != BigInt::zero() { let (r1, r2) = self.value.div_rem(v2); Ok(vm .ctx .new_tuple(vec![vm.ctx.new_int(r1), vm.ctx.new_int(r2)])) } else { Err(vm.new_zero_division_error("integer divmod by zero".to_str ing())) } } else { Ok(vm.ctx.not_implemented()) } } …
  • 7. Fix - Add divmod() @@ -739,6 +735,17 @@ fn truediv_ints(vm: &VirtualMachine, i1: &BigInt, i2: &BigInt) -> PyResult { } } +#[inline] +fn divmod(vm: &VirtualMachine, i1: &BigInt, i2: &BigInt) -> PyResult<(BigInt, BigInt)> { + if i2.is_zero() { + Err(vm.new_zero_division_error("integer division by zero".to_string())) + } else { + let modulo = (i1 % i2 + i2) % i2; + let division = (i1 - &modulo) / i2; + Ok((division, modulo)) + } +} + pub fn init(context: &PyContext) { PyInt::extend_class(context, &context.int_type); extend_class!(context, &context.int_type, {
  • 8. Fix - bugfix diff --git a/vm/src/obj/objint.rs b/vm/src/obj/objint.rs index 000dcafd..f90d069a 100644 --- a/vm/src/obj/objint.rs +++ b/vm/src/obj/objint.rs @@ -405,14 +405,10 @@ impl PyInt { fn divmod(&self, other: PyObjectRef, vm: &VirtualMachine) -> PyResult { if objtype::isinstance(&other, &vm.ctx.int_type()) { let v2 = get_value(&other); - if *v2 != BigInt::zero() { - let (r1, r2) = self.value.div_rem(v2); - Ok(vm - .ctx - .new_tuple(vec![vm.ctx.new_int(r1), vm.ctx.new_int(r2)])) - } else { - Err(vm.new_zero_division_error("integer divmod by zero".to_string())) - } + let (div, modulo) = divmod(vm, &self.value, v2)?; + Ok(vm + .ctx + .new_tuple(vec![vm.ctx.new_int(div), vm.ctx.new_int(modulo)])) } else { Ok(vm.ctx.not_implemented()) }
  • 9. Pull request (RustPython) ➜ RustPython git:(master) ✗ git push origin master:fix-divmod Enumerating objects: 36, done. Counting objects: 100% (36/36), done. Delta compression using up to 12 threads. Compressing objects: 100% (27/27), done. Writing objects: 100% (27/27), 2.50 KiB | 2.50 MiB/s, done. Total 27 (delta 24), reused 0 (delta 0) remote: Resolving deltas: 100% (24/24), completed with 9 local objects. remote: remote: Create a pull request for 'fix-divmod' on GitHub by visiting: remote: https://github.com/youknowone/RustPython/pull/new/fix-divmod remote: To https://github.com/youknowone/RustPython.git * [new branch] master -> fix-divmod
  • 10. Pull request (RustPython) ➜ RustPython git:(master) ✗ git push origin master:fix-divmod Enumerating objects: 36, done. Counting objects: 100% (36/36), done. Delta compression using up to 12 threads. Compressing objects: 100% (27/27), done. Writing objects: 100% (27/27), 2.50 KiB | 2.50 MiB/s, done. Total 27 (delta 24), reused 0 (delta 0) remote: Resolving deltas: 100% (24/24), completed with 9 local objects. remote: remote: Create a pull request for 'fix-divmod' on GitHub by visiting: remote: https://github.com/youknowone/RustPython/pull/new/fix-divmod remote: To https://github.com/youknowone/RustPython.git * [new branch] master -> fix-divmod
  • 12. Original issue (RustPython) ➜ RustPython git:(master) ✗ RUSTPYTHONPATH=Lib cargo run Compiling rustpython-vm v0.1.0 (/Users/youknowone/Projects/ RustPython/vm) Compiling rustpython v0.1.0 (/Users/youknowone/Projects/RustPython) Finished dev [unoptimized + debuginfo] target(s) in 15.14s Running `target/debug/rustpython` Welcome to the magnificent Rust Python 0.1.0 interpreter 😱 🖖 >>>>> import datetime divmod in: 0 86400 divmod out: 0 0 divmod in: 86399 86400 divmod out: 0 86399 divmod in: 86340 86400 divmod out: 0 86340 divmod in: -86340 86400 divmod out: -1 60 divmod in: 0 86400 divmod out: 0 0 >>>>> 😱 해결! 보통 이런 일은 잘 없으니
 기대하지 맙시다 ㅋㅋㅋㅋ