Skip to content

Commit 40cc4e4

Browse files
committed
py/objtype: Make mp_obj_new_type a static function.
It's only used once, in the same file it's defined, and making it static reduces code size. Along with this, the associated example code comment in `ports/unix/main.c` has been removed. Signed-off-by: Damien George <damien@micropython.org>
1 parent 3efbd72 commit 40cc4e4

File tree

3 files changed

+2
-15
lines changed

3 files changed

+2
-15
lines changed

ports/unix/main.c

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -616,19 +616,6 @@ MP_NOINLINE int main_(int argc, char **argv) {
616616
}
617617
#endif
618618

619-
// Here is some example code to create a class and instance of that class.
620-
// First is the Python, then the C code.
621-
//
622-
// class TestClass:
623-
// pass
624-
// test_obj = TestClass()
625-
// test_obj.attr = 42
626-
//
627-
// mp_obj_t test_class_type, test_class_instance;
628-
// test_class_type = mp_obj_new_type(qstr_from_str("TestClass"), mp_const_empty_tuple, mp_obj_new_dict(0));
629-
// mp_store_name(qstr_from_str("test_obj"), test_class_instance = mp_call_function_0(test_class_type));
630-
// mp_store_attr(test_class_instance, qstr_from_str("attr"), mp_obj_new_int(42));
631-
632619
/*
633620
printf("bytes:\n");
634621
printf(" total %d\n", m_get_total_bytes_allocated());

py/obj.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -987,7 +987,6 @@ void *mp_obj_malloc_with_finaliser_helper(size_t num_bytes, const mp_obj_type_t
987987
bool mp_obj_is_dict_or_ordereddict(mp_obj_t o);
988988
#define mp_obj_is_fun(o) (mp_obj_is_obj(o) && (((mp_obj_base_t *)MP_OBJ_TO_PTR(o))->type->name == MP_QSTR_function))
989989

990-
mp_obj_t mp_obj_new_type(qstr name, mp_obj_t bases_tuple, mp_obj_t locals_dict);
991990
static inline mp_obj_t mp_obj_new_bool(mp_int_t x) {
992991
return x ? mp_const_true : mp_const_false;
993992
}

py/objtype.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@
4444
#define ENABLE_SPECIAL_ACCESSORS \
4545
(MICROPY_PY_DESCRIPTORS || MICROPY_PY_DELATTR_SETATTR || MICROPY_PY_BUILTINS_PROPERTY)
4646

47+
static mp_obj_t mp_obj_new_type(qstr name, mp_obj_t bases_tuple, mp_obj_t locals_dict);
4748
static mp_obj_t mp_obj_is_subclass(mp_obj_t object, mp_obj_t classinfo);
4849
static mp_obj_t static_class_method_make_new(const mp_obj_type_t *self_in, size_t n_args, size_t n_kw, const mp_obj_t *args);
4950

@@ -1164,7 +1165,7 @@ MP_DEFINE_CONST_OBJ_TYPE(
11641165
attr, type_attr
11651166
);
11661167

1167-
mp_obj_t mp_obj_new_type(qstr name, mp_obj_t bases_tuple, mp_obj_t locals_dict) {
1168+
static mp_obj_t mp_obj_new_type(qstr name, mp_obj_t bases_tuple, mp_obj_t locals_dict) {
11681169
// Verify input objects have expected type
11691170
if (!mp_obj_is_type(bases_tuple, &mp_type_tuple)) {
11701171
mp_raise_TypeError(NULL);

0 commit comments

Comments
 (0)