Opened 6 years ago

Closed 6 years ago

#277 closed ожидается проверка (задача сдана)

HW 4

Reported by: Илья Куроптев Owned by: rutsky,grabovoy.philipp
Priority: проверка Milestone: ha4-deadline
Component: HA#4 function Version: 1.0
Keywords: Cc:

Description


Change History (20)

comment:1 Changed 6 years ago by Vladimir Rutsky

Илья, я не могу найти ваше решение в репозитории svn, вы уверены, что закоммитили его?

comment:2 Changed 6 years ago by cpptester

Type: ожидается проверкаожидаются исправления

Tested revision 679 by kuroptev.ilya.

Smoke tests

test

stage

result

info

log

run_function_smoke_test.cpp

WARNING

run_function_smoke_test-gcc62.log

SUCCESS
SUCCESS

run_function_smoke_test-valgrind.log

WARNING

run_function_smoke_test-gcc62-asan.log

SUCCESS
WARNING

run_function_smoke_test-clang-san.log

SUCCESS

Common header used in some tests: common.h

comment:3 Changed 6 years ago by cpptester

Tested revision 681 by kuroptev.ilya.

Main tests

test

stage

result

info

log

comp_all_sufficient.cpp

FAILURE

comp_all_sufficient-gcc62.log

comp_include_guard.cpp

FAILURE

comp_include_guard-gcc62.log

comp_operator_bool_const.cpp

FAILURE

comp_operator_bool_const-gcc62.log

run_free_function.cpp

SUCCESS
FAILURE

exit code 139

run_free_function-run.log

run_functor_copied.cpp

SUCCESS
FAILURE

exit code 139

run_functor_copied-run.log

Common header used in some tests: common.h

comment:4 Changed 6 years ago by cpptester

Tested revision 682 by kuroptev.ilya.

Main tests

test

stage

result

info

log

comp_all_sufficient.cpp

FAILURE

comp_all_sufficient-gcc62.log

comp_include_guard.cpp

FAILURE

comp_include_guard-gcc62.log

comp_operator_bool_const.cpp

FAILURE

comp_operator_bool_const-gcc62.log

run_free_function.cpp

SUCCESS
FAILURE

exit code 139

run_free_function-run.log

run_functor_copied.cpp

SUCCESS
FAILURE

exit code 139

run_functor_copied-run.log

Common header used in some tests: common.h

comment:5 Changed 6 years ago by cpptester

Tested revision 684 by kuroptev.ilya.

Main tests

test

stage

result

info

log

ncomp_function_explicit_operator_bool.cpp

FAILURE

run_free_function.cpp

SUCCESS
FAILURE

exit code 139

run_free_function-run.log

run_functor_copied.cpp

SUCCESS
FAILURE

exit code 139

run_functor_copied-run.log

Common header used in some tests: common.h

comment:6 Changed 6 years ago by cpptester

Tested revision 684 by kuroptev.ilya.

Main tests

test

stage

result

info

log

ncomp_function_explicit_operator_bool.cpp

FAILURE

run_free_function.cpp

SUCCESS
FAILURE

exit code 139

run_free_function-run.log

run_functor_copied.cpp

SUCCESS
FAILURE

exit code 139

run_functor_copied-run.log

run_functor_desctructor.cpp

SUCCESS
FAILURE

exit code 139

run_functor_desctructor-run.log

Common header used in some tests: common.h

comment:7 Changed 6 years ago by cpptester

Tested revision 684 by kuroptev.ilya.

Main tests

test

stage

result

info

log

ncomp_function_explicit_operator_bool.cpp

FAILURE

run_free_function.cpp

SUCCESS
FAILURE

exit code 139

run_free_function-run.log

run_functor_copied.cpp

SUCCESS
FAILURE

exit code 139

run_functor_copied-run.log

run_functor_desctructor.cpp

SUCCESS
FAILURE

exit code 139

run_functor_desctructor-run.log

Common header used in some tests: common.h

comment:8 Changed 6 years ago by cpptester

Tested revision 684 by kuroptev.ilya.

Main tests

test

stage

result

info

log

ncomp_function_explicit_operator_bool.cpp

FAILURE

run_free_function.cpp

SUCCESS
FAILURE

exit code 139

run_free_function-run.log

run_functor_copied.cpp

SUCCESS
FAILURE

exit code 139

run_functor_copied-run.log

Common header used in some tests: common.h

comment:9 Changed 6 years ago by Vladimir Rutsky

Илья, исправьте, пожалуйста, ваше решение, чтобы оно проходило автотесты. Если есть вопросы по поводу падающих тестов --- пишите.

comment:10 Changed 6 years ago by cpptester

Tested revision 717 by kuroptev.ilya.

Main tests

test

stage

result

info

log

comp_all_sufficient.cpp

FAILURE

comp_all_sufficient-gcc62.log

comp_include_guard.cpp

FAILURE

comp_include_guard-gcc62.log

comp_operator_bool_const.cpp

FAILURE

comp_operator_bool_const-gcc62.log

