Commit graph

518 commits

Author SHA1 Message Date
kngwyu 4795a35143 impl IntoPyDictPointer for IntoIterator<Item=(K, V)>
this commit has 2 purposes:
1. Avoid duplication of implementation(for BTreeMap & HashMap)
2. Enable conversion from Vec<(K, V)> to PyDict
2018-05-30 16:26:23 +09:00
Kevin Phillips 9544adaf1d Marked from_code on PyModule to only work with Python 3. It could work with Python 2 if you call, for example, Py_CompileStringFlags and pass std::prt::null_mut() as the last argument and when calling PyImport_ExecCodeModuleEx passing mutable pointers for the first and last arguments. I also added a test for this to test_module.rs 2018-05-21 16:03:21 +02:00
Kevin Phillips 1b1121e558 Added a function to PyModule to load a module from a string of Python 2018-05-21 16:03:20 +02:00
konstin c42b71bc55 Fix python2 2018-05-19 17:42:40 +02:00
konstin 314a4a2b3e Some more documentation work 2018-05-19 17:27:26 +02:00
konstin 46b9bd6a9f
Merge pull request #155 from PyO3/pyobject_macros
Refactor and Export Pyobject_* macros
2018-05-13 14:54:57 +02:00
konstin 5717463daf
Merge pull request #154 from konstin/capybara
Relax return types and add functions
2018-05-12 20:43:40 +02:00
Martin Larralde 416a7fd8d3
Export PyUnicode in Python3 as well 2018-05-08 12:54:21 +02:00
konstin d445d60e0a Export PyUnicode to fix #141 2018-05-08 10:42:17 +02:00
konstin cb5bae2c90 Export pyobejct_* macros
This is required for interaction with other native python extensions, e.g. numpy

Fixes #153
2018-05-07 23:47:23 +02:00
konstin 8c26020015 Refactor pyobject_* macros 2018-05-07 23:45:24 +02:00
konstin 858a124374 Merge master 2018-05-05 15:50:04 +02:00
konstin afcc87e82c Feature gate try_from
This was discovered https://github.com/PyO3/pyo3/issues/5#issuecomment-386579894
2018-05-05 14:43:37 +02:00
konstin 57048bc5fc Merge branch 'master' into capybara 2018-05-02 19:32:56 +02:00
konstin 15204bab56 Better way to add functions to modules 2018-05-02 19:26:54 +02:00
Martin Larralde cc352dade3 Fix exception tests failing with Python 2 2018-05-02 13:54:59 +02:00
Martin Larralde b80b85539b Remove occurrences of py::methods and py::class 2018-05-01 23:17:42 +02:00
konstin 0880ac166c Merge master 2018-05-01 20:41:35 +02:00
konstin d0c42dfcc1 Fix compilation on nightly 2018-05-01 15:44:38 +02:00
konstin 6113428746 Allow defining functions outside of the module declarations
This commit consists of
 * a proc macro to convert rust functions into python functions (`#[function]`),
 * a macro to register a function in a module (`add_function_to_module!`)
 * Documenting both the old and the new way in the book
2018-04-30 23:17:09 +02:00
konstin 1c0eac2690 Minor changes 2018-04-09 00:00:20 +02:00
konstin 45bb09b3e8 Relax return type requirements
Allows returning essentially arbitrary types by wrapping them into a PyResult. This is done with a conversion trait that specializes for PyResult.
2018-04-06 17:22:09 +02: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
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
Roy Wellington Ⅳ 11e2163bb4 Fix minor typos in example code 2018-02-22 22:22:37 -08:00
Martin Larralde e58cd1c585 Fix wrong macro being tagged with macro_export 2018-02-21 22:44:56 +01: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 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 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 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
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
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
Nikolay Kim 3681cf51e8 python2 compatibility 2018-01-19 10:08:13 -08:00
Nikolay Kim b738c1a04b clippy warnings 2018-01-19 10:02:36 -08:00
Nikolay Kim 324a6b2697 drop RefFromPyObject; allow mut refs #106 2018-01-19 09:04:42 -08:00
Nikolay Kim 35e91a5cd1 Merge branch 'master' of github.com:PyO3/pyo3 2018-01-17 08:10:01 -08:00
Nikolay Kim d6035bce15 Fix impl FromPyObject for Py<T> 2018-01-17 08:09:44 -08:00
Guanqun Lu 4bc079f619 typo fix 2017-12-27 22:11:18 +08:00
Nikolay Kim 050397b723 mark method that work with raw pointer unsafe 2017-12-26 13:41:27 -08:00
Nikolay Kim d3832359a2 proper c_char usage #93 2017-11-27 10:59:45 -08:00
messense e7a7b3d5a0
Remove use of now unneeded 'AsciiExt' trait 2017-11-23 12:08:05 +08:00
dkao1978 eb9050ab90 Add documentation for compiling on MacOS (#89)
* Update README.md

* Update overview.md

* Update lib.rs

* Update README.md

* Add links
2017-10-22 11:17:35 +08:00