@@ -36,27 +36,43 @@ impl Function {
36
36
ret_type : & Option < PyTypeRef > ,
37
37
vm : & VirtualMachine ,
38
38
) -> PyResult < Self > {
39
- dbg ! ( "Start load" ) ;
40
39
// map each arg to a PyCSimple
41
40
let args = args
42
41
. iter ( )
43
42
. map ( |arg| {
44
43
if let Some ( arg) = arg. payload_if_subclass :: < PyCSimple > ( vm) {
45
- dbg ! ( arg) ;
46
44
let converted = ffi_type_from_str ( & arg. _type_ ) ;
47
- dbg ! ( & converted) ;
48
- match converted {
45
+ return match converted {
49
46
Some ( t) => Ok ( t) ,
50
47
None => Err ( vm. new_type_error ( format ! (
51
48
"Invalid type" // TODO: add type name
52
49
) ) ) ,
53
- }
50
+ } ;
51
+ }
52
+ if let Some ( arg) = arg. payload_if_subclass :: < PyCArray > ( vm) {
53
+ let t = arg. typ . read ( ) ;
54
+ let ty_attributes = t. attributes . read ( ) ;
55
+ let ty_pystr = ty_attributes. get ( vm. ctx . intern_str ( "_type_" ) ) . ok_or_else ( || {
56
+ vm. new_type_error ( "Expected a ctypes simple type" . to_string ( ) )
57
+ } ) ?;
58
+ let ty_str = ty_pystr. downcast_ref :: < PyStr > ( ) . ok_or_else ( || {
59
+ vm. new_type_error ( "Expected a ctypes simple type" . to_string ( ) )
60
+ } ) ?. to_string ( ) ;
61
+ let converted = ffi_type_from_str ( & ty_str) ;
62
+ return match converted {
63
+ Some ( _t) => {
64
+ // TODO: Use
65
+ Ok ( Type :: void ( ) )
66
+ }
67
+ None => Err ( vm. new_type_error ( format ! (
68
+ "Invalid type" // TODO: add type name
69
+ ) ) ) ,
70
+ } ;
54
71
} else {
55
72
Err ( vm. new_type_error ( "Expected a ctypes simple type" . to_string ( ) ) )
56
73
}
57
74
} )
58
75
. collect :: < PyResult < Vec < Type > > > ( ) ?;
59
- dbg ! ( ) ;
60
76
let terminated = format ! ( "{}\0 " , function) ;
61
77
let pointer: Symbol < ' _ , FP > = unsafe {
62
78
library
@@ -73,7 +89,6 @@ impl Function {
73
89
None => Type :: c_int ( ) ,
74
90
} ;
75
91
let cif = Cif :: new ( args. clone ( ) , return_type) ;
76
- dbg ! ( ) ;
77
92
Ok ( Function {
78
93
args,
79
94
cif,
@@ -86,30 +101,26 @@ impl Function {
86
101
args : Vec < PyObjectRef > ,
87
102
vm : & VirtualMachine ,
88
103
) -> PyResult < PyObjectRef > {
89
- dbg ! ( "Start call" ) ;
90
104
let args = args
91
105
. into_iter ( )
92
106
. enumerate ( )
93
107
. map ( |( count, arg) | {
94
- dbg ! ( "Arg iter" , & arg) ;
95
- dbg ! ( & arg) ;
108
+ // none type check
109
+ if vm. is_none ( & arg) {
110
+ return Ok ( Arg :: new ( std:: ptr:: null ( ) ) ) ;
111
+ }
96
112
if let Some ( d) = arg. payload_if_subclass :: < PyCSimple > ( vm) {
97
- dbg ! ( d) ;
98
- dbg ! ( & d. _type_) ;
99
- unsafe {
100
- dbg ! ( d. value. as_ptr( ) . as_ref( ) . unwrap( ) ) ;
101
- }
102
113
return Ok ( d. to_arg ( self . args [ count] . clone ( ) , vm) . unwrap ( ) ) ;
103
114
}
104
115
if let Some ( d) = arg. payload_if_subclass :: < PyCArray > ( vm) {
105
- dbg ! ( d ) ;
116
+ return Ok ( d . to_arg ( vm ) . unwrap ( ) ) ;
106
117
}
107
118
Err ( vm. new_type_error ( "Expected a ctypes simple type" . to_string ( ) ) )
108
119
} )
109
120
. collect :: < PyResult < Vec < Arg > > > ( ) ?;
110
- // TODO: FIX return type
121
+ dbg ! ( & args) ;
122
+ // TODO: FIX return
111
123
let result: i32 = unsafe { self . cif . call ( self . pointer , & args) } ;
112
- dbg ! ( "Almost end call" ) ;
113
124
Ok ( vm. ctx . new_int ( result) . into ( ) )
114
125
}
115
126
}
0 commit comments