Program modularization method, device, equipment, storage medium and computer program product

By generating dynamic libraries and determining the target function name, the problem of low independence and flexibility in Go program modularization is solved, enabling cross-platform Go program modularization and improving program independence and flexibility.

CN122173129APending Publication Date: 2026-06-09BEIJING HONGTENG INTELLIGENT TECH CO LTD
View PDF 0 Cites 0 Cited by

Patent Information

Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
BEIJING HONGTENG INTELLIGENT TECH CO LTD
Filing Date
2024-12-06
Publication Date
2026-06-09

AI Technical Summary

Technical Problem

In existing Go language modular programming, the Go plugin mechanism requires programs to use the same version of toolchain, build tags, and environment variables, resulting in low independence and flexibility.

Method used

Based on the Go code to be modularized and the programming language type, a dynamic library is generated. By checking whether the target function name exists in the global logic function table, the internal logic function of the target is determined and executed, thus achieving cross-platform modularization of Go programs.

Benefits of technology

It achieves the independence and flexibility of Go language program modularity, avoids the risk of program crashes due to version differences, and is suitable for large-scale Go program systems developed collaboratively by distributed teams.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN122173129A_ABST
    Figure CN122173129A_ABST
Patent Text Reader

Abstract

The application discloses a program modularization method and device, equipment, a storage medium and a computer program product, and relates to the technical field of computers. The method comprises the following steps: generating a code dynamic library based on to-be-modularized Go code and a programming language type corresponding to the to-be-modularized Go code; determining whether a function name identical to a target function name corresponding to a to-be-executed logic function exists in a global logic function table in the code dynamic library; if the function name exists, determining a target internal logic function based on the target function name; and calling and executing a target programming language type corresponding to the target internal logic function in the code dynamic library. By applying the technical solution, the technical problem that, in the prior art, a Go plugin mechanism is used to realize Go language program modularization, and the program needs to be compiled by using specific parameters, thereby resulting in low independence and flexibility of the program is solved.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This application relates to the field of computer technology, and in particular to methods, apparatus, devices, storage media and computer program products for program modularization. Background Technology

[0002] Modular programming is a programming approach that breaks down a program into independent, reusable modules, each responsible for implementing a specific function. Due to its high degree of independence and flexibility, it spread rapidly upon its introduction. Modular programming is now very common, supported by almost all mainstream programming languages. However, the relative importance of modules varies across different languages, and their forms also differ.

[0003] As a relatively new programming language, Go supports modular programming. Existing Go program modularization is typically achieved using the Go plugin mechanism. However, the Go plugin mechanism usually requires programs to be compiled using the same version of the toolchain, the same build tags, and the same values ​​for certain flags and environment variables; otherwise, runtime crashes may occur. Therefore, modular programming in Go using this method offers limited program independence and flexibility. Summary of the Invention

[0004] The main objective of this application is to provide a method, apparatus, device, storage medium, and computer program product for program modularization, aiming to solve the technical problem in the prior art where the modularization of Go language programs through the Go plugin mechanism requires the program to be compiled with specific parameters, resulting in low independence and flexibility of the program.

[0005] To achieve the above objectives, this application proposes a modular program approach, which includes:

[0006] Generate a dynamic library based on the Go code to be modularized and the corresponding programming language type of the Go code to be modularized;

[0007] Determine whether there exists a function name in the global logic function table of the code dynamic library that has the same name as the target function name corresponding to the logic function to be executed;

[0008] If it exists, then determine the target's internal logic function based on the target function name;

[0009] Call and execute the target programming language type corresponding to the target internal logic function in the dynamic code library.

[0010] In one embodiment, before the step of determining whether there exists a function name in the global logic function table of the code dynamic library that has the same name as the target function name corresponding to the logic function to be executed, the method further includes:

[0011] The dynamic library is initialized using the initialization interface corresponding to the dynamic library.

[0012] Upon completion of initialization, a global logic function table is constructed using the logic function table acquisition interface corresponding to the dynamic code library.

[0013] In one embodiment, the step of constructing a global logic function table through the logic function table acquisition interface corresponding to the code dynamic library upon completion of initialization includes:

[0014] Upon completion of initialization, obtain the names of all logical functions and the addresses of their internal logic functions in the dynamic library.

[0015] Based on the logical function name and the internal logical function address, a global logical function table is constructed through the logical function table acquisition interface corresponding to the code dynamic library.

[0016] In one embodiment, the step of initializing the code dynamic library through the initialization interface corresponding to the code dynamic library includes:

[0017] Determine the initialization task of the code dynamic library, wherein the initialization task includes at least one of allocating memory, opening a file, and creating a synchronization primitive;

[0018] The dynamic code library is initialized based on the initialization interface and the initialization task corresponding to the dynamic code library.

[0019] In one embodiment, the step of initializing the code dynamic library based on the initialization interface corresponding to the code dynamic library and the initialization task includes:

[0020] If the initialization task is to allocate memory, then determine the memory usage of all logical function tables in the code dynamic library;

[0021] Based on the memory usage, memory is allocated to the logical function table through the initialization interface corresponding to the code dynamic library.

[0022] In one embodiment, the step of allocating memory for the logical function table based on the memory footprint through the initialization interface corresponding to the code dynamic library includes:

[0023] The partition information of the code dynamic library is generated based on the memory partitioning rules and the memory usage size;

[0024] Based on the partition information, determine the memory region of the logical function table in the dynamic code library and the region ratio of the memory region;

[0025] Based on the memory region and the region ratio, memory is allocated to the logical function table through the initialization interface corresponding to the code dynamic library.

[0026] In one embodiment, the step of determining the target internal logic function based on the target function name includes:

[0027] The address of the target internal logic function is determined from the global logic function table based on the target function name;

[0028] Determine the target internal logic function corresponding to the address of the target internal logic function.

