aboutsummaryrefslogtreecommitdiff
path: root/py/nativeglue.c
diff options
context:
space:
mode:
authorDamien George <damien.p.george@gmail.com>2016-02-09 13:29:20 +0000
committerDamien George <damien.p.george@gmail.com>2016-02-09 13:29:20 +0000
commit3e02b1d19a4b1fb36ee36b0d43144bad6b797f2f (patch)
tree5545397c4105c818838c6b18c664b4f82f77cb56 /py/nativeglue.c
parent9e78ab4b866c8bc4cf8b1bc21b848aadc64097cb (diff)
py/viper: Allow casting of Python integers to viper pointers.
This allows you to pass a number (being an address) to a viper function that expects a pointer, and also allows casting of integers to pointers within viper functions. This was actually the original behaviour, but it regressed due to native type identifiers being promoted to 4 bits in width.
Diffstat (limited to 'py/nativeglue.c')
-rw-r--r--py/nativeglue.c10
1 files changed, 7 insertions, 3 deletions
diff --git a/py/nativeglue.c b/py/nativeglue.c
index e27d69e14..bc2f4ff5e 100644
--- a/py/nativeglue.c
+++ b/py/nativeglue.c
@@ -50,10 +50,14 @@ mp_uint_t mp_convert_obj_to_native(mp_obj_t obj, mp_uint_t type) {
case MP_NATIVE_TYPE_BOOL:
case MP_NATIVE_TYPE_INT:
case MP_NATIVE_TYPE_UINT: return mp_obj_get_int_truncated(obj);
- default: { // a pointer
+ default: { // cast obj to a pointer
mp_buffer_info_t bufinfo;
- mp_get_buffer_raise(obj, &bufinfo, MP_BUFFER_RW);
- return (mp_uint_t)bufinfo.buf;
+ if (mp_get_buffer(obj, &bufinfo, MP_BUFFER_RW)) {
+ return (mp_uint_t)bufinfo.buf;
+ } else {
+ // assume obj is an integer that represents an address
+ return mp_obj_get_int_truncated(obj);
+ }
}
}
}