code: def _encode_path(path_items):
      
      points_per_type = PATH_POINTS_PER_TYPE
      path_items = list(path_items)
      length = 0
      for path_type, coordinates in path_items:
          num_points = points_per_type[path_type]
          length += 1 + num_points  # 1 header + N points
          if len(coordinates) != 2 * num_points:
              raise ValueError('Expected %d coordinates, got %d.' % (
                  2 * num_points, len(coordinates)))
  
      data = ffi.new('cairo_path_data_t[]', length)
      position = 0
      for path_type, coordinates in path_items:
          header = data[position].header
          header.type = path_type
          header.length = 1 + len(coordinates) // 2
          position += 1
          for i in range(0, len(coordinates), 2):
              point = data[position].point
              point.x = coordinates[i]
              point.y = coordinates[i + 1]
              position += 1
      path = ffi.new(
          'cairo_path_t *',
          {'status': constants.STATUS_SUCCESS, 'data': data, 'num_data': length})
      return path, data
docs: Take an iterable of ``(path_operation, coordinates)`` tuples
      in the same format as from :meth:`Context.copy_path`
      and return a ``(path, data)`` tuple of cdata object.
  
      The first cdata object is a ``cairo_path_t *`` pointer
      that can be used as long as both objects live.