[0029] In one embodiment, after the step of calling and executing the target programming language type corresponding to the target internal logic function in the code dynamic library, the method further includes:

[0030] Determine the deinitialization task to be executed corresponding to the code dynamic library, wherein the deinitialization task to be executed includes at least one of releasing memory, closing files, and destroying synchronization primitives;

[0031] Based on the deinitialization task to be executed, the code dynamic library is deinitialized through the deinitialization interface corresponding to the code dynamic library.

[0032] In one embodiment, the step of deinitializing the code dynamic library based on the deinitialization task to be executed by using the deinitialization interface corresponding to the code dynamic library includes:

[0033] If the uninitialization task to be executed is to release memory, then the memory release function is called, and the memory address and size to be released are determined based on the release parameters in the memory release function.

[0034] Based on the memory address to be released, determine the table of logic functions to be released in the code dynamic library;

[0035] Based on the size of the memory to be released and the table of logic functions to be released, the memory of the dynamic library is released by using the deinitialization interface corresponding to the dynamic library.

[0036] Furthermore, to achieve the above objectives, this application also proposes a modular program device, the device comprising:

[0037] The dynamic library generation module is used to generate a dynamic library based on the Go code to be modularized and the programming language type corresponding to the Go code to be modularized.

[0038] The function query module is used to determine whether there is a function name in the global logic function table of the code dynamic library that is the same as the target function name corresponding to the logic function to be executed;

[0039] A function determination module is used to determine the target's internal logic function based on the target function name if the function exists.

[0040] The function execution module is used to call and execute the target programming language type corresponding to the target internal logic function in the code dynamic library.

[0041] In one embodiment, the device further includes:

[0042] The function table construction module is used to initialize the code dynamic library through the initialization interface corresponding to the code dynamic library; when the initialization is completed, it constructs a global logical function table through the logical function table acquisition interface corresponding to the code dynamic library.

[0043] In one embodiment, the function table construction module is further configured to, upon completion of initialization, obtain the names of all logical functions and the addresses of their internal logical functions in the code dynamic library; and, based on the names of the logical functions and the addresses of their internal logical functions, construct a global logical function table through the logical function table acquisition interface corresponding to the code dynamic library.

[0044] In one embodiment, the function table construction module is further configured to determine the initialization task of the code dynamic library, the initialization task including at least one of allocating memory, opening a file, and creating a synchronization primitive; and to initialize the code dynamic library based on the initialization interface corresponding to the code dynamic library and the initialization task.

[0045] In one embodiment, the function table construction module is further configured to, if the initialization task is to allocate memory, determine the memory footprint of all logical function tables in the code dynamic library; and, based on the memory footprint, allocate memory for the logical function tables through the initialization interface corresponding to the code dynamic library.

[0046] In one embodiment, the function table construction module is further configured to generate partition information of the code dynamic library based on memory partitioning rules and the memory usage size; determine the memory region of the logical function table in the code dynamic library and the region ratio of the memory region according to the partition information; and allocate memory for the logical function table through the initialization interface corresponding to the code dynamic library based on the memory region and the region ratio.

[0047] In one embodiment, the function determination module is further configured to determine the address of a target internal logic function from the global logic function table based on the target function name; and determine the target internal logic function corresponding to the target internal logic function address.

[0048] In one embodiment, the device further includes:

[0049] The deinitialization module is used to determine the deinitialization task to be executed for the code dynamic library, wherein the deinitialization task to be executed includes at least one of releasing memory, closing files, and destroying synchronization primitives; based on the deinitialization task to be executed, the code dynamic library is deinitialized by the deinitialization interface corresponding to the code dynamic library.

[0050] In addition, to achieve the above objectives, this application also proposes a program modularization device, the device comprising: a memory, a processor, and a computer program stored in the memory and executable on the processor, the computer program being configured to implement the steps of the program modularization method as described above.

[0051] In addition, to achieve the above objectives, this application also proposes a storage medium, which is a computer-readable storage medium, on which a computer program is stored, and which, when executed by a processor, implements the steps of the program modularization method described above.

[0052] In addition, to achieve the above objectives, this application also provides a computer program product, which includes a computer program that, when executed by a processor, implements the steps of the program modularization method described above.

[0053] This application provides a method for program modularization. It discloses generating a dynamic library based on the Go code to be modularized and its corresponding programming language type; determining whether a function name exists in the global logic function table of the dynamic library that is identical to the target function name corresponding to the logic function to be executed; if so, determining the target internal logic function based on the target function name; and calling and executing the target programming language type corresponding to the target internal logic function in the dynamic library. Compared to the existing Go plugin mechanism for Go program modularization, which typically requires programs to be compiled using the same version of the toolchain, the same build tags, and the same values ​​for certain flags and environment variables, this invention generates a dynamic library based on the Go code to be modularized and its corresponding programming language type. This allows Go code to be compiled by calling the target programming language type corresponding to the target internal logic function in the dynamic library corresponding to the logic function to be executed, thus solving the technical problem that the existing Go plugin mechanism for Go program modularization requires the program to be compiled with specific parameters, resulting in low program independence and flexibility. Attached Figure Description

[0054] The accompanying drawings, which are incorporated in and form part of this specification, illustrate embodiments consistent with this application and, together with the description, serve to explain the principles of this application.

[0055] To more clearly illustrate the technical solutions in the embodiments of this application or the prior art, the drawings used in the description of the embodiments or the prior art will be briefly introduced below. Obviously, for those skilled in the art, other drawings can be obtained based on these drawings without creative effort.

[0056] Figure 1 This is a flowchart illustrating an embodiment of the modular method for the present application.

[0057] Figure 2 This is a flowchart illustrating Embodiment 2 of the modular method for the present application.

[0058] Figure 3 This is a flowchart illustrating Embodiment 3 of the modular method for the present application.

