Skip to content

Instantly share code, notes, and snippets.

@umyuu
Last active August 10, 2018 02:07
Show Gist options
  • Save umyuu/d399764220d3f3da16437abd1a2420fa to your computer and use it in GitHub Desktop.
Save umyuu/d399764220d3f3da16437abd1a2420fa to your computer and use it in GitHub Desktop.

Pythonのjson#loadを呼び出し時のスタックトレース

◇確認方法 PyCharmでブレイクポイントを設置。 ◇ソースコード

with open(str(file_name), encoding='utf-8') as f:
    lines = json.load(f)

◇以下トレース

cpython ディレクトリ直下

  1. Lib/json/init.py#load
  2. Lib/json/init.py#loads
  3. cpython/Lib/json/decoder.py#decode
  4. cpython/Lib/json/decoder.py#raw_decode
  5. `self.scan_once(s, idx)

cpython/Lib/json/scanner.py

以下の行よりc言語なので、目視トレース。

  1. _json Modules/_json.c

  2. _json.c#scanner_call

  3. _json.c#scanstring_unicode

  4. PyUnicode_GET_LENGTH

◇参考情報

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