File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -8,6 +8,7 @@ use smallvec::SmallVec;
88use std:: borrow:: Cow ;
99use std:: fmt;
1010use std:: marker:: PhantomData ;
11+ use crate :: typeref;
1112
1213import_exception ! ( json, JSONDecodeError ) ;
1314
@@ -57,7 +58,7 @@ impl<'de, 'a> Visitor<'de> for JsonValue<'a> {
5758 }
5859
5960 fn visit_unit < E > ( self ) -> Result < Self :: Value , E > {
60- Ok ( unsafe { pyo3 :: ffi :: Py_None ( ) } )
61+ Ok ( unsafe { typeref :: NONE } )
6162 }
6263
6364 fn visit_bool < E > ( self , value : bool ) -> Result < Self :: Value , E >
Original file line number Diff line number Diff line change @@ -4,6 +4,7 @@ use pyo3::prelude::*;
44use pyo3:: types:: * ;
55use std:: sync:: Once ;
66
7+ pub static mut NONE : * mut pyo3:: ffi:: PyObject = 0 as * mut pyo3:: ffi:: PyObject ;
78pub static mut STR_PTR : * mut pyo3:: ffi:: PyTypeObject = 0 as * mut pyo3:: ffi:: PyTypeObject ;
89pub static mut BYTES_PTR : * mut pyo3:: ffi:: PyTypeObject = 0 as * mut pyo3:: ffi:: PyTypeObject ;
910pub static mut DICT_PTR : * mut pyo3:: ffi:: PyTypeObject = 0 as * mut pyo3:: ffi:: PyTypeObject ;
@@ -18,6 +19,7 @@ static INIT: Once = Once::new();
1819
1920pub fn init_typerefs ( py : Python ) {
2021 INIT . call_once ( || unsafe {
22+ NONE = pyo3:: ffi:: Py_None ( ) ;
2123 STR_PTR = PyUnicode :: new ( py, "python" ) . as_ref ( py) . get_type_ptr ( ) ;
2224 BYTES_PTR = PyBytes :: new ( py, b"python" ) . as_ref ( py) . get_type_ptr ( ) ;
2325 DICT_PTR = PyDict :: new ( py) . as_ref ( ) . get_type_ptr ( ) ;
Original file line number Diff line number Diff line change @@ -31,15 +31,24 @@ def test_bool(self):
3131 self .assertEqual (orjson .dumps (obj ), ref .encode ('utf-8' ))
3232 self .assertEqual (orjson .loads (ref ), obj )
3333
34- def test_bool_array (self ):
34+ def test_bool_true_array (self ):
3535 """
36- bool array
36+ bool true array
3737 """
3838 obj = [True ] * 256
3939 ref = ('[' + ('true,' * 255 ) + 'true]' ).encode ('utf-8' )
4040 self .assertEqual (orjson .dumps (obj ), ref )
4141 self .assertEqual (orjson .loads (ref ), obj )
4242
43+ def test_bool_false_array (self ):
44+ """
45+ bool false array
46+ """
47+ obj = [False ] * 256
48+ ref = ('[' + ('false,' * 255 ) + 'false]' ).encode ('utf-8' )
49+ self .assertEqual (orjson .dumps (obj ), ref )
50+ self .assertEqual (orjson .loads (ref ), obj )
51+
4352 def test_none (self ):
4453 """
4554 null
You can’t perform that action at this time.
0 commit comments