[0059] Figure 4 This is an overall flowchart of the modular approach to the procedure described in this application;

[0060] Figure 5 This is a schematic diagram of the modular structure of the program modularization device according to an embodiment of this application;

[0061] Figure 6This is a schematic diagram of the device structure of the hardware operating environment involved in the program modularization method in this application embodiment.

[0062] The purpose, features, and advantages of this application will be further explained in conjunction with the embodiments and with reference to the accompanying drawings. Detailed Implementation

[0063] It should be understood that the specific embodiments described herein are merely illustrative of the technical solutions of this application and are not intended to limit this application.

[0064] To better understand the technical solution of this application, a detailed description will be provided below in conjunction with the accompanying drawings and specific implementation methods.

[0065] The main solution of this application embodiment is: generating a code dynamic library based on the Go code to be modularized and the programming language type corresponding to the Go code to be modularized; determining whether there is a function name in the global logic function table of the code dynamic library that is the same as the target function name corresponding to the logic function to be executed; if so, determining the target internal logic function based on the target function name; and calling and executing the target programming language type corresponding to the target internal logic function in the code dynamic library.

[0066] In existing technologies, Go program modularization is usually achieved using the Go plugin mechanism. This mechanism typically requires programs to be compiled using the same version of the toolchain, the same build tags, and the same values ​​for certain flags and environment variables. Otherwise, crashes may occur at runtime. Therefore, Go program modularization in this way does not offer high independence and flexibility.

[0067] This application provides a solution that can generate a dynamic library based on the Go code to be modularized and its corresponding programming language type. This allows the Go code to be compiled by calling the target programming language type of the target internal logic function in the dynamic library, thereby solving the technical problem that the existing technology of modularizing Go programs through the Go plugin mechanism requires the program to be compiled with specific parameters, resulting in low independence and flexibility of the program.

[0068] It should be noted that the executing entity in this embodiment can be a computing service device with data processing, network communication, and program execution functions, such as a tablet computer, personal computer, or mobile phone, or an electronic device or modular program device capable of performing the above functions. The following description uses a modular program device (hereinafter referred to as "device") as an example to illustrate this embodiment and the subsequent embodiments.

[0069] Based on this, the embodiments of this application provide a program modularization method, referring to... Figure 1 , Figure 1 This is a flowchart illustrating the first embodiment of the modular method of this application.

[0070] In this embodiment, the program modularization method includes steps S10 to S40:

[0071] Step S10: Generate a dynamic library based on the Go code to be modularized and the corresponding programming language type.

[0072] It should be understood that the Go code to be modularized mentioned above can be any Go code that needs to be modularized.

[0073] It should be noted that the above-mentioned programming language type refers to the type of programming language. Currently, common computer programming languages ​​include C, C++, Java, Python, JavaScript, etc. Among them, the programming language type in this embodiment can be C.

[0074] It should be noted that the dynamic library mentioned above can be a library file that is loaded at program runtime, also known as a shared library. In practical applications, the code in the dynamic library is loaded into memory only at program runtime, rather than being included in the executable file at compile time. This allows the program to use specific library functions only when needed, thereby saving memory.

[0075] In this embodiment, the C code corresponding to the Go code to be modularized can be generated first, and then the Go code to be modularized and the corresponding C code can be compiled to generate a dynamic library.

[0076] Step S20: Determine whether there exists a function name in the global logic function table of the code dynamic library that has the same name as the target function name corresponding to the logic function to be executed.

[0077] It should be understood that the aforementioned global logic function table can be a storage space for storing the names and addresses of logic functions, where the names and addresses of logic functions in the global logic function table can be stored accordingly.

[0078] It is understandable that the name of the target function mentioned above is the same as the name of the function corresponding to the logic function to be executed.

[0079] Step S30: If it exists, determine the target internal logic function based on the target function name.

[0080] It should be noted that the aforementioned target internal logic function can be a logic function in the code dynamic library whose function name is the target function name.

[0081] Specifically, step S30 includes: determining the address of the target internal logic function from the global logic function table according to the target function name; and determining the target internal logic function corresponding to the target internal logic function address.

[0082] It is understood that the aforementioned target internal logic function address is the address where the target internal logic function is stored in the code dynamic library. In this embodiment, since the global logic function table maps and stores the names and addresses of all logic functions, if the target function name of the logic function to be executed exists in the global logic function table, the device can query the address corresponding to the target function name in the global logic function table, thereby obtaining the aforementioned target internal logic function address. Then, the function represented by the target internal logic function address can be determined as the target internal logic function. Furthermore, if the target function name of the logic function to be executed does not exist in the global logic function table, the execution of the logic function ends.

[0083] Step S40: Call and execute the target programming language type corresponding to the target internal logic function in the code dynamic library.

[0084] In practical applications, after determining the target internal logic function in the dynamic library, the target programming language type corresponding to the target internal logic function can be called and executed. In this embodiment, the target programming language type corresponding to the target internal logic function can be C language, meaning that the C code corresponding to the target internal logic function can be executed in this embodiment. Since the internal logic function in the dynamic library contains implementations in both C and Go languages, and the C and Go code correspond one-to-one, it is possible to translate the C-style logic function into the corresponding Go-style logic function. This achieves Go module independence and eliminates the risk of program crashes caused by Go modules using different versions of toolchains or referencing different versions of dependency libraries.

[0085] This embodiment provides a program modularization method. The method discloses generating a dynamic library based on the Go code to be modularized and its corresponding programming language type; determining whether a function name exists in the global logic function table of the dynamic library that matches the target function name corresponding to the logic function to be executed; if so, determining the target internal logic function based on the target function name; and calling and executing the target programming language type corresponding to the target internal logic function in the dynamic library. Compared to the existing Go plugin mechanism for Go program modularization, which typically requires programs to be compiled using the same version of the toolchain, the same build tags, and the same values ​​for certain flags and environment variables, this embodiment can generate a dynamic library based on the Go code to be modularized and its corresponding programming language type. This allows Go code to be compiled by calling the target programming language type corresponding to the target internal logic function in the dynamic library corresponding to the logic function to be executed. This solves the technical problem in the existing Go plugin mechanism for Go program modularization, which requires the program to be compiled using specific parameters, resulting in low program independence and flexibility.

