Skip to content

Commit f44b6be

Browse files
committed
use generic hash routine where possible
1 parent 9717fd2 commit f44b6be

File tree

3 files changed

+22
-45
lines changed

3 files changed

+22
-45
lines changed

shared-bindings/microcontroller/Pin.c

Lines changed: 8 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,12 @@
4343
//| ...
4444
//|
4545

46+
//| def __hash__(self) -> int:
47+
//| """Returns a hash for the Pin."""
48+
//| ...
49+
//|
50+
// Provided by mp_generic_unary_op().
51+
4652
static void get_pin_name(const mcu_pin_obj_t *self, qstr *package, qstr *module, qstr *name) {
4753
const mp_map_t *board_map = &board_module_globals.map;
4854
for (uint8_t i = 0; i < board_map->alloc; i++) {
@@ -78,27 +84,13 @@ STATIC void mcu_pin_print(const mp_print_t *print, mp_obj_t self_in, mp_print_ki
7884
}
7985
}
8086

81-
//| def __hash__(self) -> int:
82-
//| """Returns a hash for the Pin."""
83-
//| ...
84-
//|
85-
STATIC mp_obj_t mcu_pin_unary_op(mp_unary_op_t op, mp_obj_t self_in) {
86-
switch (op) {
87-
case MP_UNARY_OP_HASH: {
88-
return mp_obj_id(self_in);
89-
}
90-
default:
91-
return MP_OBJ_NULL; // op not supported
92-
}
93-
}
94-
9587
const mp_obj_type_t mcu_pin_type = {
9688
{ &mp_type_type },
9789
.flags = MP_TYPE_FLAG_EXTENDED,
9890
.name = MP_QSTR_Pin,
9991
.print = mcu_pin_print,
10092
MP_TYPE_EXTENDED_FIELDS(
101-
.unary_op = mcu_pin_unary_op,
93+
.unary_op = mp_generic_unary_op,
10294
)
10395
};
10496

@@ -202,3 +194,4 @@ void validate_pins(qstr what, uint8_t *pin_nos, mp_int_t max_pins, mp_obj_t seq,
202194
pin_nos[i] = common_hal_mcu_pin_number(pins[i]);
203195
}
204196
}
197+
<

shared-bindings/socketpool/Socket.c

Lines changed: 7 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,12 @@
4646
//| recv that do not allocate bytes objects."""
4747
//|
4848

49+
//| def __hash__(self) -> int:
50+
//| """Returns a hash for the Socket."""
51+
//| ...
52+
//|
53+
// Provided by mp_generic_unary_op().
54+
4955
//| def __enter__(self) -> Socket:
5056
//| """No-op used by Context Managers."""
5157
//| ...
@@ -366,20 +372,6 @@ STATIC mp_obj_t socketpool_socket_settimeout(mp_obj_t self_in, mp_obj_t timeout_
366372
}
367373
STATIC MP_DEFINE_CONST_FUN_OBJ_2(socketpool_socket_settimeout_obj, socketpool_socket_settimeout);
368374

369-
//| def __hash__(self) -> int:
370-
//| """Returns a hash for the Socket."""
371-
//| ...
372-
//|
373-
STATIC mp_obj_t socketpool_socket_unary_op(mp_unary_op_t op, mp_obj_t self_in) {
374-
switch (op) {
375-
case MP_UNARY_OP_HASH: {
376-
return mp_obj_id(self_in);
377-
}
378-
default:
379-
return MP_OBJ_NULL; // op not supported
380-
}
381-
}
382-
383375
STATIC const mp_rom_map_elem_t socketpool_socket_locals_dict_table[] = {
384376
{ MP_ROM_QSTR(MP_QSTR___enter__), MP_ROM_PTR(&default___enter___obj) },
385377
{ MP_ROM_QSTR(MP_QSTR___exit__), MP_ROM_PTR(&socketpool_socket___exit___obj) },
@@ -407,6 +399,6 @@ const mp_obj_type_t socketpool_socket_type = {
407399
.name = MP_QSTR_Socket,
408400
.locals_dict = (mp_obj_dict_t *)&socketpool_socket_locals_dict,
409401
MP_TYPE_EXTENDED_FIELDS(
410-
.unary_op = socketpool_socket_unary_op,
402+
.unary_op = mp_generic_unary_op,
411403
)
412404
};

shared-bindings/ssl/SSLSocket.c

Lines changed: 7 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,12 @@
4545
//| recv that do not allocate bytes objects."""
4646
//|
4747

48+
//| def __hash__(self) -> int:
49+
//| """Returns a hash for the Socket."""
50+
//| ...
51+
//|
52+
// Provided by mp_generic_unary_op().
53+
4854
//| def __enter__(self) -> SSLSocket:
4955
//| """No-op used by Context Managers."""
5056
//| ...
@@ -282,20 +288,6 @@ STATIC mp_obj_t ssl_sslsocket_setblocking(mp_obj_t self_in, mp_obj_t blocking) {
282288
}
283289
STATIC MP_DEFINE_CONST_FUN_OBJ_2(ssl_sslsocket_setblocking_obj, ssl_sslsocket_setblocking);
284290

285-
//| def __hash__(self) -> int:
286-
//| """Returns a hash for the Socket."""
287-
//| ...
288-
//|
289-
STATIC mp_obj_t ssl_sslsocket_unary_op(mp_unary_op_t op, mp_obj_t self_in) {
290-
switch (op) {
291-
case MP_UNARY_OP_HASH: {
292-
return mp_obj_id(self_in);
293-
}
294-
default:
295-
return MP_OBJ_NULL; // op not supported
296-
}
297-
}
298-
299291
STATIC const mp_rom_map_elem_t ssl_sslsocket_locals_dict_table[] = {
300292
{ MP_ROM_QSTR(MP_QSTR___enter__), MP_ROM_PTR(&default___enter___obj) },
301293
{ MP_ROM_QSTR(MP_QSTR___exit__), MP_ROM_PTR(&ssl_sslsocket___exit___obj) },
@@ -321,6 +313,6 @@ const mp_obj_type_t ssl_sslsocket_type = {
321313
.name = MP_QSTR_SSLSocket,
322314
.locals_dict = (mp_obj_dict_t *)&ssl_sslsocket_locals_dict,
323315
MP_TYPE_EXTENDED_FIELDS(
324-
.unary_op = ssl_sslsocket_unary_op,
316+
.unary_op = mp_generic_unary_op,
325317
)
326318
};

0 commit comments

Comments
 (0)