Skip to content

Commit e47e679

Browse files
Copilotluoliwoshang
andcommitted
Remove unexpected empty lines and add zlib-static demo for libstatic testing
Co-authored-by: luoliwoshang <51194195+luoliwoshang@users.noreply.github.com>
1 parent bc80a8d commit e47e679

6 files changed

Lines changed: 139 additions & 2 deletions

File tree

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
{
2+
"name": "zlib-static",
3+
"cflags": "$(pkg-config --cflags zlib)",
4+
"libs": "$(pkg-config --libs zlib)",
5+
"include": [
6+
"zconf.h",
7+
"zlib.h"
8+
],
9+
"trimPrefixes": ["Z_"],
10+
"cplusplus": false,
11+
"mix":true,
12+
"deps":["c/os"],
13+
"symMap":{
14+
"compress":"Compress",
15+
"compress2":"Compress2",
16+
"uncompress":"Uncompress",
17+
"uncompress2":"Uncompress2",
18+
"compressBound":"CompressBound"
19+
},
20+
"libstatic": true
21+
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
package main
2+
3+
import (
4+
"fmt"
5+
"unsafe"
6+
"zlib-static"
7+
)
8+
9+
func main() {
10+
ul := zlib_static.ULong(0)
11+
data := "Hello world"
12+
res := ul.Crc32Z(
13+
(*zlib_static.Bytef)(unsafe.Pointer(unsafe.StringData(data))),
14+
zlib_static.ZSizeT(uintptr(len(data))),
15+
)
16+
fmt.Printf("%08x\n", res)
17+
}
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
package main
2+
3+
import (
4+
"unsafe"
5+
"zlib-static"
6+
7+
"github.com/goplus/lib/c"
8+
)
9+
10+
func main() {
11+
txt := []byte("zlib is a software library used for data compression. It was created by Jean-loup Gailly and Mark Adler and first released in 1995. zlib is designed to be a free, legally unencumbered—that is, not covered by any patents—alternative to the proprietary DEFLATE compression algorithm, which is often used in software applications for data compression.The library provides functions to compress and decompress data using the DEFLATE algorithm, which is a combination of the LZ77 algorithm and Huffman coding. zlib is notable for its versatility; it can be used in a wide range of applications, from web servers and web clients compressing HTTP data, to the compression of data for storage or transmission in various file formats, such as PNG, ZIP, and GZIP.")
12+
txtLen := zlib_static.ULong(len(txt))
13+
14+
for level := 0; level <= 9; level++ {
15+
cmpSize := zlib_static.ULongf(zlib_static.CompressBound(txtLen))
16+
cmpData := make([]byte, int(cmpSize))
17+
data := (*zlib_static.Bytef)(unsafe.Pointer(unsafe.SliceData(cmpData)))
18+
source := (*zlib_static.Bytef)(unsafe.Pointer(unsafe.SliceData(txt)))
19+
res := zlib_static.Compress2(data, &cmpSize, source, txtLen, c.Int(level))
20+
if res != zlib_static.OK {
21+
c.Printf(c.Str("\nCompression failed at level %d: %d\n"), level, res)
22+
continue
23+
}
24+
25+
c.Printf(c.Str("Compression level %d: Text length = %d, Compressed size = %d\n"), level, txtLen, cmpSize)
26+
27+
ucmpSize := zlib_static.ULongf(txtLen)
28+
ucmp := make([]byte, int(ucmpSize))
29+
ucmpData := (*zlib_static.Bytef)(unsafe.Pointer(unsafe.SliceData(ucmp)))
30+
cmpSource := (*zlib_static.Bytef)(unsafe.Pointer(unsafe.SliceData(cmpData)))
31+
32+
unRes := zlib_static.Uncompress(ucmpData, &ucmpSize, cmpSource, zlib_static.ULong(cmpSize))
33+
if unRes != zlib_static.OK {
34+
c.Printf(c.Str("\nDecompression failed at level %d: %d\n"), level, unRes)
35+
continue
36+
}
37+
}
38+
}
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
package main
2+
3+
import (
4+
"unsafe"
5+
"zlib-static"
6+
7+
"github.com/goplus/lib/c"
8+
)
9+
10+
func main() {
11+
txt := []byte("zlib is a software library used for data compression. It was created by Jean-loup Gailly and Mark Adler and first released in 1995. zlib is designed to be a free, legally unencumbered—that is, not covered by any patents—alternative to the proprietary DEFLATE compression algorithm, which is often used in software applications for data compression.The library provides functions to compress and decompress data using the DEFLATE algorithm, which is a combination of the LZ77 algorithm and Huffman coding. zlib is notable for its versatility; it can be used in a wide range of applications, from web servers and web clients compressing HTTP data, to the compression of data for storage or transmission in various file formats, such as PNG, ZIP, and GZIP.")
12+
txtLen := zlib_static.ULong(len(txt))
13+
14+
cmpSize := zlib_static.ULongf(zlib_static.CompressBound(txtLen))
15+
cmpData := make([]byte, int(cmpSize))
16+
data := (*zlib_static.Bytef)(unsafe.Pointer(unsafe.SliceData(cmpData)))
17+
txtData := (*zlib_static.Bytef)(unsafe.Pointer(unsafe.SliceData(txt)))
18+
19+
res := zlib_static.Compress(data, &cmpSize, txtData, txtLen)
20+
if res != zlib_static.OK {
21+
c.Printf(c.Str("\nCompression failed: %d\n"), res)
22+
return
23+
}
24+
25+
c.Printf(c.Str("Text length = %d, Compressed size = %d\n"), txtLen, cmpSize)
26+
27+
ucmpSize := zlib_static.ULongf(txtLen)
28+
ucmp := make([]byte, int(ucmpSize))
29+
ucmpPtr := (*zlib_static.Bytef)(unsafe.Pointer(unsafe.SliceData(ucmp)))
30+
31+
unRes := zlib_static.Uncompress(ucmpPtr, &ucmpSize, data, zlib_static.ULong(cmpSize))
32+
c.Printf(c.Str("Decompression result = %d, Decompressed size %d\n"), unRes, ucmpSize)
33+
34+
if unRes != zlib_static.OK {
35+
c.Printf(c.Str("\nDecompression failed: %d\n"), unRes)
36+
return
37+
}
38+
39+
c.Printf(c.Str("Decompressed data: \n"))
40+
for i := 0; i < int(ucmpSize); i++ {
41+
c.Printf(c.Str("%c"), ucmp[i])
42+
}
43+
}

_llcppgtest/zlib-static/llcppg.cfg

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
{
2+
"name": "zlib-static",
3+
"cflags": "$(pkg-config --cflags zlib)",
4+
"libs": "$(pkg-config --libs zlib)",
5+
"include": [
6+
"zconf.h",
7+
"zlib.h"
8+
],
9+
"trimPrefixes": ["Z_"],
10+
"cplusplus": false,
11+
"deps":["c/os"],
12+
"symMap":{
13+
"compress":"Compress",
14+
"compress2":"Compress2",
15+
"uncompress":"Uncompress",
16+
"uncompress2":"Uncompress2",
17+
"compressBound":"CompressBound"
18+
},
19+
"libstatic": true
20+
}

_xtool/llcppsymg/internal/symg/lib_test.go

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -188,5 +188,3 @@ func TestGenDylibPaths(t *testing.T) {
188188

189189
}
190190
}
191-
192-

0 commit comments

Comments
 (0)