线程 0 在使用 C 库和 Python 时崩溃

问题描述

我有一个用 C 编写的用于数学/天体物理计算的库和一个使用 C-Python API 的包装器,以允许用户通过 Python 访问代码。一位用户报告了以下错误消息,但我从未见过它,也不知道它的含义:

Thread 0 Crashed:
0   libsystem_kernel.dylib         0x00007fff796a82c6 __pthread_kill + 10
1   libsystem_c.dylib             0x00007fff796126a6 abort + 127
2   libsystem_malloc.dylib         0x00007fff79721077 malloc_vreport + 545
3   libsystem_malloc.dylib         0x00007fff79720e38 malloc_report + 151
4   libRSSringoccs.so             0x0000001c1e41f9bc RSSringoccs_Tau_Set_WType + 60
5   diffrec.cpython-36m-darwin.so 0x0000001c1e3f6f91 Diffrec_init + 1361

使用 gcc 或 clang(来自 bash 脚本)在 Linux 和 Mac 上使用以下选项成功构建库:

CompilerArgs1="-std=c89 -ansi -pedantic -pedantic-errors -Wall -Wextra"
CompilerArgs2="-Wpedantic -Wmisleading-indentation -Wmissing-field-initializers"
CompilerArgs3="-Wmissing-prototypes -Wold-style-deFinition -Winit-self"
CompilerArgs4="-Wmissing-declarations -Wnull-dereference -Wwrite-strings"
CompilerArgs5="-Wstrict-prototypes -I../../ -I./ -DNDEBUG -g -fPIC -O3 -c"
CompilerArgs="$CompilerArgs1 $CompilerArgs2 $CompilerArgs3"
CompilerArgs="$CompilerArgs $CompilerArgs4 $CompilerArgs5"

文件 RSSringoccs_Tau_Set_WType.c 似乎没有什么奇怪的:

void RSSringoccs_Tau_Set_WType(const char *wtype,RSSringoccs_TAUObj *tau)
{
    if (tau == NULL)
        return;

    if (tau->error_occurred)
        return;

    if (wtype == NULL)
    {
        tau->error_occurred = RSSringoccs_True;
        tau->error_message = RSSringoccs_strdup(
            "\rError Encountered: RSS_ringoccs\n"
            "\r\tRSSringoccs_Tau_Set_WType\n\n"
            "\rInput string is NULL. Returning.\n"
        );
        return;
    }

    if (tau->wtype != NULL)
        free(tau->wtype);

    tau->wtype = RSSringoccs_strdup(wtype);
    RSSringoccs_Remove_Spaces(tau->wtype);
    RSSringoccs_Make_Lower(tau->wtype);

    if (strcmp(tau->wtype,"rect") == 0)
    {
        tau->normeq = RectnormEQ;
        tau->window_func = RSSringoccs_Double_Rect_Window;
    }
    else if (strcmp(tau->wtype,"coss") == 0)
    {
        tau->normeq = CossnormEQ;
        tau->window_func = RSSringoccs_Double_Coss_Window;
    }
    else if (strcmp(tau->wtype,"kb20") == 0)
    {
        tau->normeq = KB20normEQ;
        tau->window_func = RSSringoccs_Double_Kaiser_Bessel_2_0;
    }
    else if (strcmp(tau->wtype,"kb25") == 0)
    {
        tau->normeq = KB25normEQ;
        tau->window_func = RSSringoccs_Double_Kaiser_Bessel_2_5;
    }
    else if (strcmp(tau->wtype,"kb35") == 0)
    {
        tau->normeq = KB35normEQ;
        tau->window_func = RSSringoccs_Double_Kaiser_Bessel_3_5;
    }
    else if (strcmp(tau->wtype,"kbmd20") == 0)
    {
        tau->normeq = KBMD20normEQ;
        tau->window_func = RSSringoccs_Double_Modified_Kaiser_Bessel_2_0;
    }
    else if (strcmp(tau->wtype,"kbmd25") == 0)
    {
        tau->normeq = KBMD25normEQ;
        tau->window_func = RSSringoccs_Double_Modified_Kaiser_Bessel_2_5;
    }
    else if (strcmp(tau->wtype,"kbmd35") == 0)
    {
        tau->normeq = KBMD35normEQ;
        tau->window_func = RSSringoccs_Double_Modified_Kaiser_Bessel_3_5;
    }
    else
    {
        tau->error_occurred = RSSringoccs_True;
        tau->error_message = RSSringoccs_strdup(
            "\n\rError Encountered: RSS_ringoccs\n"
            "\r\tRSSringoccs_Tau_Set_WType\n\n"
            "\r\tIllegal string for wtype. Allowed strings are:\n"
            "\r\t\trect:    Rectangular Window\n"
            "\r\t\tcoss:    Squared Cosine Window\n"
            "\r\t\tkb20:    Kaiser-Bessel with alpha=2.0 pi\n"
            "\r\t\tkb25:    Kaiser-Bessel with alpha=2.5 pi\n"
            "\r\t\tkb35:    Kaiser-Bessel with alpha=3.5 pi\n"
            "\r\t\tkbmd20:  Modified Kaiser-Bessel with alpha=2.0 pi\n"
            "\r\t\tkbmd25:  Modified Kaiser-Bessel with alpha=2.5 pi\n"
            "\r\t\tkbmd35:  Modified Kaiser-Bessel with alpha=3.5 pi\n"
        );
        tau->normeq = -1.0;
    }
}

tau->wtype 在创建 tau 时设置为 NULL。这是设置 tau->wtypeRSSringoccs_strdup函数是 POSIX strdup 函数的 C89 兼容版本,并使用 malloc。所以我认为错误不是通过 free 的非 malloc 指针产生的。

tau->window_func一个函数指针 double (*f)(double,double)tau->normeq一个双倍。

我无法在 Debian 或 MacOS Catalina 上重现此错误,因此我不确定该错误是否与代码有关。非常感谢任何帮助!

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)