[0086] Based on the first embodiment of this application, in the second embodiment of this application, the content that is the same as or similar to that in the first embodiment described above can be referred to the above description, and will not be repeated hereafter. Based on this, please refer to... Figure 2 , Figure 2 This is a flowchart illustrating a second embodiment of the modular method for the present application.

[0087] In this embodiment, before step S10, the method further includes steps S01 to S02:

[0088] Step S01: Initialize the code dynamic library through the initialization interface corresponding to the code dynamic library.

[0089] It is understood that after generating the dynamic library, this embodiment can export C interfaces from the dynamic library. In this embodiment, the C interfaces exported by the dynamic library may include, but are not limited to, initialization interfaces, logic function execution interfaces, logic function table retrieval interfaces, and deinitialization interfaces. Specifically, the initialization interface can be used to initialize the dynamic library; the logic function execution interface can be used to execute logic functions; the logic function table retrieval interface can be used to retrieve the logic function table in the dynamic library; and the deinitialization interface can be used to deinitialize the dynamic library.

[0090] It should be noted that in this embodiment, cross-platform compatibility can be achieved by exporting the C interface through a dynamic library. The C interface supports not only Linux, FreeBSD, and macOS, but also Windows.

[0091] Step S02: Upon completion of initialization, construct a global logic function table through the logic function table acquisition interface corresponding to the code dynamic library.

[0092] Further, step S02 includes: upon completion of initialization, obtaining the names of all logical functions and the addresses of their internal logical functions in the code dynamic library; and constructing a global logical function table based on the names of the logical functions and the addresses of their internal logical functions through the interface for obtaining the logical function table corresponding to the code dynamic library.

[0093] In practical applications, after generating the code dynamic library, the device can call the initialization interface exported by the code dynamic library to complete the initialization of the code dynamic library. After initialization, the device can call the logic function table acquisition interface in the code dynamic library to construct a global logic function table. In the global logic function table, the KEY can be the name of the logic function, and the VALUE is the address of the internal logic function.

[0094] Further, step S01 includes:

[0095] Step S011: Determine the initialization task of the code dynamic library, wherein the initialization task includes at least one of allocating memory, opening a file, and creating a synchronization primitive.

[0096] It should be noted that the initialization work of a dynamic library may include at least one of the following: allocating memory, opening files, and creating synchronization primitives. Among them, allocating memory can be done by allocating memory for the logical functions in the dynamic library.

[0097] It should be understood that the file opening process during dynamic library initialization typically involves loading the dynamic library and executing the initialization function. If opening a file (such as a configuration file or data file) is required within the dynamic library's initialization function, standard file opening functions (such as fopen or std::fstream) can be used. After opening the file, corresponding read and write operations can be performed to meet the needs of dynamic library initialization.

[0098] Understandably, creating synchronization primitives can create mechanisms for synchronizing processes or threads when initializing a dynamic library, ensuring they access shared resources in a consistent manner.

[0099] Step S012: Initialize the code dynamic library based on the initialization interface and the initialization task corresponding to the code dynamic library.

[0100] In this embodiment, after determining the initialization work required by the code dynamic library, the initialization interface in the code dynamic library can be called to complete the corresponding initialization work.

[0101] Further, step S012 includes:

[0102] Step S012a: If the initialization task is to allocate memory, then determine the memory usage of all logical function tables in the code dynamic library.

[0103] Step S012b: Based on the memory usage, allocate memory for the logical function table through the initialization interface corresponding to the code dynamic library.

[0104] In this embodiment, the device can allocate memory for logic functions based on the memory size required to store the logic functions in the code dynamic library.

[0105] Specifically, step S012b includes: generating partition information for the code dynamic library based on memory partitioning rules and the memory usage size; determining the memory region of the logical function table in the code dynamic library and the region ratio of the memory region according to the partition information; and allocating memory for the logical function table through the initialization interface corresponding to the code dynamic library based on the memory region and the region ratio.

[0106] It should be understood that the above memory partitioning rules can be rules for allocating memory for logical functions stored in the code dynamic library.

[0107] In practical applications, the device can determine the partitioning information of the dynamic library based on the memory partitioning rules and the memory size required by the logic functions in the dynamic library. Then, based on the partitioning information, it can determine the area in the dynamic library where each logic function should be stored and the proportion of storage in that area. Finally, it can call the initialization interface of the dynamic library to allocate memory for the logic functions based on the storage area and the proportion of storage in that area.

[0108] It should be understood that the program modularization method provided by this solution can achieve cross-platform Go program modularization by exporting C interfaces through code dynamic libraries. At the same time, by translating C-style logic functions into Go-style logic functions, the program can have independence and flexibility, and does not need to be compiled using the same version of the toolchain, the same build tags, and the same values ​​of certain flags and environment variables. Therefore, it can be applied to large-scale Go program systems developed by distributed teams, improving the flexibility of Go language modular programming.

[0109] In this embodiment, the code dynamic library is initialized through the initialization interface corresponding to the code dynamic library; upon completion of initialization, a global logic function table is constructed through the logic function table acquisition interface corresponding to the code dynamic library; since this embodiment can be initialized according to the initialization interface in the C interface exported by the code dynamic library, and a global logic function table is constructed through the logic function table acquisition interface, cross-platform modular programming of Go language programs is realized.

