Opened 4 years ago

Closed 4 years ago

#275 closed ожидаются исправления (задача сдана)

HA 4 Петряков Иван

Reported by: Иван Owned by: rutsky,grabovoy.philipp
Priority: проверка Milestone: ha4-deadline
Component: HA#4 function Version:
Keywords: Cc:

Description

Здравствуйте!

Проверьте, пожалуйста мою реализацию. Smoke test компилируется, но во время выполнения появляется SIGSEGV. Если мне правильно подсказывает дебаггер, у меня ошибка в конструкторе копирования, но какая именно я понять не могу.

Change History (25)

comment:1 Changed 4 years ago by cpptester

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

Tested revision 613 by petryakov.ivan.

Smoke tests

test

stage

result

info

log

run_function_smoke_test.cpp

WARNING

run_function_smoke_test-gcc62.log

FAILURE

exit code 139

run_function_smoke_test-run.log

Common header used in some tests: common.h

comment:2 Changed 4 years ago by cpptester

Tested revision 642 by petryakov.ivan.

Smoke tests

test

stage

result

info

log

run_function_smoke_test.cpp

SUCCESS
FAILURE

exit code 139

run_function_smoke_test-run.log

Common header used in some tests: common.h

comment:3 Changed 4 years ago by cpptester

Tested revision 642 by petryakov.ivan.

Smoke tests

test

stage

result

info

log

run_function_smoke_test.cpp

SUCCESS
SUCCESS
FAILURE

exit code 1

run_function_smoke_test-valgrind.log

SUCCESS
FAILURE

exit code 1

run_function_smoke_test-asan.log

SUCCESS
FAILURE

exit code 1

run_function_smoke_test-san.log

Common header used in some tests: common.h

comment:4 Changed 4 years ago by cpptester

Tested revision 642 by petryakov.ivan.

Smoke tests

test

stage

result

info

log

run_function_smoke_test.cpp

SUCCESS
SUCCESS
FAILURE

exit code 1

run_function_smoke_test-valgrind.log

SUCCESS
FAILURE

exit code 1

run_function_smoke_test-asan.log

SUCCESS
FAILURE

exit code 1

run_function_smoke_test-san.log

Common header used in some tests: common.h

comment:5 Changed 4 years ago by cpptester

Tested revision 642 by petryakov.ivan.

Smoke tests

test

stage

result

info

log

run_function_smoke_test.cpp

SUCCESS
SUCCESS
FAILURE

exit code 1

run_function_smoke_test-valgrind.log

SUCCESS
FAILURE

exit code 1

run_function_smoke_test-asan.log

SUCCESS
FAILURE

exit code 1

run_function_smoke_test-san.log

Common header used in some tests: common.h

comment:6 Changed 4 years ago by cpptester

Tested revision 715 by petryakov.ivan.

Smoke tests

test

stage

result

info

log

run_function_smoke_test.cpp

SUCCESS
SUCCESS
FAILURE

exit code 1

run_function_smoke_test-valgrind.log

SUCCESS
FAILURE

exit code 1

run_function_smoke_test-asan.log

SUCCESS
FAILURE

exit code 1

run_function_smoke_test-san.log

Common header used in some tests: common.h

comment:7 Changed 4 years ago by cpptester

Tested revision 716 by petryakov.ivan.

Main tests

test

stage

result

info

log

ncomp_iostream_include.cpp

FAILURE

run_assign.cpp

FAILURE

run_assign-gcc62.log

run_free_function.cpp

SUCCESS
FAILURE

exit code 139

run_free_function-run.log

Common header used in some tests: common.h

comment:8 Changed 4 years ago by cpptester

Tested revision 718 by petryakov.ivan.

Main tests

test

stage

result

info

log

run_free_function.cpp

SUCCESS
FAILURE

exit code 139

run_free_function-run.log

Common header used in some tests: common.h

comment:9 Changed 4 years ago by cpptester

Tested revision 720 by petryakov.ivan.

Smoke tests

test

stage

result

info

log

run_function_smoke_test.cpp

FAILURE

run_function_smoke_test-gcc62.log

Common header used in some tests: common.h

comment:10 Changed 4 years ago by cpptester

Tested revision 721 by petryakov.ivan.

Smoke tests

test

stage

result

info

log

run_function_smoke_test.cpp

FAILURE

run_function_smoke_test-gcc62.log

Common header used in some tests: common.h

comment:11 Changed 4 years ago by cpptester

Tested revision 722 by petryakov.ivan.

All tests passed. Good job!

comment:12 Changed 4 years ago by Иван

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

comment:13 Changed 4 years ago by Филипп

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

Привет!

Есть проблемы:

  1. для function позволено хранить в дополнительно выделенной памяти функторы, но не функции. Текущая реализация заполняет ptr_ (выделяя объект в куче) даже при конструировании от указателя на функцию и использует _raw_link в конструкторах по остаточному принципу (никогда?). Это необходимо исправить.
  1. function::operator=(function<ret(ar...)> const &y) сейчас приводит к вложенности function в function, из-за этого: ptr_ = new type_erasure_base<function<ret(ar...)>>(y);

comment:14 Changed 4 years ago by cpptester

Tested revision 828 by petryakov.ivan.

Smoke tests

test

stage

result

info

log

run_function_smoke_test.cpp

SUCCESS
FAILURE

exit code 139

run_function_smoke_test-run.log

Common header used in some tests: common.h

comment:15 Changed 4 years ago by Иван

Здравствуйте! Я избавился от вложенности функций и выделяю память теперь только для функторов.
Уже целый день бьюсь над проблемой, но не получается избавиться от bad_alloc. Он происходит (на мой взгляд) из-за неправильного преобразования типов, хотя я везде явно привожу к нужному типу. Посмотрите, пожалуйста, что у меня не так?

comment:16 Changed 4 years ago by Vladimir Rutsky

Ваше решение падает на следующем тесте:

static std::string identity_str(const std::string& s) { return s; }
...
n::function<std::string (const char*)> id2(&identity_str);
assert(id2("foo") == "foo");

из-за того, что при конструировании function от свободной функции с произвольной сигнатурой вы приводите указатель на функцию к другому, потенциально не совместимому типу:

            template <class ret, class... ar>
            function(ret(*y)(ar...))
            {
   //             try {
   //                 ptr_ = new type_erasure_base<ret(*)(ar...)>(y);
     //          }
      //          catch (...)
        //        {

                    _raw_link = (ret_val(*)(Args...)) y;
          //      }
            }

и в этом тесте получается, что вы передаёте char * в аргумент типа std::string &, что приводит к падению.

Last edited 4 years ago by Vladimir Rutsky (previous) (diff)

comment:17 Changed 4 years ago by cpptester

Tested revision 847 by petryakov.ivan.

Smoke tests

test

stage

result

info

log

run_function_smoke_test.cpp

SUCCESS
SUCCESS
SUCCESS

run_function_smoke_test-valgrind.log

SUCCESS
SUCCESS
SUCCESS
WARNING

run_function_smoke_test-san.log

Common header used in some tests: common.h

comment:18 Changed 4 years ago by cpptester

Tested revision 848 by petryakov.ivan.

Smoke tests

test

stage

result

info

log

run_function_smoke_test.cpp

SUCCESS
SUCCESS
SUCCESS

run_function_smoke_test-valgrind.log

SUCCESS
SUCCESS
SUCCESS
WARNING

run_function_smoke_test-san.log

Common header used in some tests: common.h

comment:19 Changed 4 years ago by cpptester

Tested revision 849 by petryakov.ivan.

Smoke tests

test

stage

result

info

log

run_function_smoke_test.cpp

SUCCESS
SUCCESS
SUCCESS

run_function_smoke_test-valgrind.log

SUCCESS
SUCCESS
SUCCESS
WARNING

run_function_smoke_test-san.log

Common header used in some tests: common.h

comment:20 Changed 4 years ago by cpptester

Tested revision 850 by petryakov.ivan.

Smoke tests

test

stage

result

info

log

run_function_smoke_test.cpp

FAILURE

run_function_smoke_test-gcc62.log

Common header used in some tests: common.h

comment:21 Changed 4 years ago by cpptester

Tested revision 851 by petryakov.ivan.

Main tests

test

stage

result

info

log

run_free_function.cpp

SUCCESS
FAILURE

exit code 139

run_free_function-run.log

Common header used in some tests: common.h

comment:22 Changed 4 years ago by cpptester

Tested revision 852 by petryakov.ivan.

Smoke tests

test

stage

result

info

log

run_function_smoke_test.cpp

FAILURE

run_function_smoke_test-gcc62.log

Common header used in some tests: common.h

comment:23 Changed 4 years ago by cpptester

Tested revision 853 by petryakov.ivan.

All tests passed. Good job!

comment:24 Changed 4 years ago by Филипп

Можно проверять работу?

comment:25 Changed 4 years ago by Филипп

Resolution: задача сдана
Status: newclosed
Note: See TracTickets for help on using tickets.