8
8
//! the contract-specific function pointer. This is done via the `#[entry_point]`
9
9
//! macro attribute from cosmwasm-derive.
10
10
use alloc:: vec:: Vec ;
11
- use core:: marker:: PhantomData ;
11
+ use core:: { marker:: PhantomData , ptr } ;
12
12
13
13
use serde:: de:: DeserializeOwned ;
14
14
@@ -95,7 +95,8 @@ extern "C" fn allocate(size: usize) -> u32 {
95
95
#[ no_mangle]
96
96
extern "C" fn deallocate ( pointer : u32 ) {
97
97
// auto-drop Region on function end
98
- let _ = unsafe { Region :: from_heap_ptr ( pointer as * mut Region < Owned > ) } ;
98
+ let _ =
99
+ unsafe { Region :: from_heap_ptr ( ptr:: NonNull :: new ( pointer as * mut Region < Owned > ) . unwrap ( ) ) } ;
99
100
}
100
101
101
102
// TODO: replace with https://doc.rust-lang.org/std/ops/trait.Try.html once stabilized
@@ -533,9 +534,12 @@ where
533
534
C : CustomMsg ,
534
535
E : ToString ,
535
536
{
536
- let env: Vec < u8 > = unsafe { Region :: from_heap_ptr ( env_ptr) . into_vec ( ) } ;
537
- let info: Vec < u8 > = unsafe { Region :: from_heap_ptr ( info_ptr) . into_vec ( ) } ;
538
- let msg: Vec < u8 > = unsafe { Region :: from_heap_ptr ( msg_ptr) . into_vec ( ) } ;
537
+ let env: Vec < u8 > =
538
+ unsafe { Region :: from_heap_ptr ( ptr:: NonNull :: new ( env_ptr) . unwrap ( ) ) . into_vec ( ) } ;
539
+ let info: Vec < u8 > =
540
+ unsafe { Region :: from_heap_ptr ( ptr:: NonNull :: new ( info_ptr) . unwrap ( ) ) . into_vec ( ) } ;
541
+ let msg: Vec < u8 > =
542
+ unsafe { Region :: from_heap_ptr ( ptr:: NonNull :: new ( msg_ptr) . unwrap ( ) ) . into_vec ( ) } ;
539
543
540
544
let env: Env = try_into_contract_result ! ( from_json( env) ) ;
541
545
let info: MessageInfo = try_into_contract_result ! ( from_json( info) ) ;
@@ -557,9 +561,12 @@ where
557
561
C : CustomMsg ,
558
562
E : ToString ,
559
563
{
560
- let env: Vec < u8 > = unsafe { Region :: from_heap_ptr ( env_ptr) . into_vec ( ) } ;
561
- let info: Vec < u8 > = unsafe { Region :: from_heap_ptr ( info_ptr) . into_vec ( ) } ;
562
- let msg: Vec < u8 > = unsafe { Region :: from_heap_ptr ( msg_ptr) . into_vec ( ) } ;
564
+ let env: Vec < u8 > =
565
+ unsafe { Region :: from_heap_ptr ( ptr:: NonNull :: new ( env_ptr) . unwrap ( ) ) . into_vec ( ) } ;
566
+ let info: Vec < u8 > =
567
+ unsafe { Region :: from_heap_ptr ( ptr:: NonNull :: new ( info_ptr) . unwrap ( ) ) . into_vec ( ) } ;
568
+ let msg: Vec < u8 > =
569
+ unsafe { Region :: from_heap_ptr ( ptr:: NonNull :: new ( msg_ptr) . unwrap ( ) ) . into_vec ( ) } ;
563
570
564
571
let env: Env = try_into_contract_result ! ( from_json( env) ) ;
565
572
let info: MessageInfo = try_into_contract_result ! ( from_json( info) ) ;
@@ -580,8 +587,10 @@ where
580
587
C : CustomMsg ,
581
588
E : ToString ,
582
589
{
583
- let env: Vec < u8 > = unsafe { Region :: from_heap_ptr ( env_ptr) . into_vec ( ) } ;
584
- let msg: Vec < u8 > = unsafe { Region :: from_heap_ptr ( msg_ptr) . into_vec ( ) } ;
590
+ let env: Vec < u8 > =
591
+ unsafe { Region :: from_heap_ptr ( ptr:: NonNull :: new ( env_ptr) . unwrap ( ) ) . into_vec ( ) } ;
592
+ let msg: Vec < u8 > =
593
+ unsafe { Region :: from_heap_ptr ( ptr:: NonNull :: new ( msg_ptr) . unwrap ( ) ) . into_vec ( ) } ;
585
594
586
595
let env: Env = try_into_contract_result ! ( from_json( env) ) ;
587
596
let msg: M = try_into_contract_result ! ( from_json( msg) ) ;
@@ -602,9 +611,12 @@ where
602
611
C : CustomMsg ,
603
612
E : ToString ,
604
613
{
605
- let env: Vec < u8 > = unsafe { Region :: from_heap_ptr ( env_ptr) . into_vec ( ) } ;
606
- let msg: Vec < u8 > = unsafe { Region :: from_heap_ptr ( msg_ptr) . into_vec ( ) } ;
607
- let migrate_info = unsafe { Region :: from_heap_ptr ( migrate_info_ptr) . into_vec ( ) } ;
614
+ let env: Vec < u8 > =
615
+ unsafe { Region :: from_heap_ptr ( ptr:: NonNull :: new ( env_ptr) . unwrap ( ) ) . into_vec ( ) } ;
616
+ let msg: Vec < u8 > =
617
+ unsafe { Region :: from_heap_ptr ( ptr:: NonNull :: new ( msg_ptr) . unwrap ( ) ) . into_vec ( ) } ;
618
+ let migrate_info =
619
+ unsafe { Region :: from_heap_ptr ( ptr:: NonNull :: new ( migrate_info_ptr) . unwrap ( ) ) . into_vec ( ) } ;
608
620
609
621
let env: Env = try_into_contract_result ! ( from_json( env) ) ;
610
622
let msg: M = try_into_contract_result ! ( from_json( msg) ) ;
@@ -625,8 +637,10 @@ where
625
637
C : CustomMsg ,
626
638
E : ToString ,
627
639
{
628
- let env: Vec < u8 > = unsafe { Region :: from_heap_ptr ( env_ptr) . into_vec ( ) } ;
629
- let msg: Vec < u8 > = unsafe { Region :: from_heap_ptr ( msg_ptr) . into_vec ( ) } ;
640
+ let env: Vec < u8 > =
641
+ unsafe { Region :: from_heap_ptr ( ptr:: NonNull :: new ( env_ptr) . unwrap ( ) ) . into_vec ( ) } ;
642
+ let msg: Vec < u8 > =
643
+ unsafe { Region :: from_heap_ptr ( ptr:: NonNull :: new ( msg_ptr) . unwrap ( ) ) . into_vec ( ) } ;
630
644
631
645
let env: Env = try_into_contract_result ! ( from_json( env) ) ;
632
646
let msg: M = try_into_contract_result ! ( from_json( msg) ) ;
@@ -645,8 +659,10 @@ where
645
659
C : CustomMsg ,
646
660
E : ToString ,
647
661
{
648
- let env: Vec < u8 > = unsafe { Region :: from_heap_ptr ( env_ptr) . into_vec ( ) } ;
649
- let msg: Vec < u8 > = unsafe { Region :: from_heap_ptr ( msg_ptr) . into_vec ( ) } ;
662
+ let env: Vec < u8 > =
663
+ unsafe { Region :: from_heap_ptr ( ptr:: NonNull :: new ( env_ptr) . unwrap ( ) ) . into_vec ( ) } ;
664
+ let msg: Vec < u8 > =
665
+ unsafe { Region :: from_heap_ptr ( ptr:: NonNull :: new ( msg_ptr) . unwrap ( ) ) . into_vec ( ) } ;
650
666
651
667
let env: Env = try_into_contract_result ! ( from_json( env) ) ;
652
668
let msg: Reply = try_into_contract_result ! ( from_json( msg) ) ;
@@ -665,8 +681,10 @@ where
665
681
M : DeserializeOwned ,
666
682
E : ToString ,
667
683
{
668
- let env: Vec < u8 > = unsafe { Region :: from_heap_ptr ( env_ptr) . into_vec ( ) } ;
669
- let msg: Vec < u8 > = unsafe { Region :: from_heap_ptr ( msg_ptr) . into_vec ( ) } ;
684
+ let env: Vec < u8 > =
685
+ unsafe { Region :: from_heap_ptr ( ptr:: NonNull :: new ( env_ptr) . unwrap ( ) ) . into_vec ( ) } ;
686
+ let msg: Vec < u8 > =
687
+ unsafe { Region :: from_heap_ptr ( ptr:: NonNull :: new ( msg_ptr) . unwrap ( ) ) . into_vec ( ) } ;
670
688
671
689
let env: Env = try_into_contract_result ! ( from_json( env) ) ;
672
690
let msg: M = try_into_contract_result ! ( from_json( msg) ) ;
@@ -684,8 +702,10 @@ where
684
702
Q : CustomQuery ,
685
703
E : ToString ,
686
704
{
687
- let env: Vec < u8 > = unsafe { Region :: from_heap_ptr ( env_ptr) . into_vec ( ) } ;
688
- let msg: Vec < u8 > = unsafe { Region :: from_heap_ptr ( msg_ptr) . into_vec ( ) } ;
705
+ let env: Vec < u8 > =
706
+ unsafe { Region :: from_heap_ptr ( ptr:: NonNull :: new ( env_ptr) . unwrap ( ) ) . into_vec ( ) } ;
707
+ let msg: Vec < u8 > =
708
+ unsafe { Region :: from_heap_ptr ( ptr:: NonNull :: new ( msg_ptr) . unwrap ( ) ) . into_vec ( ) } ;
689
709
690
710
let env: Env = try_into_contract_result ! ( from_json( env) ) ;
691
711
let msg: IbcChannelOpenMsg = try_into_contract_result ! ( from_json( msg) ) ;
@@ -705,8 +725,10 @@ where
705
725
C : CustomMsg ,
706
726
E : ToString ,
707
727
{
708
- let env: Vec < u8 > = unsafe { Region :: from_heap_ptr ( env_ptr) . into_vec ( ) } ;
709
- let msg: Vec < u8 > = unsafe { Region :: from_heap_ptr ( msg_ptr) . into_vec ( ) } ;
728
+ let env: Vec < u8 > =
729
+ unsafe { Region :: from_heap_ptr ( ptr:: NonNull :: new ( env_ptr) . unwrap ( ) ) . into_vec ( ) } ;
730
+ let msg: Vec < u8 > =
731
+ unsafe { Region :: from_heap_ptr ( ptr:: NonNull :: new ( msg_ptr) . unwrap ( ) ) . into_vec ( ) } ;
710
732
711
733
let env: Env = try_into_contract_result ! ( from_json( env) ) ;
712
734
let msg: IbcChannelConnectMsg = try_into_contract_result ! ( from_json( msg) ) ;
@@ -726,8 +748,10 @@ where
726
748
C : CustomMsg ,
727
749
E : ToString ,
728
750
{
729
- let env: Vec < u8 > = unsafe { Region :: from_heap_ptr ( env_ptr) . into_vec ( ) } ;
730
- let msg: Vec < u8 > = unsafe { Region :: from_heap_ptr ( msg_ptr) . into_vec ( ) } ;
751
+ let env: Vec < u8 > =
752
+ unsafe { Region :: from_heap_ptr ( ptr:: NonNull :: new ( env_ptr) . unwrap ( ) ) . into_vec ( ) } ;
753
+ let msg: Vec < u8 > =
754
+ unsafe { Region :: from_heap_ptr ( ptr:: NonNull :: new ( msg_ptr) . unwrap ( ) ) . into_vec ( ) } ;
731
755
732
756
let env: Env = try_into_contract_result ! ( from_json( env) ) ;
733
757
let msg: IbcChannelCloseMsg = try_into_contract_result ! ( from_json( msg) ) ;
@@ -747,8 +771,10 @@ where
747
771
C : CustomMsg ,
748
772
E : ToString ,
749
773
{
750
- let env: Vec < u8 > = unsafe { Region :: from_heap_ptr ( env_ptr) . into_vec ( ) } ;
751
- let msg: Vec < u8 > = unsafe { Region :: from_heap_ptr ( msg_ptr) . into_vec ( ) } ;
774
+ let env: Vec < u8 > =
775
+ unsafe { Region :: from_heap_ptr ( ptr:: NonNull :: new ( env_ptr) . unwrap ( ) ) . into_vec ( ) } ;
776
+ let msg: Vec < u8 > =
777
+ unsafe { Region :: from_heap_ptr ( ptr:: NonNull :: new ( msg_ptr) . unwrap ( ) ) . into_vec ( ) } ;
752
778
753
779
let env: Env = try_into_contract_result ! ( from_json( env) ) ;
754
780
let msg: IbcPacketReceiveMsg = try_into_contract_result ! ( from_json( msg) ) ;
@@ -768,8 +794,10 @@ where
768
794
C : CustomMsg ,
769
795
E : ToString ,
770
796
{
771
- let env: Vec < u8 > = unsafe { Region :: from_heap_ptr ( env_ptr) . into_vec ( ) } ;
772
- let msg: Vec < u8 > = unsafe { Region :: from_heap_ptr ( msg_ptr) . into_vec ( ) } ;
797
+ let env: Vec < u8 > =
798
+ unsafe { Region :: from_heap_ptr ( ptr:: NonNull :: new ( env_ptr) . unwrap ( ) ) . into_vec ( ) } ;
799
+ let msg: Vec < u8 > =
800
+ unsafe { Region :: from_heap_ptr ( ptr:: NonNull :: new ( msg_ptr) . unwrap ( ) ) . into_vec ( ) } ;
773
801
774
802
let env: Env = try_into_contract_result ! ( from_json( env) ) ;
775
803
let msg: IbcPacketAckMsg = try_into_contract_result ! ( from_json( msg) ) ;
@@ -789,8 +817,10 @@ where
789
817
C : CustomMsg ,
790
818
E : ToString ,
791
819
{
792
- let env: Vec < u8 > = unsafe { Region :: from_heap_ptr ( env_ptr) . into_vec ( ) } ;
793
- let msg: Vec < u8 > = unsafe { Region :: from_heap_ptr ( msg_ptr) . into_vec ( ) } ;
820
+ let env: Vec < u8 > =
821
+ unsafe { Region :: from_heap_ptr ( ptr:: NonNull :: new ( env_ptr) . unwrap ( ) ) . into_vec ( ) } ;
822
+ let msg: Vec < u8 > =
823
+ unsafe { Region :: from_heap_ptr ( ptr:: NonNull :: new ( msg_ptr) . unwrap ( ) ) . into_vec ( ) } ;
794
824
795
825
let env: Env = try_into_contract_result ! ( from_json( env) ) ;
796
826
let msg: IbcPacketTimeoutMsg = try_into_contract_result ! ( from_json( msg) ) ;
@@ -809,8 +839,10 @@ where
809
839
C : CustomMsg ,
810
840
E : ToString ,
811
841
{
812
- let env: Vec < u8 > = unsafe { Region :: from_heap_ptr ( env_ptr) . into_vec ( ) } ;
813
- let msg: Vec < u8 > = unsafe { Region :: from_heap_ptr ( msg_ptr) . into_vec ( ) } ;
842
+ let env: Vec < u8 > =
843
+ unsafe { Region :: from_heap_ptr ( ptr:: NonNull :: new ( env_ptr) . unwrap ( ) ) . into_vec ( ) } ;
844
+ let msg: Vec < u8 > =
845
+ unsafe { Region :: from_heap_ptr ( ptr:: NonNull :: new ( msg_ptr) . unwrap ( ) ) . into_vec ( ) } ;
814
846
815
847
let env: Env = try_into_contract_result ! ( from_json( env) ) ;
816
848
let msg: IbcSourceCallbackMsg = try_into_contract_result ! ( from_json( msg) ) ;
@@ -833,8 +865,10 @@ where
833
865
C : CustomMsg ,
834
866
E : ToString ,
835
867
{
836
- let env: Vec < u8 > = unsafe { Region :: from_heap_ptr ( env_ptr) . into_vec ( ) } ;
837
- let msg: Vec < u8 > = unsafe { Region :: from_heap_ptr ( msg_ptr) . into_vec ( ) } ;
868
+ let env: Vec < u8 > =
869
+ unsafe { Region :: from_heap_ptr ( ptr:: NonNull :: new ( env_ptr) . unwrap ( ) ) . into_vec ( ) } ;
870
+ let msg: Vec < u8 > =
871
+ unsafe { Region :: from_heap_ptr ( ptr:: NonNull :: new ( msg_ptr) . unwrap ( ) ) . into_vec ( ) } ;
838
872
839
873
let env: Env = try_into_contract_result ! ( from_json( env) ) ;
840
874
let msg: IbcDestinationCallbackMsg = try_into_contract_result ! ( from_json( msg) ) ;
0 commit comments