[0110] Based on the first and / or second embodiments of this application, in the third embodiment of this application, the content that is the same as or similar to the above embodiments can be referred to the above description, and will not be repeated hereafter. Based on this, please refer to... Figure 3 , Figure 3 This is a flowchart illustrating Embodiment 3 of the modular method for the present application.

[0111] In this embodiment, after step S40, the method further includes steps S50 to S60:

[0112] Step S50: Determine the uninitialization task to be executed corresponding to the code dynamic library. The uninitialization task to be executed includes at least one of releasing memory, closing files, and destroying synchronization primitives.

[0113] It should be understood that the uninitialization task to be performed for the code dynamic library in this embodiment may include at least one of releasing memory, closing files, and destroying synchronization primitives. In practical applications, dynamic libraries are loaded during program runtime to provide additional functions or services. After the dynamic library completes its task, if it is not deinitialized, it will continue to occupy system resources, which may lead to resource leaks. Therefore, in this embodiment, after the logic code is executed, the code dynamic library can be deinitialized to release resources.

[0114] Step S60: Based on the deinitialization task to be executed, the code dynamic library is deinitialized through the deinitialization interface corresponding to the code dynamic library.

[0115] Further, step S60 includes: if the deinitialization task to be performed is to release memory, then calling the memory release function, and determining the memory address and size to be released based on the release parameters in the memory release function; determining the logic function table to be released in the code dynamic library based on the memory address to be released; and releasing the memory of the code dynamic library by means of the deinitialization interface corresponding to the code dynamic library based on the memory size to be released and the logic function table to be released.

[0116] It is understandable that the above-mentioned memory address to be released can be the address where the logic function to be released is stored in the code dynamic library; the above-mentioned memory size to be released can be the size of the memory occupied by the logic function being released this time.

[0117] In this embodiment, after the logic function is executed, in order to avoid the completed logic function occupying the resources of the code dynamic library, the device can determine the address of the logic function to be released and the memory size it occupies according to the parameters in the memory release function. Then, it can determine the logic function table where the logic function to be released is stored according to the address of the logic function to be released. Finally, it can call the deinitialization interface corresponding to the code dynamic library to release the memory of the function table corresponding to the logic function to be released in the code dynamic library and the memory size to be released.

[0118] In the specific implementation, refer to Figure 4 , Figure 4 This is an overall flowchart of the modular approach to the procedure described in this application. Figure 4 As shown, the device first compiles the Go code to be modularized and its corresponding C code to generate a dynamic library. This dynamic library can export C interfaces, including initialization, logic function execution, logic function table retrieval, and deinitialization interfaces. The initialization interface initializes the dynamic library, and the logic function retrieval interface constructs a global logic function table. When a logic function needs to be executed, the device checks the global logic function table for a function name matching the target function name. If found, the address of the target internal logic function is determined, and the target internal logic function represented by that address in the dynamic library is identified. The C code within the target internal logic function is then called and executed, ultimately enabling the invocation of the corresponding Go code within the dynamic library. After executing the logic function, the device deinitializes the dynamic library to release its resources and manage them appropriately.

[0119] In this embodiment, a deinitialization task to be executed corresponding to the code dynamic library is disclosed. The deinitialization task to be executed includes at least one of releasing memory, closing files, and destroying synchronization primitives. Based on the deinitialization task to be executed, the code dynamic library is deinitialized by the deinitialization interface corresponding to the code dynamic library, thereby releasing the resources occupied by the dynamic library and ensuring the reasonable management and release of resources in the code dynamic library.

[0120] It should be noted that the above examples are only for understanding this application and do not constitute a limitation on the modular approach of this application. Any simple modifications based on this technical concept are within the protection scope of this application.

[0121] This application also provides a modular program device, please refer to... Figure 5 The modular program device includes:

[0122] Dynamic library generation module 10 is used to generate a code dynamic library based on the Go code to be modularized and the programming language type corresponding to the Go code to be modularized.

[0123] The function query module 20 is used to determine whether there is a function name in the global logic function table of the code dynamic library that is the same as the target function name corresponding to the logic function to be executed;

[0124] The function determination module 30 is used to determine the target internal logic function based on the target function name if the target function exists.

[0125] The function execution module 40 is used to call and execute the target programming language type corresponding to the target internal logic function in the code dynamic library.

[0126] The program modularization device provided in this application, employing the program modularization method in the above embodiments, can solve the technical problem in the prior art where implementing Go language program modularization through the Go plugin mechanism requires the program to be compiled with specific parameters, resulting in low program independence and flexibility. Compared with the prior art, the beneficial effects of the program modularization device provided in this application are the same as those of the program modularization method provided in the above embodiments, and other technical features in the program modularization device are the same as those disclosed in the methods of the above embodiments, and will not be repeated here.

[0127] This application provides a program modularization device, which includes: at least one processor; and a memory communicatively connected to the at least one processor; wherein the memory stores instructions executable by the at least one processor, which are executed by the at least one processor to enable the at least one processor to perform the program modularization method in Embodiment 1 above.

[0128] The following is for reference. Figure 6The diagram illustrates a structural schematic suitable for implementing the modular program device of the embodiments of this application. The modular program device in the embodiments of this application may include, but is not limited to, mobile terminals such as mobile phones, laptops, digital broadcast receivers, PDAs (Personal Digital Assistants), PADs (Portable Application Description), PMPs (Portable Media Players), in-vehicle terminals (e.g., in-vehicle navigation terminals), and fixed terminals such as digital TVs and desktop computers. Figure 6 The modular device shown is merely an example and should not impose any limitation on the functionality and scope of use of the embodiments of this application.

