Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commita7c3f85

Browse files
authored
Merge pull requestRustPython#595 from palaviv/socket-user-macros
Use py_class and py_module macros in socket
2 parents38c43e0 +933c8dc commita7c3f85

File tree

1 file changed

+19
-29
lines changed

1 file changed

+19
-29
lines changed

‎vm/src/stdlib/socket.rs‎

Lines changed: 19 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -420,34 +420,24 @@ fn get_addr_tuple(vm: &mut VirtualMachine, addr: SocketAddr) -> PyResult {
420420
}
421421

422422
pubfnmk_module(ctx:&PyContext) ->PyObjectRef{
423-
let py_mod = ctx.new_module(&"socket".to_string(), ctx.new_scope(None));
424-
425-
ctx.set_attr(&py_mod,"AF_INET", ctx.new_int(AddressFamily::Inetasi32));
426-
427-
ctx.set_attr(
428-
&py_mod,
429-
"SOCK_STREAM",
430-
ctx.new_int(SocketKind::Streamasi32),
431-
);
432-
433-
ctx.set_attr(&py_mod,"SOCK_DGRAM", ctx.new_int(SocketKind::Dgramasi32));
434-
435-
let socket ={
436-
let socket = ctx.new_class("socket", ctx.object());
437-
ctx.set_attr(&socket,"__new__", ctx.new_rustfunc(socket_new));
438-
ctx.set_attr(&socket,"connect", ctx.new_rustfunc(socket_connect));
439-
ctx.set_attr(&socket,"recv", ctx.new_rustfunc(socket_recv));
440-
ctx.set_attr(&socket,"send", ctx.new_rustfunc(socket_send));
441-
ctx.set_attr(&socket,"bind", ctx.new_rustfunc(socket_bind));
442-
ctx.set_attr(&socket,"accept", ctx.new_rustfunc(socket_accept));
443-
ctx.set_attr(&socket,"listen", ctx.new_rustfunc(socket_listen));
444-
ctx.set_attr(&socket,"close", ctx.new_rustfunc(socket_close));
445-
ctx.set_attr(&socket,"getsockname", ctx.new_rustfunc(socket_getsockname));
446-
ctx.set_attr(&socket,"sendto", ctx.new_rustfunc(socket_sendto));
447-
ctx.set_attr(&socket,"recvfrom", ctx.new_rustfunc(socket_recvfrom));
448-
socket
449-
};
450-
ctx.set_attr(&py_mod,"socket", socket.clone());
423+
let socket =py_class!(ctx,"socket", ctx.object(),{
424+
"__new__" => ctx.new_rustfunc(socket_new),
425+
"connect" => ctx.new_rustfunc(socket_connect),
426+
"recv" => ctx.new_rustfunc(socket_recv),
427+
"send" => ctx.new_rustfunc(socket_send),
428+
"bind" => ctx.new_rustfunc(socket_bind),
429+
"accept" => ctx.new_rustfunc(socket_accept),
430+
"listen" => ctx.new_rustfunc(socket_listen),
431+
"close" => ctx.new_rustfunc(socket_close),
432+
"getsockname" => ctx.new_rustfunc(socket_getsockname),
433+
"sendto" => ctx.new_rustfunc(socket_sendto),
434+
"recvfrom" => ctx.new_rustfunc(socket_recvfrom),
435+
});
451436

452-
py_mod
437+
py_module!(ctx,"socket",{
438+
"AF_INET" => ctx.new_int(AddressFamily::Inetasi32),
439+
"SOCK_STREAM" => ctx.new_int(SocketKind::Streamasi32),
440+
"SOCK_DGRAM" => ctx.new_int(SocketKind::Dgramasi32),
441+
"socket" => socket.clone(),
442+
})
453443
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp