Skip to content

datetime_strptime is 'NoneType' when restart cpython #117914

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
marin-man opened this issue Apr 16, 2024 · 4 comments
Closed

datetime_strptime is 'NoneType' when restart cpython #117914

marin-man opened this issue Apr 16, 2024 · 4 comments
Labels
type-bug An unexpected behavior, bug, or error

Comments

@marin-man
Copy link

marin-man commented Apr 16, 2024

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

@marin-man marin-man added the type-bug An unexpected behavior, bug, or error label Apr 16, 2024
marin-man added a commit to marin-man/cpython that referenced this issue Apr 16, 2024
@serhiy-storchaka
Copy link
Member

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

@marin-man
Copy link
Author

marin-man commented Apr 16, 2024

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

@serhiy-storchaka
Copy link
Member

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

@ericsnowcurrently
Copy link
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
Labels
type-bug An unexpected behavior, bug, or error
Projects
None yet
Development

No branches or pull requests

3 participants