[0129] like Figure 6 As shown, the modular programmable device may include a processing unit 1001 (e.g., a central processing unit, a graphics processing unit, etc.) that can perform various appropriate actions and processes according to a program stored in a read-only memory (ROM) 1002 or a program loaded from a storage device 1003 into a random access memory (RAM) 1004. The RAM 1004 also stores various programs and data required for the operation of the modular programmable device. The processing unit 1001, ROM 1002, and RAM 1004 are interconnected via a bus 1005. An input / output (I / O) interface 1006 is also connected to the bus. Typically, the following systems can be connected to the I / O interface 1006: input devices 1007 including, for example, touchscreens, touchpads, keyboards, mice, image sensors, microphones, accelerometers, gyroscopes, etc.; output devices 1008 including, for example, liquid crystal displays (LCDs), speakers, vibrators, etc.; storage devices 1003 including, for example, magnetic tapes, hard disks, etc.; and communication devices 1009. Communication device 1009 allows the modular device to communicate wirelessly or wiredly with other devices to exchange data. While the figure shows modular devices with various systems, it should be understood that implementation or possession of all the systems shown is not required. More or fewer systems may be implemented alternatively.

[0130] Specifically, according to the embodiments disclosed in this application, the processes described above with reference to the flowcharts can be implemented as computer software programs. For example, embodiments disclosed in this application include a computer program product comprising a computer program carried on a computer-readable medium, the computer program containing program code for performing the methods shown in the flowcharts. In such embodiments, the computer program can be downloaded and installed from a network via a communication device, or installed from storage device 1003, or installed from ROM 1002. When the computer program is executed by processing device 1001, it performs the functions defined in the methods of the embodiments disclosed in this application.

[0131] The modular program device provided in this application, employing the modular program method described in the above embodiments, can solve the technical problem of modular program development. Compared with the prior art, the beneficial effects of the modular program device provided in this application are the same as those of the modular program method provided in the above embodiments, and other technical features of this modular program device are the same as those disclosed in the previous embodiment method, and will not be repeated here.

[0132] It should be understood that the various parts disclosed in this application can be implemented using hardware, software, firmware, or a combination thereof. In the description of the above embodiments, specific features, structures, materials, or characteristics can be combined in any suitable manner in one or more embodiments or examples.

[0133] The above description is merely a specific embodiment of this application, but the scope of protection of this application is not limited thereto. Any variations or substitutions that can be easily conceived by those skilled in the art within the scope of the technology disclosed in this application should be included within the scope of protection of this application. Therefore, the scope of protection of this application should be determined by the scope of the claims.

[0134] This application provides a computer-readable storage medium having computer-readable program instructions (i.e., a computer program) stored thereon, the computer-readable program instructions being used to execute the program modularization method in the above embodiments.

[0135] The computer-readable storage medium provided in this application may be, for example, a USB flash drive, but is not limited to, electrical, magnetic, optical, electromagnetic, infrared, or semiconductor systems, devices, or any combination thereof. More specific examples of computer-readable storage media may include, but are not limited to: electrical connections having one or more wires, portable computer disks, hard disks, random access memory (RAM), read-only memory (ROM), erasable programmable read-only memory (EPROM or flash memory), optical fiber, portable compact disk read-only memory (CD-ROM), optical storage devices, magnetic storage devices, or any suitable combination thereof. In this embodiment, the computer-readable storage medium may be any tangible medium containing or storing a program that can be used by or in conjunction with an instruction execution system, system, or device. The program code contained on the computer-readable storage medium may be transmitted using any suitable medium, including but not limited to: wires, optical cables, RF (Radio Frequency), etc., or any suitable combination thereof.

[0136] The aforementioned computer-readable storage medium may be included in a program modular device; or it may exist independently and not assembled into a program modular device.

[0137] The aforementioned computer-readable storage medium carries one or more programs. When the one or more programs are executed by the program modularization device, the program modularization device: generates a code dynamic library based on the Go code to be modularized and the programming language type corresponding to the Go code to be modularized; determines whether there is a function name in the global logic function table of the code dynamic library that is the same as the target function name corresponding to the logic function to be executed; if so, determines the target internal logic function based on the target function name; and calls and executes the target programming language type corresponding to the target internal logic function in the code dynamic library.

[0138] Computer program code for performing the operations of this application can be written in one or more programming languages ​​or a combination thereof, including object-oriented programming languages ​​such as Java, Smalltalk, and C++, and conventional procedural programming languages ​​such as the "C" language or similar programming languages. The program code can be executed entirely on the user's computer, partially on the user's computer, as a standalone software package, partially on the user's computer and partially on a remote computer, or entirely on a remote computer or server. In cases involving remote computers, the remote computer can be connected to the user's computer via any type of network—including a Local Area Network (LAN) or a Wide Area Network (WAN)—or can be connected to an external computer (e.g., via the Internet using an Internet service provider).

[0139] The flowcharts and block diagrams in the accompanying drawings illustrate the architecture, functionality, and operation of possible implementations of systems, methods, and computer program products according to various embodiments of this application. In this regard, each block in a flowchart or block diagram may represent a module, segment, or portion of code containing one or more executable instructions for implementing a specified logical function. It should also be noted that in some alternative implementations, the functions indicated in the blocks may occur in a different order than those indicated in the drawings. For example, two consecutively indicated blocks may actually be executed substantially in parallel, and they may sometimes be executed in reverse order, depending on the functions involved. It should also be noted that each block in the block diagrams and / or flowcharts, and combinations of blocks in the block diagrams and / or flowcharts, can be implemented using a dedicated hardware-based system that performs the specified function or operation, or using a combination of dedicated hardware and computer instructions.

[0140] The modules described in the embodiments of this application can be implemented in software or hardware. The names of the modules do not necessarily limit the functionality of the unit itself.

[0141] The readable storage medium provided in this application is a computer-readable storage medium that stores computer-readable program instructions (i.e., computer programs) for executing the above-described program modularization method. This solves the technical problem in the prior art where implementing Go language program modularization through the Go plugin mechanism requires the program to be compiled with specific parameters, resulting in low program independence and flexibility. Compared with the prior art, the beneficial effects of the computer-readable storage medium provided in this application are the same as those of the program modularization method provided in the above embodiments, and will not be repeated here.

[0142] This application also provides a computer program product, including a computer program that, when executed by a processor, implements the steps of the program modularization method described above.

[0143] The computer program product provided in this application solves the technical problem in the prior art where the modularization of Go language programs through the Go plugin mechanism requires the program to be compiled with specific parameters, resulting in low program independence and flexibility. Compared with the prior art, the beneficial effects of the computer program product provided in this application are the same as those of the program modularization method provided in the above embodiments, and will not be repeated here.

[0144] The above description is only a part of the embodiments of this application and does not limit the patent scope of this application. All equivalent structural transformations made under the technical concept of this application and using the contents of the specification and drawings of this application, or direct / indirect applications in other related technical fields, are included in the patent protection scope of this application.

[0145] This invention discloses A1, a program modularization method, the method comprising:

[0146] Generate a dynamic library based on the Go code to be modularized and the corresponding programming language type of the Go code to be modularized;

[0147] Determine whether there exists a function name in the global logic function table of the code dynamic library that has the same name as the target function name corresponding to the logic function to be executed;

[0148] If it exists, then determine the target's internal logic function based on the target function name;

[0149] Call and execute the target programming language type corresponding to the target internal logic function in the dynamic code library.

[0150] A2. As described in A1, before the step of determining whether there is a function name with the same name as the target function name corresponding to the logic function to be executed in the global logic function table of the code dynamic library, the method further includes:

[0151] The dynamic library is initialized using the initialization interface corresponding to the dynamic library.

[0152] Upon completion of initialization, a global logic function table is constructed using the logic function table acquisition interface corresponding to the dynamic code library.

[0153] A3. As described in A2, the step of constructing a global logical function table through the interface for obtaining the logical function table corresponding to the code dynamic library upon completion of initialization includes:

[0154] Upon completion of initialization, obtain the names of all logical functions and the addresses of their internal logic functions in the dynamic library.

[0155] Based on the logical function name and the internal logical function address, a global logical function table is constructed through the logical function table acquisition interface corresponding to the code dynamic library.

[0156] A4. As described in A2, the step of initializing the code dynamic library through the initialization interface corresponding to the code dynamic library includes:

[0157] Determine the initialization task of the code dynamic library, wherein the initialization task includes at least one of allocating memory, opening a file, and creating a synchronization primitive;

[0158] The dynamic code library is initialized based on the initialization interface and the initialization task corresponding to the dynamic code library.

[0159] A5. As described in A4, the step of initializing the code dynamic library based on the initialization interface corresponding to the code dynamic library and the initialization task includes:

[0160] If the initialization task is to allocate memory, then determine the memory usage of all logical function tables in the code dynamic library;

[0161] Based on the memory usage, memory is allocated to the logical function table through the initialization interface corresponding to the code dynamic library.

[0162] A6. As described in A5, the step of allocating memory for the logical function table based on the memory footprint through the initialization interface corresponding to the code dynamic library includes:

[0163] The partition information of the code dynamic library is generated based on the memory partitioning rules and the memory usage size;

[0164] Based on the partition information, determine the memory region of the logical function table in the dynamic code library and the region ratio of the memory region;

[0165] Based on the memory region and the region ratio, memory is allocated to the logical function table through the initialization interface corresponding to the code dynamic library.

[0166] A7. As described in A1, the step of determining the target internal logic function based on the target function name includes:

[0167] The address of the target internal logic function is determined from the global logic function table based on the target function name;

[0168] Determine the target internal logic function corresponding to the address of the target internal logic function.

[0169] A8. The method as described in any one of A1 to A7, after the step of calling and executing the target programming language type corresponding to the target internal logic function in the code dynamic library, further includes:

[0170] Determine the deinitialization task to be executed corresponding to the code dynamic library, wherein the deinitialization task to be executed includes at least one of releasing memory, closing files, and destroying synchronization primitives;

[0171] Based on the deinitialization task to be executed, the code dynamic library is deinitialized through the deinitialization interface corresponding to the code dynamic library.

[0172] A9. The method described in A8, wherein the step of deinitializing the code dynamic library based on the deinitialization task to be executed by using the deinitialization interface corresponding to the code dynamic library includes:

[0173] If the uninitialization task to be executed is to release memory, then the memory release function is called, and the memory address and size to be released are determined based on the release parameters in the memory release function.

[0174] Based on the memory address to be released, determine the table of logic functions to be released in the code dynamic library;

[0175] Based on the size of the memory to be released and the table of logic functions to be released, the memory of the dynamic library is released by using the deinitialization interface corresponding to the dynamic library.

[0176] The present invention also discloses B10, a program modularization device, the device comprising:

[0177] The dynamic library generation module is used to generate a dynamic library based on the Go code to be modularized and the programming language type corresponding to the Go code to be modularized.

[0178] The function query module is used to determine whether there is a function name in the global logic function table of the code dynamic library that is the same as the target function name corresponding to the logic function to be executed;

[0179] A function determination module is used to determine the target's internal logic function based on the target function name if the function exists.

[0180] The function execution module is used to call and execute the target programming language type corresponding to the target internal logic function in the code dynamic library.

[0181] B11. The apparatus as described in B10, further comprising:

[0182] The function table construction module is used to initialize the code dynamic library through the initialization interface corresponding to the code dynamic library; when the initialization is completed, it constructs a global logical function table through the logical function table acquisition interface corresponding to the code dynamic library.

[0183] B12. In the apparatus described in B11, the function table construction module is further configured to, upon completion of initialization, obtain the names of all logical functions and the addresses of their internal logical functions in the code dynamic library; and, based on the names of the logical functions and the addresses of their internal logical functions, construct a global logical function table through the interface for obtaining the logical function table corresponding to the code dynamic library.

