You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
openCtypesopenForeigntypetlett_typ : t structure typ = structure "Time_val"let f_tv_sec = field t_typ "tv_sec" (int64_t)
let f_tv_usec = field t_typ "tv_usec" (int64_t)
let _ = seal t_typ
let get_current_time =
foreign "g_get_current_time" (ptr Time_val.t_typ @-> returning (void))
In the tests:
lettest_time_val_from_iso8601test_ctxt=let iso8601 ="2018-02-07T10:39:38Z"inmatchGLib.Time_val.from_iso8601 iso8601 with| (false, _) -> assert_equal ~msg:"No time val"truefalse| (true, tv) -> let dt =GLib.Date_time.create_from_timeval_utc (Ctypes.addr tv) inlet (y,m,d) =GLib.Date_time.get_ymd dt inlet _ = assert_equal_int32 (Int32.of_int 2018) y inlet _ = assert_equal_int32 (Int32.of_int 2) m in
assert_equal_int32 (Int32.of_int 07) d
lettest_core_get_current_time_and_to_iso8601test_ctxt=let tv =Ctypes.make GLib.Time_val.t_typ inlet tv_ptr =Ctypes.addr tv inlet _ =GLib.Core.get_current_time tv_ptr inmatchGLib.Time_val.to_iso8601 tv_ptr with|None -> assert_equal ~msg:"No iso8601 from Timeval"truefalse|Someiso8601 -> let now =GLib.Date_time.create_now_local ()inlet (year, month, day) =GLib.Date_time.get_ymd now inlet dt =GLib.Date_time.create_from_timeval_utc tv_ptr inlet (y,m,d) =GLib.Date_time.get_ymd dt inlet _ = assert_equal_int32 year y inlet _ = assert_equal_int32 month m in
assert_equal_int32 day d
The construction of Timeval.from_iso8601 is not clear because, it make locally a structure that is used
as default value for during the allocation of a structure Time_val on the heap then the pointer is passed to the function in order to fill the structure in the heap, then I get the value of the pointer (ie the structure)
Question: why not return a pointer ? Is it possible ?
The text was updated successfully, but these errors were encountered:
An example is the
Time_val.t
structure.The two functions in the
Time_val
module:And the function in the
Core
module:In the tests:
The construction of
Timeval.from_iso8601
is not clear because, it make locally a structure that is usedas default value for during the allocation of a structure Time_val on the heap then the pointer is passed to the function in order to fill the structure in the heap, then I get the value of the pointer (ie the structure)
Question: why not return a pointer ? Is it possible ?
The text was updated successfully, but these errors were encountered: