From 6a83de355adec0e83105835708e25f33ae018939 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Fri, 27 Jun 2025 02:49:43 +0000 Subject: [PATCH 01/10] Initial plan From 0e95f6a482bd8d580dbf556a25e441dbb6c010df Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Fri, 27 Jun 2025 02:53:26 +0000 Subject: [PATCH 02/10] Initial plan for adding libstatic support Co-authored-by: luoliwoshang <51194195+luoliwoshang@users.noreply.github.com> --- parser/testdata/func/hfile/forwarddecl.h.i | 10 ++++++++++ 1 file changed, 10 insertions(+) create mode 100644 parser/testdata/func/hfile/forwarddecl.h.i diff --git a/parser/testdata/func/hfile/forwarddecl.h.i b/parser/testdata/func/hfile/forwarddecl.h.i new file mode 100644 index 000000000..c33952221 --- /dev/null +++ b/parser/testdata/func/hfile/forwarddecl.h.i @@ -0,0 +1,10 @@ +# 1 "/home/runner/work/llcppg/llcppg/parser/testdata/func/hfile/forwarddecl.h" +# 1 "" 1 +# 1 "" 3 +# 453 "" 3 +# 1 "" 1 +# 1 "" 2 +# 1 "/home/runner/work/llcppg/llcppg/parser/testdata/func/hfile/forwarddecl.h" 2 +void foo0(); +void foo1(int a); +void foo2(int a,...); From 3d094edbe90af9d8be06024be9e50b6d150ba125 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Fri, 27 Jun 2025 02:59:30 +0000 Subject: [PATCH 03/10] Implement libstatic configuration support for static library symbol reading Co-authored-by: luoliwoshang <51194195+luoliwoshang@users.noreply.github.com> --- _xtool/llcppsymg/internal/symg/lib_test.go | 84 +++++++++++++++++++++- _xtool/llcppsymg/internal/symg/symg.go | 4 +- _xtool/llcppsymg/llcppsymg.go | 7 ++ config/config.go | 1 + config/config_test.go | 19 +++++ 5 files changed, 112 insertions(+), 3 deletions(-) diff --git a/_xtool/llcppsymg/internal/symg/lib_test.go b/_xtool/llcppsymg/internal/symg/lib_test.go index fcbc08bbd..703afbbe4 100644 --- a/_xtool/llcppsymg/internal/symg/lib_test.go +++ b/_xtool/llcppsymg/internal/symg/lib_test.go @@ -165,7 +165,7 @@ func TestGenDylibPaths(t *testing.T) { } if err != nil { - t.Fatalf("expected no error, got %w", err) + t.Fatalf("expected no error, got %v", err) } if !reflect.DeepEqual(notFounds, tc.wantNotFound) { @@ -188,3 +188,85 @@ func TestGenDylibPaths(t *testing.T) { } } + +func TestLibModeConfiguration(t *testing.T) { + testCases := []struct { + name string + libName string + mode symbol.Mode + expected string // expected file extension + }{ + { + name: "Dynamic library mode", + libName: "test", + mode: symbol.ModeDynamic, + expected: getExpectedDynamicExt(), + }, + { + name: "Static library mode", + libName: "test", + mode: symbol.ModeStatic, + expected: ".a", + }, + } + + for _, tc := range testCases { + t.Run(tc.name, func(t *testing.T) { + tempDir, err := os.MkdirTemp("", "libmode_test") + if err != nil { + t.Fatal(err) + } + defer os.RemoveAll(tempDir) + + // Create the expected library file + expectedFileName := fmt.Sprintf("lib%s%s", tc.libName, tc.expected) + expectedPath := filepath.Join(tempDir, expectedFileName) + + file, err := os.Create(expectedPath) + if err != nil { + t.Fatalf("Failed to create test file %s: %v", expectedPath, err) + } + file.Close() + + // Test that the library can be found with the correct mode + foundPath, err := symbol.FindLibFile(tempDir, tc.libName, tc.mode) + if err != nil { + t.Fatal(err) + } + + if foundPath != expectedPath { + t.Errorf("Expected path %s, got %s", expectedPath, foundPath) + } + + // Test that the Libs.Files method respects the mode + libs := &symg.Libs{ + Paths: []string{tempDir}, + Names: []string{tc.libName}, + } + + foundPaths, notFound, err := libs.Files([]string{}, tc.mode) + if err != nil { + t.Fatal(err) + } + + if len(notFound) > 0 { + t.Errorf("Expected no missing libraries, but found: %v", notFound) + } + + if len(foundPaths) != 1 { + t.Errorf("Expected 1 library path, got %d", len(foundPaths)) + } + + if foundPaths[0] != expectedPath { + t.Errorf("Expected path %s, got %s", expectedPath, foundPaths[0]) + } + }) + } +} + +func getExpectedDynamicExt() string { + if runtime.GOOS == "linux" { + return ".so" + } + return ".dylib" +} diff --git a/_xtool/llcppsymg/internal/symg/symg.go b/_xtool/llcppsymg/internal/symg/symg.go index 593c8e046..fccaf3824 100644 --- a/_xtool/llcppsymg/internal/symg/symg.go +++ b/_xtool/llcppsymg/internal/symg/symg.go @@ -37,11 +37,11 @@ type Config struct { TrimPrefixes []string SymMap map[string]string IsCpp bool - libMode LibMode + LibMode LibMode } func Do(conf *Config) (symbolTable []*llcppg.SymbolInfo, err error) { - symbols, err := fetchSymbols(conf.Libs, conf.libMode) + symbols, err := fetchSymbols(conf.Libs, conf.LibMode) if err != nil { return } diff --git a/_xtool/llcppsymg/llcppsymg.go b/_xtool/llcppsymg/llcppsymg.go index aef494361..b6a7c0b53 100644 --- a/_xtool/llcppsymg/llcppsymg.go +++ b/_xtool/llcppsymg/llcppsymg.go @@ -21,6 +21,7 @@ import ( "fmt" "os" + "github.com/goplus/llcppg/_xtool/internal/symbol" "github.com/goplus/llcppg/_xtool/llcppsymg/internal/symg" llcppg "github.com/goplus/llcppg/config" args "github.com/goplus/llcppg/internal/arg" @@ -64,6 +65,11 @@ func main() { fmt.Fprintln(os.Stderr, "Failed to parse config file:", ags.CfgFile) } + libMode := symbol.ModeDynamic + if conf.LibStatic { + libMode = symbol.ModeStatic + } + symbolTable, err := symg.Do(&symg.Config{ Libs: conf.Libs, CFlags: conf.CFlags, @@ -72,6 +78,7 @@ func main() { TrimPrefixes: conf.TrimPrefixes, SymMap: conf.SymMap, IsCpp: conf.Cplusplus, + LibMode: libMode, }) check(err) diff --git a/config/config.go b/config/config.go index 44486a974..b50229457 100644 --- a/config/config.go +++ b/config/config.go @@ -33,6 +33,7 @@ type Config struct { Mix bool `json:"mix,omitempty"` SymMap map[string]string `json:"symMap,omitempty"` TypeMap map[string]string `json:"typeMap,omitempty"` + LibStatic bool `json:"libstatic,omitempty"` } func NewDefault() *Config { diff --git a/config/config_test.go b/config/config_test.go index fff625f0f..70fce1ab8 100644 --- a/config/config_test.go +++ b/config/config_test.go @@ -120,6 +120,25 @@ func TestGetConfByByte(t *testing.T) { mode: useStdin, }, + { + name: "Static library configuration", + input: `{ + "name": "mylib", + "cflags": "-I/opt/homebrew/include", + "include": ["mylib.h"], + "libs": "-L/opt/homebrew/lib -lmylib", + "libstatic": true + }`, + expect: llconfig.Config{ + Name: "mylib", + CFlags: "-I/opt/homebrew/include", + Include: []string{"mylib.h"}, + Libs: "-L/opt/homebrew/lib -lmylib", + LibStatic: true, + }, + mode: useFile, + }, + { name: "Invalid JSON", input: `{invalid json}`, From f04b76b84da37c158c03be12b9791d07459dc0c5 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Fri, 27 Jun 2025 03:07:29 +0000 Subject: [PATCH 04/10] Remove unnecessary intermediate file and update .gitignore Co-authored-by: luoliwoshang <51194195+luoliwoshang@users.noreply.github.com> --- .gitignore | 3 +++ parser/testdata/func/hfile/forwarddecl.h.i | 10 ---------- 2 files changed, 3 insertions(+), 10 deletions(-) delete mode 100644 parser/testdata/func/hfile/forwarddecl.h.i diff --git a/.gitignore b/.gitignore index 8a4df88dc..a1d671f9e 100644 --- a/.gitignore +++ b/.gitignore @@ -15,6 +15,9 @@ # Output of the go coverage tool, specifically when used with LiteIDE *.out +# Preprocessor intermediate files +*.h.i + # Dependency directories (remove the comment below to include it) # vendor/ diff --git a/parser/testdata/func/hfile/forwarddecl.h.i b/parser/testdata/func/hfile/forwarddecl.h.i deleted file mode 100644 index c33952221..000000000 --- a/parser/testdata/func/hfile/forwarddecl.h.i +++ /dev/null @@ -1,10 +0,0 @@ -# 1 "/home/runner/work/llcppg/llcppg/parser/testdata/func/hfile/forwarddecl.h" -# 1 "" 1 -# 1 "" 3 -# 453 "" 3 -# 1 "" 1 -# 1 "" 2 -# 1 "/home/runner/work/llcppg/llcppg/parser/testdata/func/hfile/forwarddecl.h" 2 -void foo0(); -void foo1(int a); -void foo2(int a,...); From 72448b28cfc8e8d33ab483a3c07302e73cca3ba6 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Fri, 27 Jun 2025 03:17:30 +0000 Subject: [PATCH 05/10] Remove unnecessary .gitignore entry for *.h.i files Co-authored-by: luoliwoshang <51194195+luoliwoshang@users.noreply.github.com> --- .gitignore | 3 --- 1 file changed, 3 deletions(-) diff --git a/.gitignore b/.gitignore index a1d671f9e..8a4df88dc 100644 --- a/.gitignore +++ b/.gitignore @@ -15,9 +15,6 @@ # Output of the go coverage tool, specifically when used with LiteIDE *.out -# Preprocessor intermediate files -*.h.i - # Dependency directories (remove the comment below to include it) # vendor/ From bc80a8d340121b42618f217baf71ac56822b294b Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Fri, 27 Jun 2025 04:09:31 +0000 Subject: [PATCH 06/10] Remove problematic TestLibModeConfiguration test to fix llgo compatibility Co-authored-by: luoliwoshang <51194195+luoliwoshang@users.noreply.github.com> --- _xtool/llcppsymg/internal/symg/lib_test.go | 80 ---------------------- 1 file changed, 80 deletions(-) diff --git a/_xtool/llcppsymg/internal/symg/lib_test.go b/_xtool/llcppsymg/internal/symg/lib_test.go index 703afbbe4..8e24c137c 100644 --- a/_xtool/llcppsymg/internal/symg/lib_test.go +++ b/_xtool/llcppsymg/internal/symg/lib_test.go @@ -189,84 +189,4 @@ func TestGenDylibPaths(t *testing.T) { } } -func TestLibModeConfiguration(t *testing.T) { - testCases := []struct { - name string - libName string - mode symbol.Mode - expected string // expected file extension - }{ - { - name: "Dynamic library mode", - libName: "test", - mode: symbol.ModeDynamic, - expected: getExpectedDynamicExt(), - }, - { - name: "Static library mode", - libName: "test", - mode: symbol.ModeStatic, - expected: ".a", - }, - } - - for _, tc := range testCases { - t.Run(tc.name, func(t *testing.T) { - tempDir, err := os.MkdirTemp("", "libmode_test") - if err != nil { - t.Fatal(err) - } - defer os.RemoveAll(tempDir) - - // Create the expected library file - expectedFileName := fmt.Sprintf("lib%s%s", tc.libName, tc.expected) - expectedPath := filepath.Join(tempDir, expectedFileName) - - file, err := os.Create(expectedPath) - if err != nil { - t.Fatalf("Failed to create test file %s: %v", expectedPath, err) - } - file.Close() - - // Test that the library can be found with the correct mode - foundPath, err := symbol.FindLibFile(tempDir, tc.libName, tc.mode) - if err != nil { - t.Fatal(err) - } - - if foundPath != expectedPath { - t.Errorf("Expected path %s, got %s", expectedPath, foundPath) - } - - // Test that the Libs.Files method respects the mode - libs := &symg.Libs{ - Paths: []string{tempDir}, - Names: []string{tc.libName}, - } - - foundPaths, notFound, err := libs.Files([]string{}, tc.mode) - if err != nil { - t.Fatal(err) - } - if len(notFound) > 0 { - t.Errorf("Expected no missing libraries, but found: %v", notFound) - } - - if len(foundPaths) != 1 { - t.Errorf("Expected 1 library path, got %d", len(foundPaths)) - } - - if foundPaths[0] != expectedPath { - t.Errorf("Expected path %s, got %s", expectedPath, foundPaths[0]) - } - }) - } -} - -func getExpectedDynamicExt() string { - if runtime.GOOS == "linux" { - return ".so" - } - return ".dylib" -} From e47e67982ba4794c3382bb9e5ebda1fe225e62a8 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Fri, 27 Jun 2025 06:16:54 +0000 Subject: [PATCH 07/10] Remove unexpected empty lines and add zlib-static demo for libstatic testing Co-authored-by: luoliwoshang <51194195+luoliwoshang@users.noreply.github.com> --- _llcppgtest/zlib-static/conf/linux/llcppg.cfg | 21 +++++++++ .../zlib-static/demo/crc32demo/demo.go | 17 ++++++++ .../zlib-static/demo/efficiency/efficiency.go | 38 ++++++++++++++++ _llcppgtest/zlib-static/demo/normal/normal.go | 43 +++++++++++++++++++ _llcppgtest/zlib-static/llcppg.cfg | 20 +++++++++ _xtool/llcppsymg/internal/symg/lib_test.go | 2 - 6 files changed, 139 insertions(+), 2 deletions(-) create mode 100644 _llcppgtest/zlib-static/conf/linux/llcppg.cfg create mode 100644 _llcppgtest/zlib-static/demo/crc32demo/demo.go create mode 100644 _llcppgtest/zlib-static/demo/efficiency/efficiency.go create mode 100644 _llcppgtest/zlib-static/demo/normal/normal.go create mode 100644 _llcppgtest/zlib-static/llcppg.cfg diff --git a/_llcppgtest/zlib-static/conf/linux/llcppg.cfg b/_llcppgtest/zlib-static/conf/linux/llcppg.cfg new file mode 100644 index 000000000..741a0660c --- /dev/null +++ b/_llcppgtest/zlib-static/conf/linux/llcppg.cfg @@ -0,0 +1,21 @@ +{ + "name": "zlib-static", + "cflags": "$(pkg-config --cflags zlib)", + "libs": "$(pkg-config --libs zlib)", + "include": [ + "zconf.h", + "zlib.h" + ], + "trimPrefixes": ["Z_"], + "cplusplus": false, + "mix":true, + "deps":["c/os"], + "symMap":{ + "compress":"Compress", + "compress2":"Compress2", + "uncompress":"Uncompress", + "uncompress2":"Uncompress2", + "compressBound":"CompressBound" + }, + "libstatic": true +} diff --git a/_llcppgtest/zlib-static/demo/crc32demo/demo.go b/_llcppgtest/zlib-static/demo/crc32demo/demo.go new file mode 100644 index 000000000..980fd6dbb --- /dev/null +++ b/_llcppgtest/zlib-static/demo/crc32demo/demo.go @@ -0,0 +1,17 @@ +package main + +import ( + "fmt" + "unsafe" + "zlib-static" +) + +func main() { + ul := zlib_static.ULong(0) + data := "Hello world" + res := ul.Crc32Z( + (*zlib_static.Bytef)(unsafe.Pointer(unsafe.StringData(data))), + zlib_static.ZSizeT(uintptr(len(data))), + ) + fmt.Printf("%08x\n", res) +} diff --git a/_llcppgtest/zlib-static/demo/efficiency/efficiency.go b/_llcppgtest/zlib-static/demo/efficiency/efficiency.go new file mode 100644 index 000000000..b1e98a8bc --- /dev/null +++ b/_llcppgtest/zlib-static/demo/efficiency/efficiency.go @@ -0,0 +1,38 @@ +package main + +import ( + "unsafe" + "zlib-static" + + "github.com/goplus/lib/c" +) + +func main() { + 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.") + txtLen := zlib_static.ULong(len(txt)) + + for level := 0; level <= 9; level++ { + cmpSize := zlib_static.ULongf(zlib_static.CompressBound(txtLen)) + cmpData := make([]byte, int(cmpSize)) + data := (*zlib_static.Bytef)(unsafe.Pointer(unsafe.SliceData(cmpData))) + source := (*zlib_static.Bytef)(unsafe.Pointer(unsafe.SliceData(txt))) + res := zlib_static.Compress2(data, &cmpSize, source, txtLen, c.Int(level)) + if res != zlib_static.OK { + c.Printf(c.Str("\nCompression failed at level %d: %d\n"), level, res) + continue + } + + c.Printf(c.Str("Compression level %d: Text length = %d, Compressed size = %d\n"), level, txtLen, cmpSize) + + ucmpSize := zlib_static.ULongf(txtLen) + ucmp := make([]byte, int(ucmpSize)) + ucmpData := (*zlib_static.Bytef)(unsafe.Pointer(unsafe.SliceData(ucmp))) + cmpSource := (*zlib_static.Bytef)(unsafe.Pointer(unsafe.SliceData(cmpData))) + + unRes := zlib_static.Uncompress(ucmpData, &ucmpSize, cmpSource, zlib_static.ULong(cmpSize)) + if unRes != zlib_static.OK { + c.Printf(c.Str("\nDecompression failed at level %d: %d\n"), level, unRes) + continue + } + } +} diff --git a/_llcppgtest/zlib-static/demo/normal/normal.go b/_llcppgtest/zlib-static/demo/normal/normal.go new file mode 100644 index 000000000..9f15e416d --- /dev/null +++ b/_llcppgtest/zlib-static/demo/normal/normal.go @@ -0,0 +1,43 @@ +package main + +import ( + "unsafe" + "zlib-static" + + "github.com/goplus/lib/c" +) + +func main() { + 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.") + txtLen := zlib_static.ULong(len(txt)) + + cmpSize := zlib_static.ULongf(zlib_static.CompressBound(txtLen)) + cmpData := make([]byte, int(cmpSize)) + data := (*zlib_static.Bytef)(unsafe.Pointer(unsafe.SliceData(cmpData))) + txtData := (*zlib_static.Bytef)(unsafe.Pointer(unsafe.SliceData(txt))) + + res := zlib_static.Compress(data, &cmpSize, txtData, txtLen) + if res != zlib_static.OK { + c.Printf(c.Str("\nCompression failed: %d\n"), res) + return + } + + c.Printf(c.Str("Text length = %d, Compressed size = %d\n"), txtLen, cmpSize) + + ucmpSize := zlib_static.ULongf(txtLen) + ucmp := make([]byte, int(ucmpSize)) + ucmpPtr := (*zlib_static.Bytef)(unsafe.Pointer(unsafe.SliceData(ucmp))) + + unRes := zlib_static.Uncompress(ucmpPtr, &ucmpSize, data, zlib_static.ULong(cmpSize)) + c.Printf(c.Str("Decompression result = %d, Decompressed size %d\n"), unRes, ucmpSize) + + if unRes != zlib_static.OK { + c.Printf(c.Str("\nDecompression failed: %d\n"), unRes) + return + } + + c.Printf(c.Str("Decompressed data: \n")) + for i := 0; i < int(ucmpSize); i++ { + c.Printf(c.Str("%c"), ucmp[i]) + } +} diff --git a/_llcppgtest/zlib-static/llcppg.cfg b/_llcppgtest/zlib-static/llcppg.cfg new file mode 100644 index 000000000..2789ccae9 --- /dev/null +++ b/_llcppgtest/zlib-static/llcppg.cfg @@ -0,0 +1,20 @@ +{ + "name": "zlib-static", + "cflags": "$(pkg-config --cflags zlib)", + "libs": "$(pkg-config --libs zlib)", + "include": [ + "zconf.h", + "zlib.h" + ], + "trimPrefixes": ["Z_"], + "cplusplus": false, + "deps":["c/os"], + "symMap":{ + "compress":"Compress", + "compress2":"Compress2", + "uncompress":"Uncompress", + "uncompress2":"Uncompress2", + "compressBound":"CompressBound" + }, + "libstatic": true +} diff --git a/_xtool/llcppsymg/internal/symg/lib_test.go b/_xtool/llcppsymg/internal/symg/lib_test.go index 8e24c137c..5ee33d235 100644 --- a/_xtool/llcppsymg/internal/symg/lib_test.go +++ b/_xtool/llcppsymg/internal/symg/lib_test.go @@ -188,5 +188,3 @@ func TestGenDylibPaths(t *testing.T) { } } - - From 4aad4845a854345638fcb2cd8cd33194dcca8a74 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Fri, 27 Jun 2025 06:44:26 +0000 Subject: [PATCH 08/10] Fix symbol extraction for static libraries by removing -D flag Co-authored-by: luoliwoshang <51194195+luoliwoshang@users.noreply.github.com> --- _xtool/llcppsymg/internal/symg/symg.go | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/_xtool/llcppsymg/internal/symg/symg.go b/_xtool/llcppsymg/internal/symg/symg.go index fccaf3824..2501957be 100644 --- a/_xtool/llcppsymg/internal/symg/symg.go +++ b/_xtool/llcppsymg/internal/symg/symg.go @@ -10,6 +10,7 @@ import ( "github.com/goplus/llcppg/_xtool/internal/clangtool" "github.com/goplus/llcppg/_xtool/internal/header" "github.com/goplus/llcppg/_xtool/internal/ld" + "github.com/goplus/llcppg/_xtool/internal/symbol" llcppg "github.com/goplus/llcppg/config" "github.com/goplus/llgo/xtool/nm" ) @@ -117,7 +118,7 @@ func fetchSymbols(lib string, mode LibMode) ([]*nm.Symbol, error) { for _, libFile := range libFiles { args := []string{"-g"} - if runtime.GOOS == "linux" { + if runtime.GOOS == "linux" && mode == symbol.ModeDynamic { args = append(args, "-D") } From 09012efc78957e5afdef61d916af47a021925ca7 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Fri, 27 Jun 2025 07:03:00 +0000 Subject: [PATCH 09/10] Fix zlib-static demo package name to be valid Go identifier Co-authored-by: luoliwoshang <51194195+luoliwoshang@users.noreply.github.com> --- _llcppgtest/zlib-static/conf/linux/llcppg.cfg | 2 +- .../zlib-static/demo/crc32demo/demo.go | 8 +++---- .../zlib-static/demo/efficiency/efficiency.go | 24 +++++++++---------- _llcppgtest/zlib-static/demo/normal/normal.go | 22 ++++++++--------- _llcppgtest/zlib-static/llcppg.cfg | 2 +- 5 files changed, 29 insertions(+), 29 deletions(-) diff --git a/_llcppgtest/zlib-static/conf/linux/llcppg.cfg b/_llcppgtest/zlib-static/conf/linux/llcppg.cfg index 741a0660c..ee69c3958 100644 --- a/_llcppgtest/zlib-static/conf/linux/llcppg.cfg +++ b/_llcppgtest/zlib-static/conf/linux/llcppg.cfg @@ -1,5 +1,5 @@ { - "name": "zlib-static", + "name": "zlibstatic", "cflags": "$(pkg-config --cflags zlib)", "libs": "$(pkg-config --libs zlib)", "include": [ diff --git a/_llcppgtest/zlib-static/demo/crc32demo/demo.go b/_llcppgtest/zlib-static/demo/crc32demo/demo.go index 980fd6dbb..7a6131fb8 100644 --- a/_llcppgtest/zlib-static/demo/crc32demo/demo.go +++ b/_llcppgtest/zlib-static/demo/crc32demo/demo.go @@ -3,15 +3,15 @@ package main import ( "fmt" "unsafe" - "zlib-static" + "zlibstatic" ) func main() { - ul := zlib_static.ULong(0) + ul := zlibstatic.ULong(0) data := "Hello world" res := ul.Crc32Z( - (*zlib_static.Bytef)(unsafe.Pointer(unsafe.StringData(data))), - zlib_static.ZSizeT(uintptr(len(data))), + (*zlibstatic.Bytef)(unsafe.Pointer(unsafe.StringData(data))), + zlibstatic.ZSizeT(uintptr(len(data))), ) fmt.Printf("%08x\n", res) } diff --git a/_llcppgtest/zlib-static/demo/efficiency/efficiency.go b/_llcppgtest/zlib-static/demo/efficiency/efficiency.go index b1e98a8bc..680838843 100644 --- a/_llcppgtest/zlib-static/demo/efficiency/efficiency.go +++ b/_llcppgtest/zlib-static/demo/efficiency/efficiency.go @@ -2,35 +2,35 @@ package main import ( "unsafe" - "zlib-static" + "zlibstatic" "github.com/goplus/lib/c" ) func main() { 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.") - txtLen := zlib_static.ULong(len(txt)) + txtLen := zlibstatic.ULong(len(txt)) for level := 0; level <= 9; level++ { - cmpSize := zlib_static.ULongf(zlib_static.CompressBound(txtLen)) + cmpSize := zlibstatic.ULongf(zlibstatic.CompressBound(txtLen)) cmpData := make([]byte, int(cmpSize)) - data := (*zlib_static.Bytef)(unsafe.Pointer(unsafe.SliceData(cmpData))) - source := (*zlib_static.Bytef)(unsafe.Pointer(unsafe.SliceData(txt))) - res := zlib_static.Compress2(data, &cmpSize, source, txtLen, c.Int(level)) - if res != zlib_static.OK { + data := (*zlibstatic.Bytef)(unsafe.Pointer(unsafe.SliceData(cmpData))) + source := (*zlibstatic.Bytef)(unsafe.Pointer(unsafe.SliceData(txt))) + res := zlibstatic.Compress2(data, &cmpSize, source, txtLen, c.Int(level)) + if res != zlibstatic.OK { c.Printf(c.Str("\nCompression failed at level %d: %d\n"), level, res) continue } c.Printf(c.Str("Compression level %d: Text length = %d, Compressed size = %d\n"), level, txtLen, cmpSize) - ucmpSize := zlib_static.ULongf(txtLen) + ucmpSize := zlibstatic.ULongf(txtLen) ucmp := make([]byte, int(ucmpSize)) - ucmpData := (*zlib_static.Bytef)(unsafe.Pointer(unsafe.SliceData(ucmp))) - cmpSource := (*zlib_static.Bytef)(unsafe.Pointer(unsafe.SliceData(cmpData))) + ucmpData := (*zlibstatic.Bytef)(unsafe.Pointer(unsafe.SliceData(ucmp))) + cmpSource := (*zlibstatic.Bytef)(unsafe.Pointer(unsafe.SliceData(cmpData))) - unRes := zlib_static.Uncompress(ucmpData, &ucmpSize, cmpSource, zlib_static.ULong(cmpSize)) - if unRes != zlib_static.OK { + unRes := zlibstatic.Uncompress(ucmpData, &ucmpSize, cmpSource, zlibstatic.ULong(cmpSize)) + if unRes != zlibstatic.OK { c.Printf(c.Str("\nDecompression failed at level %d: %d\n"), level, unRes) continue } diff --git a/_llcppgtest/zlib-static/demo/normal/normal.go b/_llcppgtest/zlib-static/demo/normal/normal.go index 9f15e416d..4b03e6c6e 100644 --- a/_llcppgtest/zlib-static/demo/normal/normal.go +++ b/_llcppgtest/zlib-static/demo/normal/normal.go @@ -2,36 +2,36 @@ package main import ( "unsafe" - "zlib-static" + "zlibstatic" "github.com/goplus/lib/c" ) func main() { 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.") - txtLen := zlib_static.ULong(len(txt)) + txtLen := zlibstatic.ULong(len(txt)) - cmpSize := zlib_static.ULongf(zlib_static.CompressBound(txtLen)) + cmpSize := zlibstatic.ULongf(zlibstatic.CompressBound(txtLen)) cmpData := make([]byte, int(cmpSize)) - data := (*zlib_static.Bytef)(unsafe.Pointer(unsafe.SliceData(cmpData))) - txtData := (*zlib_static.Bytef)(unsafe.Pointer(unsafe.SliceData(txt))) + data := (*zlibstatic.Bytef)(unsafe.Pointer(unsafe.SliceData(cmpData))) + txtData := (*zlibstatic.Bytef)(unsafe.Pointer(unsafe.SliceData(txt))) - res := zlib_static.Compress(data, &cmpSize, txtData, txtLen) - if res != zlib_static.OK { + res := zlibstatic.Compress(data, &cmpSize, txtData, txtLen) + if res != zlibstatic.OK { c.Printf(c.Str("\nCompression failed: %d\n"), res) return } c.Printf(c.Str("Text length = %d, Compressed size = %d\n"), txtLen, cmpSize) - ucmpSize := zlib_static.ULongf(txtLen) + ucmpSize := zlibstatic.ULongf(txtLen) ucmp := make([]byte, int(ucmpSize)) - ucmpPtr := (*zlib_static.Bytef)(unsafe.Pointer(unsafe.SliceData(ucmp))) + ucmpPtr := (*zlibstatic.Bytef)(unsafe.Pointer(unsafe.SliceData(ucmp))) - unRes := zlib_static.Uncompress(ucmpPtr, &ucmpSize, data, zlib_static.ULong(cmpSize)) + unRes := zlibstatic.Uncompress(ucmpPtr, &ucmpSize, data, zlibstatic.ULong(cmpSize)) c.Printf(c.Str("Decompression result = %d, Decompressed size %d\n"), unRes, ucmpSize) - if unRes != zlib_static.OK { + if unRes != zlibstatic.OK { c.Printf(c.Str("\nDecompression failed: %d\n"), unRes) return } diff --git a/_llcppgtest/zlib-static/llcppg.cfg b/_llcppgtest/zlib-static/llcppg.cfg index 2789ccae9..cd53cad4e 100644 --- a/_llcppgtest/zlib-static/llcppg.cfg +++ b/_llcppgtest/zlib-static/llcppg.cfg @@ -1,5 +1,5 @@ { - "name": "zlib-static", + "name": "zlibstatic", "cflags": "$(pkg-config --cflags zlib)", "libs": "$(pkg-config --libs zlib)", "include": [ From f9844c624e8383c1631736a4ecd34d4705b989e1 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Fri, 27 Jun 2025 07:18:58 +0000 Subject: [PATCH 10/10] Rename zlib-static folder to zlibstatic to match package name Co-authored-by: luoliwoshang <51194195+luoliwoshang@users.noreply.github.com> --- _llcppgtest/{zlib-static => zlibstatic}/conf/linux/llcppg.cfg | 0 _llcppgtest/{zlib-static => zlibstatic}/demo/crc32demo/demo.go | 0 .../{zlib-static => zlibstatic}/demo/efficiency/efficiency.go | 0 _llcppgtest/{zlib-static => zlibstatic}/demo/normal/normal.go | 0 _llcppgtest/{zlib-static => zlibstatic}/llcppg.cfg | 0 5 files changed, 0 insertions(+), 0 deletions(-) rename _llcppgtest/{zlib-static => zlibstatic}/conf/linux/llcppg.cfg (100%) rename _llcppgtest/{zlib-static => zlibstatic}/demo/crc32demo/demo.go (100%) rename _llcppgtest/{zlib-static => zlibstatic}/demo/efficiency/efficiency.go (100%) rename _llcppgtest/{zlib-static => zlibstatic}/demo/normal/normal.go (100%) rename _llcppgtest/{zlib-static => zlibstatic}/llcppg.cfg (100%) diff --git a/_llcppgtest/zlib-static/conf/linux/llcppg.cfg b/_llcppgtest/zlibstatic/conf/linux/llcppg.cfg similarity index 100% rename from _llcppgtest/zlib-static/conf/linux/llcppg.cfg rename to _llcppgtest/zlibstatic/conf/linux/llcppg.cfg diff --git a/_llcppgtest/zlib-static/demo/crc32demo/demo.go b/_llcppgtest/zlibstatic/demo/crc32demo/demo.go similarity index 100% rename from _llcppgtest/zlib-static/demo/crc32demo/demo.go rename to _llcppgtest/zlibstatic/demo/crc32demo/demo.go diff --git a/_llcppgtest/zlib-static/demo/efficiency/efficiency.go b/_llcppgtest/zlibstatic/demo/efficiency/efficiency.go similarity index 100% rename from _llcppgtest/zlib-static/demo/efficiency/efficiency.go rename to _llcppgtest/zlibstatic/demo/efficiency/efficiency.go diff --git a/_llcppgtest/zlib-static/demo/normal/normal.go b/_llcppgtest/zlibstatic/demo/normal/normal.go similarity index 100% rename from _llcppgtest/zlib-static/demo/normal/normal.go rename to _llcppgtest/zlibstatic/demo/normal/normal.go diff --git a/_llcppgtest/zlib-static/llcppg.cfg b/_llcppgtest/zlibstatic/llcppg.cfg similarity index 100% rename from _llcppgtest/zlib-static/llcppg.cfg rename to _llcppgtest/zlibstatic/llcppg.cfg