run_functor_copied.cpp

SUCCESS
FAILURE

exit code 139

run_functor_copied-run.log

Common header used in some tests: common.h

comment:11 Changed 6 years ago by cpptester

Tested revision 719 by kuroptev.ilya.

Smoke tests

test

stage

result

info

log

run_function_smoke_test.cpp

SUCCESS
SUCCESS
SUCCESS

run_function_smoke_test-valgrind.log

SUCCESS
FAILURE

exit code 1

run_function_smoke_test-asan.log

SUCCESS
SUCCESS

Common header used in some tests: common.h

comment:12 Changed 6 years ago by cpptester

Tested revision 723 by kuroptev.ilya.

Smoke tests

test

stage

result

info

log

run_function_smoke_test.cpp

SUCCESS
SUCCESS
SUCCESS

run_function_smoke_test-valgrind.log

SUCCESS
FAILURE

exit code 1

run_function_smoke_test-asan.log

SUCCESS
SUCCESS

Common header used in some tests: common.h

comment:13 Changed 6 years ago by Vladimir Rutsky

Про падение ASAN.

Ошибка: AddressSanitizer: new-delete-type-mismatch --- похоже, что указатель указывает на созданный объект одного типа, а удаляется как объект другого типа (например, в результате некорректного приведения типов где-то по дороге).

Далее идёт информация про размеры: объект создан как структура из 16 байт, а удаляется как структура из 8 байт:

  object passed to delete has wrong type:
  size of the allocated type:   16 bytes;
  size of the deallocated type: 8 bytes.

Далее идёт стек-трейс, где объект удаляется:

...
    #5 0x40ae2d in std::shared_ptr<fn::function<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > (int)>::CallableBase>::~shared_ptr() /usr/include/c++/6/bits/shared_ptr.h:93
    #6 0x40ae4d in fn::function<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > (int)>::~function() /mnt/src/fn.hpp:31

это деструктор function, который вызывает деструктор shared_ptr --- значит внутри shared_ptr используется не тот деструктор для типа (либо из-за приведения типов, либо из-за чего то ещё).

Далее идёт стек-трейс где объект был создан:

    #0 0x7fbed4025f60 in operator new(unsigned long) (/usr/lib/x86_64-linux-gnu/libasan.so.3+0xc7f60)
    #1 0x409aca in clone /mnt/src/fn.hpp:56
    #2 0x41150e in fn::function<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > (int)>::operator=(fn::function<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > (int)> const&) /mnt/src/fn.hpp:147

Из всего этого получается примерно следующая выжимка:

    template <class R, class ... Argss>
    class function <R(Argss ...)>
    {
    private:
...
        std::shared_ptr<CallableBase> pFunctor;
...

        class CallableBase
        {
        public:
            virtual R operator()(Argss&& ... args) = 0;
            virtual CallableBase* clone() = 0;
        };
...
        class Callable: public CallableBase
...

            CallableBase* clone()
            {
                return new Callable<F>(f);
            }
...
        function& operator=(const function& fun)
        {
...
                    pFunctor = std::shared_ptr<CallableBase>((*fun.pFunctor).clone());
...
        }

clone() возвращает указатель на базовый класс (CallableBase) и shared_ptr впоследствии удаляет именно его. Есть приведение к базовому типу.

Вопрос: почему вызывается десткрутор базового класса, а не производного и как сделать так, чтобы вызывался деструктор производного класса?

comment:14 Changed 6 years ago by cpptester

Tested revision 726 by kuroptev.ilya.

All tests passed. Good job!

comment:15 Changed 6 years ago by cpptester

Tested revision 727 by kuroptev.ilya.

All tests passed. Good job!

comment:16 Changed 6 years ago by Илья Куроптев

Type: ожидаются исправленияожидается проверка

comment:17 Changed 6 years ago by Vladimir Rutsky

Milestone: ha4-milestone2ha4-deadline
Type: ожидается проверкаожидаются исправления

Замечания:

  1. Вместо отдельного поля Holder status_; стоит использовать значения pFunction_ и pFunctor_ (если оба nullptr, то Empty, и т.п.). Вы можете заменить Holder status_; на приватный метод status, который будет возращать значение enum Holder --- благодаря оптимизациям это будет также эффективно как проверять status_ inline в методах, но код может получиться проще и более поддерживаемым.
  1. Наследуйтесь от std::exception публично:
class bad_function_call: public std::exception
  1. Используйте std::unique_ptr вместо std::shared_ptr --- каждый экземпляр должен хранить свою копию функтора и семантика std::uniqute_ptr здесь подходит лучше и он более эффективен.


comment:18 Changed 6 years ago by cpptester

Tested revision 787 by kuroptev.ilya.

All tests passed. Good job!

comment:19 Changed 6 years ago by Илья Куроптев

Type: ожидаются исправленияожидается проверка

comment:20 Changed 6 years ago by Vladimir Rutsky

Resolution: задача сдана
Status: newclosed

Решение зачтено.

Note: See TracTickets for help on using tickets.