Commit Graph

780 Commits

Author SHA1 Message Date
konstin ced4eb532c Expect the pyo3 crate to be in scope for the codegen
This allows using generated code from crates that do not directly depend on pyo3.

E.g.:

```rust
extern crate my_pyo3_wrapper;

use my_pyo3_wrapper::pyo3;

#[py::modinit(rust2py)]
fn init_mod(py: Python, m: &PyModule) -> PyResult<()> {
    // ...
    Ok(())
}
2018-04-05 13:39:07 +02:00
konstin e570c6b9b9 Move the codegen into its own crate
This makes the code generatioin reusable from third party crates.
2018-04-05 13:39:07 +02:00
Nikolay Kim 14ab12b89f move doc generation to asfter script section 2018-04-03 10:32:10 -07:00
Nikolay Kim cab682d855 use rust bin dir instead 2018-04-03 10:15:57 -07:00
Nikolay Kim 6b665e9a82 create cargo dir 2018-04-03 10:15:04 -07:00
Nikolay Kim a5d0b30227 use precompiled mdbook 2018-03-30 14:51:13 -07:00
Nikolay Kim 0982cba184 use precompiled mdbook 2018-03-30 14:29:36 -07:00
Nikolay Kim 6719e152ba
Merge pull request #137 from PyO3/try_from_fixes
use PyTryFrom explicitly (fixes for 1.26.0-nightly)
2018-03-29 07:40:58 -07:00
Alexey Popravka e66c5ebb83 use PyTryFrom explicitly 2018-03-29 17:36:05 +03:00
Vlad Shcherbina 2aedbffcd0 Fix typos 2018-03-15 14:41:16 +03:00
Roy Wellington Ⅳ 80502bd307 Change type of kwargs in the example to Option<PyDict>
That's what the immediately preceding paragraph says the type is, and that
would make more sense.
2018-03-15 14:27:45 +03:00
Roy Wellington Ⅳ 24eee46128 Fix typos and other minor touchups to guide
* Fix some typos
* Capitalize Rust, acronyms
* Remove some trailing whitespace
2018-03-15 14:27:45 +03:00
Vlad Shcherbina 5dc5c534df Enable backtrace on AppVeyor too
Alto to hopefully diagnose intermittent failures.
2018-03-15 13:51:12 +03:00
Vlad Shcherbina 5198fccaeb Enable backtrace
To simplify troubleshooting on the build server.
2018-03-14 01:05:47 +03:00
Nikolay Kim ffee21cb1f
Merge pull request #130 from ethanhs/pep523
Add PEP 523 frame eval API methods and definitions
2018-03-01 19:55:20 -08:00
Ethan Smith 5cc6dc74d4
conditionally include Python3.6 items 2018-03-01 14:46:27 -08:00
Ethan Smith 6c25a753b8
Add PEP 523 frame eval API things 2018-03-01 13:36:16 -08:00
Nikolay Kim 4585f990b7
Merge pull request #128 from Eijebong/log
Bump log to 0.4
2018-02-27 09:08:56 -08:00
Bastien Orivel 7278f4275d Bump log to 0.4 2018-02-27 18:05:29 +01:00
Nikolay Kim d3a762ea9f
Merge pull request #127 from d0c-s4vage/hotfix-fix_word_count_cls_example-126
Synchronizes word-count-cls example README and code
2018-02-26 13:18:38 -08:00
James Johnson 8844502775 Syntax error in README changes.
see #126
2018-02-26 15:05:31 -06:00
James Johnson a923f8b5d3 Synchronizes word-count-cls example README and code.
see #126
2018-02-26 15:03:29 -06:00
Nikolay Kim 2c0a866029
Merge pull request #121 from thanatos/token-typo
Fix minor typos in example code
2018-02-23 01:48:41 -08:00
Roy Wellington Ⅳ 11e2163bb4 Fix minor typos in example code 2018-02-22 22:22:37 -08:00
Nikolay Kim 25514f69da
Merge pull request #118 from althonos/patch-1
Fix wrong macro being tagged with `macro_export`
2018-02-21 14:25:37 -08:00
Martin Larralde e58cd1c585 Fix wrong macro being tagged with `macro_export` 2018-02-21 22:44:56 +01:00
Nikolay Kim d00abc1fa7 use pyo3cls 2018-02-21 10:43:52 -08:00
Nikolay Kim 524fdeeea5 update changes 2018-02-21 10:35:49 -08:00
Nikolay Kim 995ec109c3
Merge pull request #116 from althonos/master
Allow importing exceptions from nested modules
2018-02-21 10:35:11 -08:00
Nikolay Kim e585f5881d update num-traits 2018-02-21 10:33:38 -08:00
Nikolay Kim 057660e546 fix python3.7 support 2018-02-21 10:29:14 -08:00
Martin Larralde cce9d0de56 Allow importing exceptions from nested modules 2018-02-21 19:16:17 +01:00
Nikolay Kim d50d1fb7ea enable python3.7 builds 2018-02-21 10:06:48 -08:00
Nikolay Kim 5b9696945f wrong log version 2018-02-21 09:42:52 -08:00
Nikolay Kim 0b9557a245 call_method*() crashes when the method does not exist #113 2018-02-21 09:39:06 -08:00
Nikolay Kim b7a8d25338 const fns that we use are stable now 2018-02-21 09:23:58 -08:00
Nikolay Kim 438f4bf091 ignore some python code in doc strings 2018-02-21 09:23:52 -08:00
Vlad Shcherbina 4eb22a3c20 Travis: move doc build step to `script` #115
To ensure that doc build failures aren't silently ignored.
2018-02-14 20:45:08 +03:00
Vlad Shcherbina c4939ab9d7 Fix documentation build (hopefully) #115 2018-02-14 19:23:09 +03:00
Vlad Shcherbina f8d914cac8 Fix broken links
https://pyo3.github.io/PyO3 -> https://pyo3.github.io/pyo3
in the documentation.
2018-02-14 17:21:17 +03:00
Brian Anderson 473b1f8b30 Use version 0.2 in guide overview 2018-02-13 00:14:51 +03:00
Vlad Shcherbina a59e1dc8ad Fix unused_parens warnings
I left the parentheses in place to keep the resemblance
to the original C macros.
2018-02-12 14:36:05 +03:00
Nikolay Kim 30baa990f8
Update CHANGES.txt 2018-02-11 09:38:50 -08:00
Nikolay Kim 0874c243ef
Merge pull request #112 from Vlad-Shcherbina/patch-3
Disallow str/float to int conversions #108
2018-02-11 09:37:28 -08:00
Vlad Shcherbina a5d3ed0939 Add tests that string/float to int conversions raise TypeError #108 2018-02-11 19:09:15 +03:00
Vlad Shcherbina 9fe78b5cb3 Disallow implicit weakly-typed conversions to integers #108
In `int_fits_c_long!`,
use `PyLong_AsLong(PyNumber_Index(x))`
instead of `PyNumber_Index(x)`.

In `int_convert_u64_or_i64!`,
use `PyLong_As*LongLong(PyNumber_Index(x))`
instead of `PyLong_As*LongLong(if PyLong_Check(x) {x} else {PyNumber_Long(x)})`.

Along the way, fix memory leak caused by missing `Py_DECREF(num)`.


`PyNumber_Index(x)` is the best way to get an integer losslessly:
https://docs.python.org/3/reference/datamodel.html#object.__index__
https://docs.python.org/3.5/c-api/number.html#c.PyNumber_Index

`PyLong_AsLong(x)` has the problem that it attempts to call `x.__int__()`.
Strings don't implement this method, but floats do, so it silently converts
floats to integers.
https://docs.python.org/3.5/c-api/long.html#c.PyLong_AsLong

`PyNumber_Long(x)` is equivalent to `int(x)` call,
so not only does it truncate floats, but also attempts to parse strings.
https://docs.python.org/3.5/c-api/number.html#c.PyNumber_Long

`PyLong_Check(x)` is redundant because it happens inside `PyNumber_Index(x)`
anyway:
988fb28431/Objects/abstract.c (L1259)
2018-02-11 19:04:12 +03:00
Vlad Shcherbina f8e503f3b7 Drop tests for implicit float to int conversions #108
Neither Python nor Rust has implicit float to integer conversions
(they mask programming errors), so it would make sense for the
bindings library to disallow them as well.

Later there will be tests that such conversions result in TypeError.
2018-02-11 18:19:21 +03:00
Nikolay Kim b4f7273474
Update CHANGES.txt 2018-02-10 11:27:45 -08:00
Nikolay Kim ffb5880fa2
Merge pull request #111 from Vlad-Shcherbina/patch-2
Remove PyEval_ThreadsInitialized() assertion #110
2018-02-10 11:26:31 -08:00
Vlad Shcherbina 81fd4bd24e Remove PyEval_ThreadsInitialized() assertion #110
First, this function should not be called before `Py_Initialize()`.
It accesses the field `_PyRuntime.ceval.gil.locked` of the global
variable, which is zero initially, but uses -1 to indicate that
the GIL is not created or destroyed.
(8ff5356473/Python/ceval_gil.h (L98))

Second, this assertion can't be moved after `Py_InitializeEx(0)` call,
because in Python 3.7 they started calling `PyEval_InitThreads()`
from `Py_Initialize()`.
(2914bb32e2 (diff-baf5eab51059d96fb8837152dab0d1a4R689))
2018-02-10 21:36:59 +03:00