Skip to content

datetime_strptime is 'NoneType' when restart cpython #117914

Description

@marin-man

Bug report

Bug description:

When executing the following code, it will appear TypeError: 'NoneType' object is not callable

#include "Python.h"
#include <iostream>

void py_test() {
    Py_Initialize();
    auto pName = PyUnicode_DecodeFSDefault("datetime");
    auto pModule = PyImport_Import(pName);
    auto datetime = PyObject_GetAttrString(pModule, "datetime");
    auto strptime = PyObject_GetAttrString(datetime, "strptime");
    auto args = PyTuple_New(2);
    PyTuple_SetItem(args, 0, PyUnicode_FromString("2000-01"));
    PyTuple_SetItem(args, 1, PyUnicode_FromString("%Y-%m"));
    auto res = PyObject_CallObject(strptime, args);
    PyObject_Print(res, stdout, 0);
    Py_Finalize();
}

int main() {
    py_test();
    std::cout << "========" << std::endl;
    py_test();
    return 0;
}

CPython versions tested on:

3.11

Operating systems tested on:

macOS

Linked PRs

Activity

  1. added a commit that references this issue on Apr 16, 2024
  2. serhiy-storchaka commented on Apr 16, 2024

    @serhiy-storchaka
    Member

    Is it Python 3.11 only issue? Is it reproduced in 3.12 or in the main branch?

  3. marin-man commented on Apr 16, 2024

    @marin-man
    Author

    Is it Python 3.11 only issue? Is it reproduced in 3.12 or in the main branch?

    Python 3.12 and main branch seems to be worse, it crashes on import after restart.

    #include "Python.h"
    #include <iostream>
    
    void py_test() {
      Py_Initialize();
      auto pName = PyUnicode_DecodeFSDefault("datetime");
      auto pModule = PyImport_Import(pName);
      Py_Finalize();
    }
    
    int main() {
      py_test();
      std::cout << "========" << std::endl;
      py_test();
      return 0;
    }
    ========
    a.out(39618,0x7ff8589827c0) malloc: *** error for object 0x10bffedc0: pointer being freed was not allocated
    a.out(39618,0x7ff8589827c0) malloc: *** set a breakpoint in malloc_error_break to debug
    [1]    39618 abort      ./a.out
  4. serhiy-storchaka commented on Apr 16, 2024

    @serhiy-storchaka
    Member

    If the bug is not 3.11 specific, the PR should be created for the main branch.

  5. ericsnowcurrently commented on Jun 12, 2024

    @ericsnowcurrently
    Member

    This appears to be a duplicate of gh-71587. If I'm mistaken, please re-open.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    type-bugAn unexpected behavior, bug, or error

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions