code: def test_parse_trim_buffers(c_parser_only, encoding):
      # This test is part of a bugfix for gh-13703. It attempts to
      # to stress the system memory allocator, to cause it to move the
      # stream buffer and either let the OS reclaim the region, or let
      # other memory requests of parser otherwise modify the contents
      # of memory space, where it was formally located.
      # This test is designed to cause a `segfault` with unpatched
      # `tokenizer.c`. Sometimes the test fails on `segfault`, other
      # times it fails due to memory corruption, which causes the
      # loaded DataFrame to differ from the expected one.
  
      # Also force 'utf-8' encoding, so that `_string_convert` would take
      # a different execution branch.
  
      parser = c_parser_only
  
      # Generate a large mixed-type CSV file on-the-fly (one record is
      # approx 1.5KiB).
      record_ = (
          """9999-9,99:99,,,,ZZ,ZZ,,,ZZZ-ZZZZ,.Z-ZZZZ,-9.99,,,9.99,Z"""
          """ZZZZ,,-99,9,ZZZ-ZZZZ,ZZ-ZZZZ,,9.99,ZZZ-ZZZZZ,ZZZ-ZZZZZ,"""
          """ZZZ-ZZZZ,ZZZ-ZZZZ,ZZZ-ZZZZ,ZZZ-ZZZZ,ZZZ-ZZZZ,ZZZ-ZZZZ,9"""
          """99,ZZZ-ZZZZ,,ZZ-ZZZZ,,,,,ZZZZ,ZZZ-ZZZZZ,ZZZ-ZZZZ,,,9,9,"""
          """9,9,99,99,999,999,ZZZZZ,ZZZ-ZZZZZ,ZZZ-ZZZZ,9,ZZ-ZZZZ,9."""
          """99,ZZ-ZZZZ,ZZ-ZZZZ,,,,ZZZZ,,,ZZ,ZZ,,,,,,,,,,,,,9,,,999."""
          """99,999.99,,,ZZZZZ,,,Z9,,,,,,,ZZZ,ZZZ,,,,,,,,,,,ZZZZZ,ZZ"""
          """ZZZ,ZZZ-ZZZZZZ,ZZZ-ZZZZZZ,ZZ-ZZZZ,ZZ-ZZZZ,ZZ-ZZZZ,ZZ-ZZ"""
          """ZZ,,,999999,999999,ZZZ,ZZZ,,,ZZZ,ZZZ,999.99,999.99,,,,Z"""
          """ZZ-ZZZ,ZZZ-ZZZ,-9.99,-9.99,9,9,,99,,9.99,9.99,9,9,9.99,"""
          """9.99,,,,9.99,9.99,,99,,99,9.99,9.99,,,ZZZ,ZZZ,,999.99,,"""
          """999.99,ZZZ,ZZZ-ZZZZ,ZZZ-ZZZZ,,,ZZZZZ,ZZZZZ,ZZZ,ZZZ,9,9,"""
          """,,,,,ZZZ-ZZZZ,ZZZ999Z,,,999.99,,999.99,ZZZ-ZZZZ,,,9.999"""
          """,9.999,9.999,9.999,-9.999,-9.999,-9.999,-9.999,9.999,9."""
          """999,9.999,9.999,9.999,9.999,9.999,9.999,99999,ZZZ-ZZZZ,"""
          """,9.99,ZZZ,,,,,,,,ZZZ,,,,,9,,,,9,,,,,,,,,,ZZZ-ZZZZ,ZZZ-Z"""
          """ZZZ,,ZZZZZ,ZZZZZ,ZZZZZ,ZZZZZ,,,9.99,,ZZ-ZZZZ,ZZ-ZZZZ,ZZ"""
          """,999,,,,ZZ-ZZZZ,ZZZ,ZZZ,ZZZ-ZZZZ,ZZZ-ZZZZ,,,99.99,99.99"""
          """,,,9.99,9.99,9.99,9.99,ZZZ-ZZZZ,,,ZZZ-ZZZZZ,,,,,-9.99,-"""
          """9.99,-9.99,-9.99,,,,,,,,,ZZZ-ZZZZ,,9,9.99,9.99,99ZZ,,-9"""
          """.99,-9.99,ZZZ-ZZZZ,,,,,,,ZZZ-ZZZZ,9.99,9.99,9999,,,,,,,"""
          """,,,-9.9,Z/Z-ZZZZ,999.99,9.99,,999.99,ZZ-ZZZZ,ZZ-ZZZZ,9."""
          """99,9.99,9.99,9.99,9.99,9.99,,ZZZ-ZZZZZ,ZZZ-ZZZZZ,ZZZ-ZZ"""
          """ZZZ,ZZZ-ZZZZZ,ZZZ-ZZZZZ,ZZZ,ZZZ,ZZZ,ZZZ,9.99,,,-9.99,ZZ"""
          """-ZZZZ,-999.99,,-9999,,999.99,,,,999.99,99.99,,,ZZ-ZZZZZ"""
          """ZZZ,ZZ-ZZZZ-ZZZZZZZ,,,,ZZ-ZZ-ZZZZZZZZ,ZZZZZZZZ,ZZZ-ZZZZ"""
          """,9999,999.99,ZZZ-ZZZZ,-9.99,-9.99,ZZZ-ZZZZ,99:99:99,,99"""
          """,99,,9.99,,-99.99,,,,,,9.99,ZZZ-ZZZZ,-9.99,-9.99,9.99,9"""
          """.99,,ZZZ,,,,,,,ZZZ,ZZZ,,,,,"""
      )
  
      # Set the number of lines so that a call to `parser_trim_buffers`
      # is triggered: after a couple of full chunks are consumed a
      # relatively small 'residual' chunk would cause reallocation
      # within the parser.
      chunksize, n_lines = 128, 2 * 128 + 15
      csv_data = "\n".join([record_] * n_lines) + "\n"
  
      # We will use StringIO to load the CSV from this text buffer.
      # pd.read_csv() will iterate over the file in chunks and will
      # finally read a residual chunk of really small size.
  
      # Generate the expected output: manually create the dataframe
      # by splitting by comma and repeating the `n_lines` times.
      row = tuple(
          val_ if val_ else np.nan for val_ in record_.split(",")
      )
      expected = DataFrame(
          [row for _ in range(n_lines)],
          dtype=object,
          columns=None,
          index=None,
      )
  
      # Iterate over the CSV file in chunks of `chunksize` lines
      with parser.read_csv(
          StringIO(csv_data),
          header=None,
          dtype=object,
          chunksize=chunksize,
          encoding=encoding,
      ) as chunks_:
          result = concat(chunks_, axis=0, ignore_index=True)
  
      # Check for data corruption if there was no segfault
      tm.assert_frame_equal(result, expected)
  
imports: from decimal import Decimal
  from io import BytesIO, StringIO, TextIOWrapper
  import mmap
  import os
  import tarfile
  import numpy
  import pytest
  from pandas.compat.numpy import np_version_gte1p24
  from pandas.errors import ParserError, ParserWarning
  import pandas.util._test_decorators
  from pandas import DataFrame, concat
  import pandas._testing
label_desc: Use image node_id 12 for calling a global function with example usage: test_parse_trim_buffers(c_parser_only, encoding) without return types