Skip to content

Use py_class and py_module macros in socket #595

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Mar 4, 2019
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Use py_module macro
  • Loading branch information
palaviv committed Mar 4, 2019
commit 933c8dc792c016206c9797d736f8c181eb9310df
20 changes: 6 additions & 14 deletions vm/src/stdlib/socket.rs
Original file line number Diff line number Diff line change
Expand Up @@ -420,18 +420,6 @@ fn get_addr_tuple(vm: &mut VirtualMachine, addr: SocketAddr) -> PyResult {
}

pub fn mk_module(ctx: &PyContext) -> PyObjectRef {
let py_mod = ctx.new_module(&"socket".to_string(), ctx.new_scope(None));

ctx.set_attr(&py_mod, "AF_INET", ctx.new_int(AddressFamily::Inet as i32));

ctx.set_attr(
&py_mod,
"SOCK_STREAM",
ctx.new_int(SocketKind::Stream as i32),
);

ctx.set_attr(&py_mod, "SOCK_DGRAM", ctx.new_int(SocketKind::Dgram as i32));

let socket = py_class!(ctx, "socket", ctx.object(), {
"__new__" => ctx.new_rustfunc(socket_new),
"connect" => ctx.new_rustfunc(socket_connect),
Expand All @@ -445,7 +433,11 @@ pub fn mk_module(ctx: &PyContext) -> PyObjectRef {
"sendto" => ctx.new_rustfunc(socket_sendto),
"recvfrom" => ctx.new_rustfunc(socket_recvfrom),
});
ctx.set_attr(&py_mod, "socket", socket.clone());

py_mod
py_module!(ctx, "socket", {
"AF_INET" => ctx.new_int(AddressFamily::Inet as i32),
"SOCK_STREAM" => ctx.new_int(SocketKind::Stream as i32),
"SOCK_DGRAM" => ctx.new_int(SocketKind::Dgram as i32),
"socket" => socket.clone(),
})
}