From 7269dc64c2b64689dd9970324cfb455d4cebd5e8 Mon Sep 17 00:00:00 2001 From: Daniel Grunwald Date: Fri, 22 Jan 2016 20:38:34 +0100 Subject: [PATCH] python*-sys: use #![no_std] --- python27-sys/src/lib.rs | 1 + python27-sys/src/methodobject.rs | 3 ++- python27-sys/src/modsupport.rs | 2 +- python27-sys/src/object.rs | 2 +- python27-sys/src/objectabstract.rs | 2 +- python27-sys/src/pyport.rs | 4 ++-- python3-sys/src/ceval.rs | 7 ++----- python3-sys/src/code.rs | 2 +- python3-sys/src/import.rs | 5 +---- python3-sys/src/lib.rs | 3 ++- python3-sys/src/methodobject.rs | 7 ++++--- python3-sys/src/moduleobject.rs | 4 ++-- python3-sys/src/object.rs | 26 +++++++++++++------------- python3-sys/src/objectabstract.rs | 2 +- python3-sys/src/objimpl.rs | 2 +- python3-sys/src/pyhash.rs | 2 +- python3-sys/src/pyport.rs | 4 ++-- python3-sys/src/pythonrun.rs | 4 ++-- 18 files changed, 40 insertions(+), 42 deletions(-) diff --git a/python27-sys/src/lib.rs b/python27-sys/src/lib.rs index e84b8e41..5cf5cd48 100644 --- a/python27-sys/src/lib.rs +++ b/python27-sys/src/lib.rs @@ -1,3 +1,4 @@ +#![no_std] #![allow(non_camel_case_types, non_upper_case_globals, non_snake_case)] extern crate libc; diff --git a/python27-sys/src/methodobject.rs b/python27-sys/src/methodobject.rs index 71ed1585..9d7effa9 100644 --- a/python27-sys/src/methodobject.rs +++ b/python27-sys/src/methodobject.rs @@ -1,4 +1,5 @@ use libc::{c_char, c_int}; +use core::ptr; //use pyport::Py_ssize_t; use object::{PyObject, PyTypeObject, Py_TYPE}; @@ -103,6 +104,6 @@ extern "C" { #[inline(always)] pub unsafe fn PyCFunction_New(ml: *mut PyMethodDef, slf: *mut PyObject) -> *mut PyObject { - PyCFunction_NewEx(ml, slf, ::std::ptr::null_mut()) + PyCFunction_NewEx(ml, slf, ptr::null_mut()) } diff --git a/python27-sys/src/modsupport.rs b/python27-sys/src/modsupport.rs index 7610d775..f8a8792b 100644 --- a/python27-sys/src/modsupport.rs +++ b/python27-sys/src/modsupport.rs @@ -1,5 +1,5 @@ use libc::{c_char, c_int, c_long}; -use std::ptr; +use core::ptr; use pyport::Py_ssize_t; use object::PyObject; use methodobject::PyMethodDef; diff --git a/python27-sys/src/object.rs b/python27-sys/src/object.rs index e3689112..4bccf5a6 100644 --- a/python27-sys/src/object.rs +++ b/python27-sys/src/object.rs @@ -1,4 +1,4 @@ -use std::ptr; +use core::ptr; use libc::{c_void, c_int, c_uint, c_long, c_char, c_double, FILE}; use pyport::Py_ssize_t; use methodobject::PyMethodDef; diff --git a/python27-sys/src/objectabstract.rs b/python27-sys/src/objectabstract.rs index 7434c9cd..0877526f 100644 --- a/python27-sys/src/objectabstract.rs +++ b/python27-sys/src/objectabstract.rs @@ -1,6 +1,6 @@ use libc::{c_void, c_char, c_int}; use pyport::Py_ssize_t; -use std::ptr; +use core::ptr; use object::*; #[inline] diff --git a/python27-sys/src/pyport.rs b/python27-sys/src/pyport.rs index db77d9a7..cfe8558c 100644 --- a/python27-sys/src/pyport.rs +++ b/python27-sys/src/pyport.rs @@ -3,6 +3,6 @@ pub type Py_uintptr_t = ::libc::uintptr_t; pub type Py_intptr_t = ::libc::intptr_t; pub type Py_ssize_t = ::libc::ssize_t; -pub const PY_SSIZE_T_MIN : Py_ssize_t = ::std::isize::MIN as Py_ssize_t; -pub const PY_SSIZE_T_MAX : Py_ssize_t = ::std::isize::MAX as Py_ssize_t; +pub const PY_SSIZE_T_MIN : Py_ssize_t = ::core::isize::MIN as Py_ssize_t; +pub const PY_SSIZE_T_MAX : Py_ssize_t = ::core::isize::MAX as Py_ssize_t; diff --git a/python3-sys/src/ceval.rs b/python3-sys/src/ceval.rs index 9c965041..691daf8c 100644 --- a/python3-sys/src/ceval.rs +++ b/python3-sys/src/ceval.rs @@ -11,7 +11,7 @@ extern "C" { #[inline] pub unsafe fn PyEval_CallObject(func: *mut PyObject, arg: *mut PyObject) -> *mut PyObject { - PyEval_CallObjectWithKeywords(func, arg, ::std::ptr::null_mut()) + PyEval_CallObjectWithKeywords(func, arg, ::core::ptr::null_mut()) } extern "C" { @@ -26,10 +26,7 @@ extern "C" { pub fn PyEval_GetGlobals() -> *mut PyObject; pub fn PyEval_GetLocals() -> *mut PyObject; pub fn PyEval_GetFrame() -> *mut ::PyFrameObject; - pub fn Py_AddPendingCall(func: - ::std::option::Option c_int>, + pub fn Py_AddPendingCall(func: Option c_int>, arg: *mut c_void) -> c_int; pub fn Py_MakePendingCalls() -> c_int; pub fn Py_SetRecursionLimit(arg1: c_int) -> (); diff --git a/python3-sys/src/code.rs b/python3-sys/src/code.rs index 96fcb545..1e365e21 100644 --- a/python3-sys/src/code.rs +++ b/python3-sys/src/code.rs @@ -29,7 +29,7 @@ impl Clone for PyCodeObject { #[inline] fn clone(&self) -> Self { *self } } impl Default for PyCodeObject { - #[inline] fn default() -> Self { unsafe { ::std::mem::zeroed() } } + #[inline] fn default() -> Self { unsafe { ::core::mem::zeroed() } } } /* Masks for co_flags */ diff --git a/python3-sys/src/import.rs b/python3-sys/src/import.rs index 3f439396..e7e8c7b3 100644 --- a/python3-sys/src/import.rs +++ b/python3-sys/src/import.rs @@ -62,10 +62,7 @@ extern "C" { -> c_int; pub fn PyImport_AppendInittab(name: *const c_char, - initfunc: - ::std::option::Option - *mut PyObject>) + initfunc: Option *mut PyObject>) -> c_int; } diff --git a/python3-sys/src/lib.rs b/python3-sys/src/lib.rs index 6a56f879..470497e1 100644 --- a/python3-sys/src/lib.rs +++ b/python3-sys/src/lib.rs @@ -1,4 +1,5 @@ -#![allow(non_camel_case_types, non_snake_case, non_upper_case_globals, raw_pointer_derive)] +#![no_std] +#![allow(non_camel_case_types, non_snake_case, non_upper_case_globals)] #![cfg_attr(Py_LIMITED_API, allow(unused_imports))] // old: marked with TODO diff --git a/python3-sys/src/methodobject.rs b/python3-sys/src/methodobject.rs index 5728ac15..ba2a09c9 100644 --- a/python3-sys/src/methodobject.rs +++ b/python3-sys/src/methodobject.rs @@ -1,4 +1,5 @@ use libc::{c_char, c_int}; +use core::{mem, ptr}; use object::{PyObject, PyTypeObject, Py_TYPE}; extern "C" { @@ -42,13 +43,13 @@ pub struct PyMethodDef { impl Clone for PyMethodDef { #[inline] fn clone(&self) -> PyMethodDef { *self } } -impl ::std::default::Default for PyMethodDef { - fn default() -> PyMethodDef { unsafe { ::std::mem::zeroed() } } +impl Default for PyMethodDef { + fn default() -> PyMethodDef { unsafe { mem::zeroed() } } } #[inline(always)] pub unsafe fn PyCFunction_New(ml: *mut PyMethodDef, slf: *mut PyObject) -> *mut PyObject { - PyCFunction_NewEx(ml, slf, ::std::ptr::null_mut()) + PyCFunction_NewEx(ml, slf, ptr::null_mut()) } extern "C" { diff --git a/python3-sys/src/moduleobject.rs b/python3-sys/src/moduleobject.rs index adc0141c..08912abc 100644 --- a/python3-sys/src/moduleobject.rs +++ b/python3-sys/src/moduleobject.rs @@ -37,7 +37,7 @@ pub struct PyModuleDef_Base { pub m_index: Py_ssize_t, pub m_copy: *mut PyObject, } -impl ::std::clone::Clone for PyModuleDef_Base { +impl Clone for PyModuleDef_Base { fn clone(&self) -> PyModuleDef_Base { *self } } @@ -61,7 +61,7 @@ pub struct PyModuleDef { pub m_clear: Option, pub m_free: Option, } -impl ::std::clone::Clone for PyModuleDef { +impl Clone for PyModuleDef { fn clone(&self) -> PyModuleDef { *self } } diff --git a/python3-sys/src/object.rs b/python3-sys/src/object.rs index f72cdf28..aed23a22 100644 --- a/python3-sys/src/object.rs +++ b/python3-sys/src/object.rs @@ -1,4 +1,4 @@ -use std::ptr; +use core::ptr; use libc::{c_void, c_int, c_uint, c_ulong, c_char}; use pyport::{Py_ssize_t, Py_hash_t}; @@ -110,7 +110,7 @@ mod bufferinfo { #[inline] fn clone(&self) -> Self { *self } } impl Default for Py_buffer { - #[inline] fn default() -> Self { unsafe { ::std::mem::zeroed() } } + #[inline] fn default() -> Self { unsafe { ::core::mem::zeroed() } } } pub type getbufferproc = @@ -285,7 +285,7 @@ mod typeobject { #[inline] fn clone(&self) -> Self { *self } } impl Default for PyNumberMethods { - #[inline] fn default() -> Self { unsafe { ::std::mem::zeroed() } } + #[inline] fn default() -> Self { unsafe { ::core::mem::zeroed() } } } #[repr(C)] #[derive(Copy)] @@ -305,7 +305,7 @@ mod typeobject { #[inline] fn clone(&self) -> Self { *self } } impl Default for PySequenceMethods { - #[inline] fn default() -> Self { unsafe { ::std::mem::zeroed() } } + #[inline] fn default() -> Self { unsafe { ::core::mem::zeroed() } } } #[repr(C)] #[derive(Copy)] @@ -318,7 +318,7 @@ mod typeobject { #[inline] fn clone(&self) -> Self { *self } } impl Default for PyMappingMethods { - #[inline] fn default() -> Self { unsafe { ::std::mem::zeroed() } } + #[inline] fn default() -> Self { unsafe { ::core::mem::zeroed() } } } #[repr(C)] #[derive(Copy)] @@ -334,7 +334,7 @@ mod typeobject { } #[cfg(Py_3_5)] impl Default for PyAsyncMethods { - #[inline] fn default() -> Self { unsafe { ::std::mem::zeroed() } } + #[inline] fn default() -> Self { unsafe { ::core::mem::zeroed() } } } #[repr(C)] #[derive(Copy)] @@ -346,7 +346,7 @@ mod typeobject { #[inline] fn clone(&self) -> Self { *self } } impl Default for PyBufferProcs { - #[inline] fn default() -> Self { unsafe { ::std::mem::zeroed() } } + #[inline] fn default() -> Self { unsafe { ::core::mem::zeroed() } } } #[repr(C)] @@ -419,7 +419,7 @@ mod typeobject { #[inline] fn clone(&self) -> Self { *self } } impl Default for PyTypeObject { - #[inline] fn default() -> Self { unsafe { ::std::mem::zeroed() } } + #[inline] fn default() -> Self { unsafe { ::core::mem::zeroed() } } } #[repr(C)] @@ -441,7 +441,7 @@ mod typeobject { #[inline] fn clone(&self) -> Self { *self } } impl Default for PyHeapTypeObject { - #[inline] fn default() -> Self { unsafe { ::std::mem::zeroed() } } + #[inline] fn default() -> Self { unsafe { ::core::mem::zeroed() } } } #[inline] @@ -463,8 +463,8 @@ pub struct PyType_Slot { impl Clone for PyType_Slot { fn clone(&self) -> PyType_Slot { *self } } -impl ::std::default::Default for PyType_Slot { - fn default() -> PyType_Slot { unsafe { ::std::mem::zeroed() } } +impl Default for PyType_Slot { + fn default() -> PyType_Slot { unsafe { ::core::mem::zeroed() } } } #[repr(C)] @@ -479,8 +479,8 @@ pub struct PyType_Spec { impl Clone for PyType_Spec { fn clone(&self) -> PyType_Spec { *self } } -impl ::std::default::Default for PyType_Spec { - fn default() -> PyType_Spec { unsafe { ::std::mem::zeroed() } } +impl Default for PyType_Spec { + fn default() -> PyType_Spec { unsafe { ::core::mem::zeroed() } } } extern "C" { diff --git a/python3-sys/src/objectabstract.rs b/python3-sys/src/objectabstract.rs index 33cd80f2..97cbb1c4 100644 --- a/python3-sys/src/objectabstract.rs +++ b/python3-sys/src/objectabstract.rs @@ -1,6 +1,6 @@ use libc::{c_void, c_char, c_int}; use pyport::Py_ssize_t; -use std::ptr; +use core::ptr; use object::*; #[inline] diff --git a/python3-sys/src/objimpl.rs b/python3-sys/src/objimpl.rs index 838de566..575a6d4f 100644 --- a/python3-sys/src/objimpl.rs +++ b/python3-sys/src/objimpl.rs @@ -41,7 +41,7 @@ impl Clone for PyObjectArenaAllocator { } #[cfg(all(not(Py_LIMITED_API), Py_3_4))] impl Default for PyObjectArenaAllocator { - #[inline] fn default() -> Self { unsafe { ::std::mem::zeroed() } } + #[inline] fn default() -> Self { unsafe { ::core::mem::zeroed() } } } #[cfg(all(not(Py_LIMITED_API), Py_3_4))] extern "C" { diff --git a/python3-sys/src/pyhash.rs b/python3-sys/src/pyhash.rs index 9fee0956..4b0833af 100644 --- a/python3-sys/src/pyhash.rs +++ b/python3-sys/src/pyhash.rs @@ -15,7 +15,7 @@ impl Clone for PyHash_FuncDef { #[inline] fn clone(&self) -> Self { *self } } impl Default for PyHash_FuncDef { - #[inline] fn default() -> Self { unsafe { ::std::mem::zeroed() } } + #[inline] fn default() -> Self { unsafe { ::core::mem::zeroed() } } } extern "C" { diff --git a/python3-sys/src/pyport.rs b/python3-sys/src/pyport.rs index ddaf97b6..9ac73372 100644 --- a/python3-sys/src/pyport.rs +++ b/python3-sys/src/pyport.rs @@ -6,6 +6,6 @@ pub type Py_ssize_t = ::libc::ssize_t; pub type Py_hash_t = Py_ssize_t; pub type Py_uhash_t = ::libc::size_t; -pub const PY_SSIZE_T_MIN : Py_ssize_t = ::std::isize::MIN as Py_ssize_t; -pub const PY_SSIZE_T_MAX : Py_ssize_t = ::std::isize::MAX as Py_ssize_t; +pub const PY_SSIZE_T_MIN : Py_ssize_t = ::core::isize::MIN as Py_ssize_t; +pub const PY_SSIZE_T_MAX : Py_ssize_t = ::core::isize::MAX as Py_ssize_t; diff --git a/python3-sys/src/pythonrun.rs b/python3-sys/src/pythonrun.rs index 6f219838..9884bf5e 100644 --- a/python3-sys/src/pythonrun.rs +++ b/python3-sys/src/pythonrun.rs @@ -1,5 +1,5 @@ use libc::{c_char, c_int, wchar_t, FILE}; -use std::ptr; +use core::ptr; use object::*; use pystate::PyThreadState; #[cfg(not(Py_LIMITED_API))] @@ -177,7 +177,7 @@ extern "C" { arg3: *mut PyObject) -> (); // TODO: these moved to pylifecycle.h - pub fn Py_AtExit(func: ::std::option::Option ()>) + pub fn Py_AtExit(func: Option ()>) -> c_int; pub fn Py_Exit(arg1: c_int) -> (); pub fn Py_Main(argc: c_int, argv: *mut *mut wchar_t)