Skip to content

Commit c816ab2

Browse files
authored
Merge pull request #32 from drujensen/dj/support-latest-mojo-version
fix: support Mojo 24.3
2 parents 92d0748 + b9b181b commit c816ab2

File tree

5 files changed

+18
-52
lines changed

5 files changed

+18
-52
lines changed

external/libc.mojo

Lines changed: 1 addition & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -13,37 +13,6 @@ alias GRND_NONBLOCK: UInt8 = 1
1313

1414
alias char_pointer = AnyPointer[c_char]
1515

16-
17-
# @value
18-
# struct Str:
19-
# var vector: List[c_char]
20-
21-
# fn __init__(inout self, string: String):
22-
# self.vector = List[c_char](capacity=len(string) + 1)
23-
# for i in range(len(string)):
24-
# self.vector.push_back(ord(string[i]))
25-
# self.vector.push_back(0)
26-
27-
# fn __init__(inout self, size: Int):
28-
# self.vector = List[c_char]()
29-
# self.vector.resize(size + 1, 0)
30-
31-
# fn __len__(self) -> Int:
32-
# for i in range(len(self.vector)):
33-
# if self.vector[i] == 0:
34-
# return i
35-
# return -1
36-
37-
# fn to_string(self, size: Int) -> String:
38-
# var result: String = ""
39-
# for i in range(size):
40-
# result += chr(self.vector[i].to_int())
41-
# return result
42-
43-
# fn __enter__(owned self: Self) -> Self:
44-
# return self ^
45-
46-
4716
# Adapted from https://github.com/crisadamo/mojo-Libc . Huge thanks to Cristian!
4817
# C types
4918
alias c_void = UInt8
@@ -751,7 +720,7 @@ fn inet_pton(address_family: Int, address: String) -> Int:
751720
var conv_status = inet_pton(
752721
rebind[c_int](address_family), to_char_ptr(address), ip_buf
753722
)
754-
return ip_buf.bitcast[c_uint]().load().to_int()
723+
return int(ip_buf.bitcast[c_uint]().load())
755724

756725

757726
# --- ( File Related Syscalls & Structs )---------------------------------------

external/morrow.mojo

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ struct TimeZone:
5151
@staticmethod
5252
fn local() -> TimeZone:
5353
var local_t = c_localtime(0)
54-
return TimeZone(local_t.tm_gmtoff.to_int(), "local")
54+
return TimeZone(int(local_t.tm_gmtoff), "local")
5555

5656
@staticmethod
5757
fn from_utc(utc_str: String) raises -> TimeZone:
@@ -247,15 +247,15 @@ struct Morrow:
247247
tz = TimeZone(0, "UTC")
248248
else:
249249
tm = c_localtime(t.tv_sec)
250-
tz = TimeZone(tm.tm_gmtoff.to_int(), "local")
250+
tz = TimeZone(int(tm.tm_gmtoff), "local")
251251

252252
var result = Self(
253-
tm.tm_year.to_int() + 1900,
254-
tm.tm_mon.to_int() + 1,
255-
tm.tm_mday.to_int(),
256-
tm.tm_hour.to_int(),
257-
tm.tm_min.to_int(),
258-
tm.tm_sec.to_int(),
253+
int(tm.tm_year) + 1900,
254+
int(tm.tm_mon) + 1,
255+
int(tm.tm_mday),
256+
int(tm.tm_hour),
257+
int(tm.tm_min),
258+
int(tm.tm_sec),
259259
t.tv_usec,
260260
tz,
261261
)
@@ -264,13 +264,13 @@ struct Morrow:
264264
@staticmethod
265265
fn fromtimestamp(timestamp: Float64) raises -> Self:
266266
var timestamp_ = normalize_timestamp(timestamp)
267-
var t = CTimeval(timestamp_.to_int())
267+
var t = CTimeval(int(timestamp_))
268268
return Self._fromtimestamp(t, False)
269269

270270
@staticmethod
271271
fn utcfromtimestamp(timestamp: Float64) raises -> Self:
272272
var timestamp_ = normalize_timestamp(timestamp)
273-
var t = CTimeval(timestamp_.to_int())
273+
var t = CTimeval(int(timestamp_))
274274
return Self._fromtimestamp(t, True)
275275

276276

lightbug_http/__init__.mojo

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,5 @@ from lightbug_http.sys.server import SysServer
44

55

66
trait DefaultConstructible:
7-
fn __init__(inout self):
7+
fn __init__(inout self) raises:
88
...

lightbug_http/net.mojo

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ alias default_tcp_keep_alive = Duration(15 * 1000 * 1000 * 1000) # 15 seconds
1919

2020

2121
trait Net(DefaultConstructible):
22-
fn __init__(inout self):
22+
fn __init__(inout self) raises:
2323
...
2424

2525
fn __init__(inout self, keep_alive: Duration) raises:
@@ -284,4 +284,4 @@ fn get_peer_name(fd: Int32) raises -> HostPort:
284284
return HostPort(
285285
host=convert_binary_ip_to_string(addr_in.sin_addr.s_addr, AF_INET, 16),
286286
port=convert_binary_port_to_int(addr_in.sin_port),
287-
)
287+
)

lightbug_http/sys/net.mojo

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -128,10 +128,10 @@ struct SysListenConfig(ListenConfig):
128128
var __keep_alive: Duration
129129

130130
fn __init__(inout self) raises:
131-
self.__keep_alive = Duration(default_tcp_keep_alive)
131+
self.__keep_alive = default_tcp_keep_alive
132132

133133
fn __init__(inout self, keep_alive: Duration) raises:
134-
self.__keep_alive = Duration(keep_alive)
134+
self.__keep_alive = keep_alive
135135

136136
fn listen(inout self, network: String, address: String) raises -> SysListener:
137137
var addr = resolve_internet_addr(network, address)
@@ -235,11 +235,8 @@ struct SysConnection(Connection):
235235
struct SysNet(Net):
236236
var __lc: SysListenConfig
237237

238-
fn __init__(inout self):
239-
try:
240-
self.__lc = SysListenConfig(default_tcp_keep_alive)
241-
except e:
242-
print("Could not initialize SysListenConfig: " + e.__str__())
238+
fn __init__(inout self) raises:
239+
self.__lc = SysListenConfig(default_tcp_keep_alive)
243240

244241
fn __init__(inout self, keep_alive: Duration) raises:
245242
self.__lc = SysListenConfig(keep_alive)

0 commit comments

Comments
 (0)