[0184] B13. The apparatus as described in B11, wherein the function table construction module is further configured to determine the initialization task of the code dynamic library, the initialization task including at least one of allocating memory, opening a file, and creating a synchronization primitive; and to initialize the code dynamic library based on the initialization interface corresponding to the code dynamic library and the initialization task.

[0185] B14. In the apparatus described in B13, the function table construction module is further configured to, if the initialization task is to allocate memory, determine the memory footprint of all logical function tables in the code dynamic library; and, based on the memory footprint, allocate memory for the logical function tables through the initialization interface corresponding to the code dynamic library.

[0186] B15. In the apparatus described in B14, the function table construction module is further configured to generate partition information of the code dynamic library based on memory partitioning rules and the memory usage size; determine the memory region of the logical function table in the code dynamic library and the region ratio of the memory region according to the partition information; and allocate memory for the logical function table through the initialization interface corresponding to the code dynamic library based on the memory region and the region ratio.

[0187] B16. The apparatus as described in B10, wherein the function determination module is further configured to determine the address of a target internal logic function from the global logic function table based on the target function name; and determine the target internal logic function corresponding to the address of the target internal logic function.

[0188] B17. The apparatus of any one of B10 to B16, wherein the apparatus further comprises:

[0189] The deinitialization module is used to determine the deinitialization task to be executed for the code dynamic library, wherein the deinitialization task to be executed includes at least one of releasing memory, closing files, and destroying synchronization primitives; based on the deinitialization task to be executed, the code dynamic library is deinitialized by the deinitialization interface corresponding to the code dynamic library.

[0190] The present invention also discloses C18, a program modularization device, the device comprising: a memory, a processor, and a program modularization program stored in the memory and executable on the processor, the program modularization program being configured to implement the steps of the program modularization method as described above.

[0191] The present invention also discloses D19, a storage medium storing a program modularization program, which, when executed by a processor, implements the steps of the program modularization method described above.

[0192] The present invention also discloses E20, a computer program product comprising a computer program, wherein the computer program, when executed by a processor, implements the steps of the program modularization method described above.

Claims

1. A program modularization method, characterized in that, The method includes: Generate a dynamic library based on the Go code to be modularized and the corresponding programming language type of the Go code to be modularized; Determine whether there exists a function name in the global logic function table of the code dynamic library that has the same name as the target function name corresponding to the logic function to be executed; If it exists, then determine the target's internal logic function based on the target function name; Call and execute the target programming language type corresponding to the target internal logic function in the dynamic code library.

2. The method as described in claim 1, characterized in that, Before the step of determining whether there exists a function name in the global logic function table of the code dynamic library that has the same name as the target function name corresponding to the logic function to be executed, the method further includes: The dynamic library is initialized using the initialization interface corresponding to the dynamic library. Upon completion of initialization, a global logic function table is constructed using the logic function table acquisition interface corresponding to the dynamic code library.

3. The method as described in claim 2, characterized in that, The step of constructing a global logic function table through the logic function table acquisition interface corresponding to the code dynamic library upon initialization includes: Upon completion of initialization, obtain the names of all logical functions and the addresses of their internal logic functions in the dynamic library. Based on the logical function name and the internal logical function address, a global logical function table is constructed through the logical function table acquisition interface corresponding to the code dynamic library.

4. The method as described in claim 2, characterized in that, The step of initializing the code dynamic library through the initialization interface corresponding to the code dynamic library includes: Determine the initialization task of the code dynamic library, wherein the initialization task includes at least one of allocating memory, opening a file, and creating a synchronization primitive; The dynamic code library is initialized based on the initialization interface and the initialization task corresponding to the dynamic code library.

5. The method according to any one of claims 1 to 4, characterized in that, After the step of calling and executing the target programming language type corresponding to the target internal logic function in the code dynamic library, the method further includes: Determine the deinitialization task to be executed corresponding to the code dynamic library, wherein the deinitialization task to be executed includes at least one of releasing memory, closing files, and destroying synchronization primitives; Based on the deinitialization task to be executed, the code dynamic library is deinitialized through the deinitialization interface corresponding to the code dynamic library.

6. The method as described in claim 5, characterized in that, The step of deinitializing the code dynamic library based on the deinitialization task to be executed by using the deinitialization interface corresponding to the code dynamic library includes: If the uninitialization task to be executed is to release memory, then the memory release function is called, and the memory address and size to be released are determined based on the release parameters in the memory release function. Based on the memory address to be released, determine the table of logic functions to be released in the code dynamic library; Based on the size of the memory to be released and the table of logic functions to be released, the memory of the dynamic library is released by using the deinitialization interface corresponding to the dynamic library.

7. A modular programmable device, characterized in that, The device includes: The dynamic library generation module is used to generate a dynamic library based on the Go code to be modularized and the programming language type corresponding to the Go code to be modularized. The function query module is used to determine whether there is a function name in the global logic function table of the code dynamic library that is the same as the target function name corresponding to the logic function to be executed; A function determination module is used to determine the target's internal logic function based on the target function name if the function exists. The function execution module is used to call and execute the target programming language type corresponding to the target internal logic function in the code dynamic library.

8. A modular programmable device, characterized in that, The device includes: a memory, a processor, and a computer program stored in the memory and executable on the processor, the computer program being configured to implement the steps of the program modularization method as described in any one of claims 1 to 6.

9. A storage medium, characterized in that, The storage medium is a computer-readable storage medium, and a computer program is stored on the storage medium. When the computer program is executed by a processor, it implements the steps of the program modularization method as described in any one of claims 1 to 6.

10. A computer program product, characterized in that, The computer program product includes a computer program that, when executed by a processor, implements the steps of the program modularization method as described in any one of claims 1 to 6.