修复了大量存在的问题,增加了假鸭子类型等等机制
This commit is contained in:
@@ -122,8 +122,8 @@ class zdeflate_stream:
|
||||
|
||||
|
||||
def write_dynamic_block(self, data: UINT8PTR, length: t.CSizeT, final: t.CInt):
|
||||
lit_freqs: list[t.CInt, 288]
|
||||
dist_freqs: list[t.CInt, 32]
|
||||
lit_freqs: t.CArray[t.CInt, 288]
|
||||
dist_freqs: t.CArray[t.CInt, 32]
|
||||
zdeflate_count_freqs(lit_freqs, dist_freqs, self, data, length)
|
||||
hlit: t.CInt = 286
|
||||
while hlit > 257 and lit_freqs[hlit - 1] == 0: hlit -= 1
|
||||
@@ -133,11 +133,11 @@ class zdeflate_stream:
|
||||
dist_tree = zhuff.zhuff_tree()
|
||||
lit_tree.build_codes(lit_freqs, hlit, zdef.ZDEFLATE_MAX_BITS)
|
||||
dist_tree.build_codes(dist_freqs, hdist, zdef.ZDEFLATE_MAX_BITS)
|
||||
all_lengths: list[t.CInt, 288 + 32]
|
||||
all_lengths: t.CArray[t.CInt, 288 + 32]
|
||||
for i in range(hlit): all_lengths[i] = lit_tree.codes[i].bits
|
||||
for i in range(hdist): all_lengths[hlit + i] = dist_tree.codes[i].bits
|
||||
total_lengths: t.CInt = hlit + hdist
|
||||
cl_freqs: list[t.CInt, 19]
|
||||
cl_freqs: t.CArray[t.CInt, 19]
|
||||
zdeflate_count_cl_freqs(all_lengths, total_lengths, cl_freqs)
|
||||
cl_tree = zhuff.zhuff_tree()
|
||||
cl_tree.build_codes(cl_freqs, 19, 7)
|
||||
@@ -373,14 +373,28 @@ def zdeflate_write_cl_encoded(all_lengths: INTPTR, total: t.CInt,
|
||||
|
||||
|
||||
def zdeflate_create(pool: mpool.MPool | t.CPtr, level: t.CInt, wbits: t.CInt, mem_level: t.CInt, strategy: t.CInt) -> zdeflate_stream | t.CPtr:
|
||||
s: zdeflate_stream | t.CPtr = zdef.zdef_alloc(pool, zdeflate_stream.__sizeof__())
|
||||
stdio.printf("[DEBUG] zdeflate_create: pool=%p, level=%d, wbits=%d\n", pool, level, wbits)
|
||||
n: t.CSizeT = zdeflate_stream.__sizeof__()
|
||||
stdio.printf("[DEBUG] zdeflate_create: sizeof(zdeflate_stream)=%zu\n", n)
|
||||
s: zdeflate_stream | t.CPtr = zdef.zdef_alloc(pool, n)
|
||||
stdio.printf("[DEBUG] zdeflate_create: allocated stream=%p\n", s)
|
||||
if not s: return None
|
||||
stdio.printf("[DEBUG] zdeflate_create: memset(s, 0)\n")
|
||||
memset(s, 0, zdeflate_stream.__sizeof__())
|
||||
stdio.printf("[DEBUG] zdeflate_create: s.pool = pool\n")
|
||||
s.pool = pool
|
||||
stdio.printf("[DEBUG] zdeflate_create: creating zbit_writer\n")
|
||||
s.writer = zdef.zbit_writer(pool)
|
||||
stdio.printf("[DEBUG] zdeflate_create: zbit_writer created, writer.buf=%p\n", s.writer.buf)
|
||||
stdio.printf("[DEBUG] zdeflate_create: allocating window\n")
|
||||
s.window = BYTEPTR(zdef.zdef_alloc(pool, zdef.ZDEFLATE_WINDOW_SIZE))
|
||||
stdio.printf("[DEBUG] zdeflate_create: window=%p\n", s.window)
|
||||
stdio.printf("[DEBUG] zdeflate_create: allocating hash_head\n")
|
||||
s.hash_head = INTPTR(zdef.zdef_alloc(pool, zdef.ZDEFLATE_HASH_SIZE * int.__sizeof__()))
|
||||
stdio.printf("[DEBUG] zdeflate_create: hash_head=%p\n", s.hash_head)
|
||||
stdio.printf("[DEBUG] zdeflate_create: allocating hash_prev\n")
|
||||
s.hash_prev = INTPTR(zdef.zdef_alloc(pool, zdef.ZDEFLATE_WINDOW_SIZE * int.__sizeof__()))
|
||||
stdio.printf("[DEBUG] zdeflate_create: hash_prev=%p\n", s.hash_prev)
|
||||
if not s.window or not s.hash_head or not s.hash_prev:
|
||||
s.destroy()
|
||||
return None
|
||||
@@ -400,7 +414,9 @@ def zdeflate_create(pool: mpool.MPool | t.CPtr, level: t.CInt, wbits: t.CInt, me
|
||||
|
||||
def zdeflate_one_shot(pool: mpool.MPool | t.CPtr, data: UINT8PTR, length: t.CSizeT,
|
||||
level: t.CInt, wbits: t.CInt, out_len: t.CSizeT | t.CPtr) -> t.CUInt8T | t.CPtr:
|
||||
stdio.printf("[DEBUG] zdeflate_one_shot: pool=%p, data=%p, length=%zu, level=%d, wbits=%d\n", pool, data, length, level, wbits)
|
||||
s: zdeflate_stream | t.CPtr = zdeflate_create(pool, level, wbits, 8, 0)
|
||||
stdio.printf("[DEBUG] zdeflate_one_shot: stream created=%p\n", s)
|
||||
if not s: return None
|
||||
|
||||
memset(s.hash_head, -1, zdef.ZDEFLATE_HASH_SIZE * int.__sizeof__())
|
||||
|
||||
Reference in New Issue
Block a user