Function calling method and device, electronic equipment and storage medium
Patent Information
- Application Number
- CN202111447422.X
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2021-11-30
- Publication Date
- 2026-09-22
- Estimated Expiration
- 2041-11-30
AI Technical Summary
[0005]为克服相关技术中存在的问题,本公开提供一种函数调用方法、装置、电子设备及存储介质,以至少解决相关技术中程序的代码的维护成本高的问题
[0042]利用预设框架函数调用以第二函数的第二返回值作为实参的第一函数,以得到第一函数的第一返回值。无需在程序中的每一个需要调用第一函数的位置,编写用于调用第二函数的语句、用于将第二函数的第二返回值提供给第一函数的语句、用于调用第一函数的语句,降低程序的代码的开发成本。在出现第一函数的名称发生改变、第二的名称发生改变、第一函数的形参的类型发生改变、第二函数的形参的类型发生改变等情况时,无需在每一个需要调用第一函数的位置,修改用于调用第二函数的语句、用于将第二函数的第二返回值提供给第一函数的语句、用于调用第一函数的语句,降低程序的代码的维护成本。
Smart Images

Figure CN116204185B_ABST
Abstract
Description
Technical Field
[0001] This disclosure relates to the Internet field, and in particular to function calling methods, devices, electronic devices, and storage media. Background Technology
[0002] When developing programs using computer languages such as C++, some modules often need to call functions that take the return value of other functions as arguments.
[0003] In related technologies, at every point in a program where a function that takes the return value of another function as an argument needs to be called, statements for calling the other function, statements for providing the return value of the other function to the function that takes the return value of the other function as an argument, and statements for calling the function that takes the return value of the other function as an argument need to be written.
[0004] If situations arise during code maintenance, such as changes to the name of a function that takes the return value of another function as an argument, changes to the name of another function, changes to the type of the formal parameter of a function that takes the return value of another function as an argument, or changes to the type of the formal parameter of another function, it is necessary to modify the statements used to call the other function, the statements used to provide the return value of the other function to the function that takes the return value of another function as an argument, and the statements used to call the function that takes the return value of another function as an argument at every location where the function that takes the return value of another function as an argument needs to be called, resulting in high maintenance costs for the program code. Summary of the Invention
[0005] To overcome the problems existing in related technologies, this disclosure provides a function call method, apparatus, electronic device, and storage medium to at least solve the problem of high maintenance costs of program code in related technologies. The technical solution of this disclosure is as follows:
[0006] According to a first aspect of the present disclosure, a function call method is provided, comprising:
[0007] The system receives input parameters for a preset framework function sent by the client. The input parameters include: the identifier of the first function, the identifier of the second function, and the sequence of actual parameters of the second function.
[0008] Based on the input parameters, a preset framework function is invoked to obtain the first return value of the first function, and the first return value is returned to the client. When the preset framework function is invoked, it is used for:
[0009] The first function is determined from the function library based on its identifier;
[0010] The second function is determined from the function library based on the identifier of the second function, and the second function is called based on the actual parameter sequence to obtain the second return value sequence of the second function;
[0011] Based on the second return value sequence, the first function is called to obtain the first return value of the first function.
[0012] In some embodiments, calling the second function based on the sequence of actual parameters includes:
[0013] If the argument sequence satisfies the first calling condition, the second function is called based on the argument sequence to obtain the second return value sequence of the second function; wherein, the first calling condition is that for each argument in the argument sequence, the type of the argument is the same as the type of the formal parameter of the second function corresponding to the argument;
[0014] as well as,
[0015] Based on the second return value sequence, calling the first function yields the following first return value:
[0016] If the second return value sequence satisfies the second calling condition, the first function is called based on the second return value sequence to obtain the first return value of the first function; wherein, the second calling condition is that for each second return value in the second return value sequence, the type of the second return value is the same as the type of the parameter corresponding to the second return value in the parameter type sequence of the first function.
[0017] In some embodiments, calling the first function based on the second return value sequence to obtain the first return value of the first function includes:
[0018] Generate a data structure that includes the second return value sequence;
[0019] Call the preset parameter passing function, and through the preset parameter passing function, traverse each second return value in the data structure, and pass the traversed second return value to the formal parameter corresponding to the first function;
[0020] Call the first function and obtain the first return value of the first function.
[0021] In some embodiments, the method further includes:
[0022] If the argument sequence does not meet the first calling condition, the problematic argument in the argument sequence is returned to the client.
[0023] In some embodiments, the method further includes:
[0024] If the second return value sequence does not meet the second calling condition, the second return value of the second return value sequence is returned to the client.
[0025] According to a second aspect of the present disclosure, a function calling apparatus is provided, comprising:
[0026] The receiving module is configured to receive input parameters of a preset framework function sent by the client. The input parameters include: the identifier of the first function, the identifier of the second function, and the sequence of actual parameters of the second function.
[0027] The calling module is configured to, based on the input parameters, call a preset framework function to obtain a first return value of the first function, and return the first return value to the client. When the preset framework function is called, it is used to: determine a first function from a function library based on the identifier of the first function; determine a second function from a function library based on the identifier of the second function, and call the second function based on the actual parameter sequence to obtain a second return value sequence of the second function; and call the first function based on the second return value sequence to obtain a first return value of the first function.
[0028] In some embodiments, the calling module is further configured to, when the argument sequence satisfies a first calling condition, call the second function based on the argument sequence to obtain a second return value sequence of the second function; wherein, the first calling condition is that for each argument in the argument sequence, the type of the argument is the same as the type of the formal parameter of the second function corresponding to the argument; and when the second return value sequence satisfies a second calling condition, call the first function based on the second return value sequence to obtain a first return value of the first function; wherein, the second calling condition is that for each second return value in the second return value sequence, the type of the second return value is the same as the type of the formal parameter in the parameter type sequence of the first function corresponding to the second return value.
[0029] In some embodiments, the calling module is further configured to generate a data structure including the second return value sequence;
[0030] Generate a data structure including the second return value sequence; call a preset parameter passing function, traverse each second return value in the data structure through the preset parameter passing function, and pass the traversed second return value to the formal parameter corresponding to the first function; call the first function to obtain the first return value of the first function.
[0031] In some embodiments, the apparatus further includes:
[0032] The first feedback module is configured to return the problematic actual parameter in the actual parameter sequence to the client if the actual parameter sequence does not meet the first calling condition.
[0033] In some embodiments, the apparatus further includes:
[0034] The second feedback module is configured to return a second return value from the second return value sequence to the client if the second return value sequence does not meet the second calling condition.
[0035] According to a third aspect of the present disclosure, an electronic device is provided, characterized in that it includes:
[0036] processor;
[0037] Memory used to store the processor's executable instructions;
[0038] The processor is configured to execute the instructions to implement the above function call method.
[0039] According to a fourth aspect of the present disclosure, a computer-readable storage medium is provided that, when instructions in the computer-readable storage medium are executed by a processor of an electronic device, enables the electronic device to perform the above-described function call method.
[0040] According to a fifth aspect of the present disclosure, a computer program product is provided, including computer-readable code that, when run on an electronic device, causes the electronic device to execute the above-described function call method.
[0041] The technical solutions provided by the embodiments of this disclosure may include the following beneficial effects:
[0042] This method utilizes a pre-defined function call framework to take the second return value of the second function as an argument to the first function, thus obtaining the first return value of the first function. This eliminates the need to write statements to call the second function, provide the second return value of the second function to the first function, and call the first function at every point in the program where the first function needs to be called, reducing the program's code development cost. Furthermore, it eliminates the need to modify statements to call the second function, provide the second return value of the second function to the first function, and call the first function at every point where the first function needs to be called, reducing the program's code maintenance cost. Attached Figure Description
[0043] The accompanying drawings, which are incorporated in and form a part of this specification, illustrate embodiments consistent with this disclosure and, together with the description, serve to explain the principles of this disclosure.
[0044] Figure 1 This is a schematic diagram illustrating an application scenario of the function call method provided in this publication;
[0045] Figure 2 This is a flowchart illustrating one embodiment of a function call method according to an exemplary embodiment;
[0046] Figure 3 This is a structural block diagram illustrating a function call apparatus according to an exemplary embodiment;
[0047] Figure 4 This is a structural block diagram of an electronic device according to an exemplary embodiment. Detailed Implementation
[0048] To enable those skilled in the art to better understand the technical solutions of this disclosure, the technical solutions in the embodiments of this disclosure will be clearly and completely described below with reference to the accompanying drawings.
[0049] It should be noted that the terms "first," "second," etc., used in the specification, claims, and accompanying drawings of this disclosure are used to distinguish similar objects and are not necessarily used to describe a specific order or sequence. It should be understood that such data can be interchanged where appropriate so that the embodiments of this disclosure described herein can be implemented in orders other than those illustrated or described herein. The embodiments described in the following exemplary embodiments do not represent all embodiments consistent with this disclosure. Rather, they are merely examples of apparatuses and methods consistent with some aspects of this disclosure as detailed in the appended claims.
[0050] Please refer to Figure 1 This diagram illustrates an application scenario of the function call method provided in this disclosure.
[0051] exist Figure 1 The diagram illustrates a client and an electronic device. The client can be a module in a program developed using a computer language such as C++, and the electronic device's memory stores preset framework functions. When the client needs the first return value of the first function, it sends the input parameters of the preset framework function to the electronic device. Based on the input parameters, the electronic device calls the preset framework function, obtains the first return value, and then returns the first return value to the client.
[0052] Figure 2This is a flowchart illustrating one embodiment of a function call method according to an exemplary embodiment. The method includes the following steps:
[0053] Step 201: Receive the input parameters of the preset framework function sent by the client.
[0054] In this disclosure, the first function takes the second return value of the second function as an argument. For example, the first function is a C function or a C++ function in a third-party library that takes the second return value of the second function as an argument. The client can refer to a module in a program developed using a computer language such as C++. When the client needs to call the first function to obtain the first return value of the first function, the client sends the input parameters of a preset framework function.
[0055] In this disclosure, the code for a pre-written pre-defined framework function is stored in advance on an electronic device used to execute the function call method provided in this disclosure. The function call method provided in this disclosure can be executed by a process running on the electronic device, and the process running on the electronic device can receive the argument sequence of the pre-defined framework function. The pre-defined framework function is a function used to obtain the first return value of a first function. The pre-defined framework function includes code for operations to obtain the first return value of the first function. When the pre-defined framework function is called, the code for the pre-defined framework function is executed, the code for obtaining the first return value of the first function is executed, and the operations for obtaining the first return value of the first function are executed. The code for operations to obtain the first return value of the first function consists of statements for each step involved in the operations to obtain the first return value of the first function. The developer inputs the function definition statement, including the function name and variables representing input parameters, and the statements for each step involved in the operations to obtain the first return value of the first function, into the corresponding window of the development framework. Then, all the input statements are compiled to obtain the code for the pre-defined framework function.
[0056] In this disclosure, when the client needs to call the first function to obtain the first return value of the first function, it can receive the input parameters of the preset framework function sent by the client.
[0057] In this application, the input parameters of the preset framework function include: an identifier of the first function, an identifier of the second function, and a sequence of actual parameters of the second function. The sequence of actual parameters of the second function includes each actual parameter of the second function.
[0058] Step 202: Based on the input parameters of the preset framework function, call the preset framework function to obtain the first return value of the first function, and return the first return value of the first function to the client.
[0059] In this disclosure, after receiving the input parameters of the preset framework function sent by the client, the preset framework function can be called based on the input parameters of the preset framework function.
[0060] In this disclosure, when the preset framework function is called, it is used to: determine a first function from a function library based on the identifier of a first function; determine a second function from the function library based on the identifier of a second function, and call the second function based on the argument sequence of the second function to obtain a second return value sequence of the second function; and call the first function based on the second return value sequence of the second function to obtain a first return value of the first function. Each function in the function library has a unique identifier. The first function can be determined from the function library based on its identifier, and the second function can be determined from the function library based on its identifier.
[0061] When calling the second function based on its argument sequence, for each actual argument in the argument sequence, a variable corresponding to that actual argument can be created, and its value can be set to that actual argument. A function for parameter passing can be pre-written. After setting the variable corresponding to each actual argument to its corresponding parameter, the parameter passing function can be called. This function passes the variable corresponding to each actual argument to the corresponding formal parameter in the second function. After passing the variable corresponding to each actual argument to the corresponding formal parameter in the second function, the second function can be called. When the second function completes execution, each of its second return values can be obtained, and these second return values constitute the second return value sequence of the second function.
[0062] When calling the first function based on the second return value sequence of the second function, for each second return value in the second return value sequence, a variable corresponding to that second return value can be created, and the value of the variable corresponding to that second return value can be set to that return value. After setting the value of the variable corresponding to each second return value, the variable corresponding to each second return value can be used as input data for a pre-written function for parameter passing. The pre-written function for parameter passing is then called, and for each second return value in the second return value sequence, the variable corresponding to that second return value is passed to the formal parameter in the first function corresponding to that second return value. For each second return value in the second return value sequence of the second function, the formal parameter in the first function corresponding to that second return value is the parameter whose position is the same as that of the second return value in the second return value sequence. For example, for the first second return value in the second return value sequence of the second function, the parameter in the first function corresponding to that second return value is the first parameter in the first function; similarly, for the second second return value in the second return value sequence of the second function, the parameter in the first function corresponding to that second return value is the second parameter in the first function. After passing the variable corresponding to each second return value to the corresponding parameter in the first function, the first function can be called. When the first function completes execution, the first return value of the first function can be obtained.
[0063] In this disclosure, a pre-defined framework function is used to call a first function with the second return value of a second function as an actual parameter to obtain the first return value of the first function. This eliminates the need to write statements for calling the second function, providing the second return value of the second function to the first function, and calling the first function at every point in the program where the first function needs to be called, thus reducing the program's code development cost. Furthermore, when the name of the first function changes, the name of the second function changes, the types of the parameters of the first function change, or the types of the parameters of the second function change, it is not necessary to modify the statements for calling the second function, providing the second return value of the second function to the first function, and calling the first function at every point where the first function needs to be called, thus reducing the program's code maintenance cost.
[0064] In some embodiments, calling a second function based on an argument sequence includes: if the argument sequence satisfies a first calling condition, calling the second function based on the argument sequence to obtain a second return value sequence of the second function, wherein the first calling condition is that for each argument in the argument sequence, the type of the argument is the same as the type of the formal parameter of the second function corresponding to the argument; and calling a first function based on the second return value sequence to obtain a first return value of the first function includes: if the second return value sequence satisfies a second calling condition, calling the first function based on the second return value sequence to obtain a first return value of the first function, wherein the second calling condition is that for each second return value in the second return value sequence, the type of the second return value is the same as the type of the formal parameter in the parameter type sequence of the first function corresponding to the second return value.
[0065] In this disclosure, the parameter type sequence of the first function includes the parameter type of each parameter of the first function. For example, if the number of parameters of the first function is N, all parameters of the first function include: the 1st parameter, the 2nd parameter, ..., the Nth parameter. The parameter type sequence of the first function includes: the parameter type of the 1st parameter, the parameter type of the 2nd parameter, ..., the parameter type of the Nth parameter.
[0066] In this disclosure, for each actual parameter in the argument sequence of the second function, the formal parameter of the second function corresponding to that actual parameter is the formal parameter among all the formal parameters of the second function whose position is the same as that actual parameter in the argument sequence of the second function.
[0067] For example, the second function has N actual parameters and N formal parameters. For the first actual parameter in the second function's parameter sequence, the formal parameter corresponding to the first actual parameter is the first formal parameter of the second function. For the second actual parameter in the second function's parameter sequence, the formal parameter corresponding to the second actual parameter is the second formal parameter of the second function. For the Nth actual parameter in the second function's parameter sequence, the formal parameter corresponding to the Nth actual parameter is the Nth formal parameter of the second function.
[0068] In this disclosure, for each second return value in the second return value sequence of the second function, the parameter type in the parameter type sequence of the first function corresponding to the second return value is the same parameter type as the second return value in the second return value sequence.
[0069] For example, the second return value sequence of the second function includes N second return values, the first function has N formal parameters, and the parameter type sequence of the first function includes the parameter type of the first formal parameter, the parameter type of the second formal parameter, ..., the parameter type of the Nth formal parameter of the first function, and so on. For the first second return value in the second return value sequence of the second function, the parameter type corresponding to that first second return value in the parameter type sequence of the first function is the parameter type of the first formal parameter of the first function. For the second second return value in the second return value sequence of the second function, the parameter type corresponding to that second second return value in the parameter type sequence of the first function is the parameter type of the second formal parameter of the first function. For the Nth second return value in the second return value sequence of the second function, the parameter type corresponding to that Nth second return value in the parameter type sequence of the first function is the parameter type of the Nth formal parameter of the first function.
[0070] In this disclosure, the parameter sequence of the second function satisfies the first calling condition, ensuring that the type of each actual parameter in the parameter sequence of the second function is the same as the type of the corresponding formal parameter of the second function. When the parameter sequence of the second function satisfies the first calling condition, calling the second function based on the parameter sequence avoids the situation where the call to the second function fails due to a difference in type between an actual parameter and a corresponding formal parameter, thus avoiding waste of resources consumed in calling the second function. Similarly, the second return value sequence of the second function satisfies the second calling condition, ensuring that each second return value in the second return value sequence is the same as the type of the corresponding formal parameter in the parameter type sequence of the first function. When the second return value sequence of the second function satisfies the second calling condition, calling the first function based on the second return value sequence avoids the situation where the call to the first function fails due to a difference in type between a second return value and a corresponding formal parameter in the parameter type sequence, thus avoiding waste of resources consumed in calling the first function.
[0071] In some embodiments, calling a first function based on a second return value sequence of a second function to obtain a first return value of the first function includes: generating a data structure including a second return value sequence of the second function; calling a preset parameter passing function, traversing each second return value in the data structure including the second return value sequence of the second function through the preset parameter passing function, and passing the traversed second return value to the corresponding formal parameter of the first function; and calling the first function to obtain the first return value of the first function.
[0072] The data structure can be a `std:tuple` structure in C++. The default parameter passing function can be a `std:apply` function in C++. When generating a `std:tuple` structure including a second return value sequence, the second return value sequence can be used as the input parameter to the function provided by the C++ development framework for generating `std:tuple` structures. Calling the function generates the `std:tuple` structure, thus generating the `std:tuple` structure including the second return value sequence.
[0073] The `std:apply` function can iterate through each second return value in a `std:tuple` structure containing a sequence of second return values. Each iterated second return value is passed to the corresponding parameter of the first function, which can be a parameter of the first function corresponding to the iterated second return value. Calling the first function returns its first return value. The order of the second return values in the `std:tuple` structure matches the order of the second return values in the sequence. The parameter of the first function corresponding to the iterated second return value is the parameter whose position is the same as that of the iterated second return value in the `std:tuple` structure. For example, if the sequence of second return values of the second function includes N second return values, the generated `std:tuple` structure will also include N second return values. The process can be repeated until the first, second, ..., Nth second return value is reached. The first second return value is passed to the first function's parameter corresponding to the first second return value, i.e., the first parameter; the second second return value is passed to the first function's parameter corresponding to the second second return value, i.e., the second parameter; and the Nth second return value is passed to the first function's parameter corresponding to the Nth second return value, i.e., the Nth parameter.
[0074] After passing each of the second return values in the std:tuple structure, which includes the second return value sequence, to the corresponding formal parameter of the first function, the first function can be called to obtain the first return value of the first function.
[0075] In this disclosure, the first function can be called by calling the preset parameter passing function, namely the std:apply function, and the first return value of the first function can be obtained. The std:apply function can automatically pass each second return value in the data structure to the corresponding formal parameter in the first function to call the first function, without creating a variable corresponding to each second return value, and without writing a function for parameter passing, thus improving the convenience of calling the first function.
[0076] In some embodiments, the method further includes: if the argument sequence of the second function does not satisfy the first calling condition, returning the problematic argument from the argument sequence of the second function to the client.
[0077] In this disclosure, for each actual parameter in the argument sequence of the second function, the corresponding formal parameter in the second function is the formal parameter whose position is the same as that of the actual parameter in the argument sequence of the second function. For each actual parameter in the argument sequence of the second function, if the type of the actual parameter is different from the type of the corresponding formal parameter in the second function, then the actual parameter is a problem parameter.
[0078] For example, for the first actual parameter in the argument sequence of the second function, the formal parameter corresponding to that actual parameter of the second function is the first formal parameter among all the formal parameters of the second function. If the type of the first actual parameter in the argument sequence of the second function is different from the type of the first formal parameter of the second function, then the first actual parameter in the argument sequence of the second function is a problem argument.
[0079] In this disclosure, if a problematic argument causes the argument sequence of the second function to fail to meet the first calling condition, the problematic argument in the argument sequence of the second function can be returned to the client. The client can then show the problematic argument in the argument sequence of the second function to a user, such as an engineer developing a program using the C++ language, so that the user can know which argument caused the first calling condition to be failed and the second function cannot be called.
[0080] In some embodiments, the method further includes: if the second return value sequence of the second function does not satisfy the second calling condition, returning a problem second return value from the second return value sequence of the second function to the client.
[0081] In this disclosure, for each second return value in the second return value sequence of the second function, the parameter type corresponding to that return value in the parameter type sequence of the first function is the same parameter type as the return value in the second return value sequence. For a second return value in the second return value sequence of the second function, if the type of the second return value is different from the parameter type corresponding to that second return value, then the second return value is a problem second return value.
[0082] For example, for the first second return value in the second return value sequence of the second function, the parameter type corresponding to the first second return value in the parameter type sequence of the first function is the first parameter type in the parameter type sequence of the first function. If the type of the first second return value in the second return value sequence of the second function is different from the first parameter type in the parameter type sequence of the first function, then the first second return value in the second return value sequence of the second function is a second return value of a problem.
[0083] In this disclosure, if a problematic second return value causes the second return value sequence of the second function to fail to meet the second calling condition, the problematic second return value from the second return value sequence of the second function can be returned to the client. The client can display the problematic second return value from the second return value sequence to a user, such as an engineer developing a program using the C++ language, thereby allowing the user to know which second return value in the second return value sequence of the second function caused the second calling condition to be failed and the first function could not be called.
[0084] Figure 3 This is a structural block diagram illustrating a function call apparatus according to an exemplary embodiment. (Refer to...) Figure 3 The device includes: a receiving module 301 and a calling module 302.
[0085] The receiving module 301 is configured to receive input parameters of a preset framework function sent by the client. The input parameters include: the identifier of the first function, the identifier of the second function, and the sequence of actual parameters of the second function.
[0086] The calling module 302 is configured to call a preset framework function based on the input parameters, obtain a first return value of the first function, and return the first return value to the client. When the preset framework function is called, it is used to: determine a first function from the function library based on the identifier of the first function; determine a second function from the function library based on the identifier of the second function, and call the first function based on the second return value sequence to obtain the first return value of the first function.
[0087] In some embodiments, the calling module 302 is further configured to, when the argument sequence satisfies a first calling condition, call the second function based on the argument sequence to obtain a second return value sequence of the second function; wherein, the first calling condition is that for each argument in the argument sequence, the type of the argument is the same as the type of the formal parameter of the second function corresponding to the argument; and when the second return value sequence satisfies a second calling condition, call the first function based on the second return value sequence to obtain a first return value of the first function; wherein, the second calling condition is that for each second return value in the second return value sequence, the type of the second return value is the same as the type of the formal parameter in the parameter type sequence of the first function corresponding to the second return value.
[0088] In some embodiments, the calling module 302 is further configured to generate a data structure including the second return value sequence;
[0089] Generate a data structure including the second return value sequence; call a preset parameter passing function, traverse each second return value in the data structure through the preset parameter passing function, and pass the traversed second return value to the formal parameter corresponding to the first function; call the first function to obtain the first return value of the first function.
[0090] In some embodiments, the apparatus further includes:
[0091] The first feedback module is configured to return the problematic actual parameter in the actual parameter sequence to the client if the actual parameter sequence does not meet the first calling condition.
[0092] In some embodiments, the apparatus further includes:
[0093] The second feedback module is configured to return a second return value from the second return value sequence to the client if the second return value sequence does not meet the second calling condition.
[0094] Regarding the apparatus in the above embodiments, the specific manner in which each module performs its operation has been described in detail in the embodiments related to the method, and will not be elaborated upon here.
[0095] Figure 4 This is a structural block diagram of an electronic device according to an exemplary embodiment. (Refer to...) Figure 4 The electronic device includes a processing component 422, which further includes one or more processors, and memory resources represented by memory 432 for storing instructions executable by the processing component 422, such as application programs. The application programs stored in memory 432 may include one or more modules, each corresponding to a set of instructions. Furthermore, the processing component 422 is configured to execute instructions to perform the aforementioned function call method.
[0096] The electronic device may also include a power supply component 426 configured to perform power management of the electronic device, a wired or wireless network interface 450 configured to connect the electronic device to a network, and an input / output (I / O) interface 458. The electronic device may operate on an operating system stored in memory 432, such as Windows Server™, MacOS X™, Unix™, Linux™, FreeBSD™, or similar.
[0097] In an exemplary embodiment, a computer-readable storage medium including instructions is also provided, such as a memory including instructions that can be executed by an electronic device to perform a function call method. Optionally, the computer-readable storage medium may be a ROM, random access memory (RAM), CD-ROM, magnetic tape, floppy disk, and optical data storage device, etc.
[0098] In an exemplary embodiment, this application also provides a computer program product including computer-readable code that, when executed on an electronic device, causes the electronic device to execute a function call method.
[0099] Other embodiments of the invention will readily occur to those skilled in the art upon consideration of the specification and practice of the invention disclosed herein. This application is intended to cover any variations, uses, or adaptations of the invention that follow the general principles of the invention and include common knowledge or customary techniques in the art not disclosed herein. The specification and examples are to be considered exemplary only, and the true scope and spirit of the invention are indicated by the following claims.
[0100] It should be understood that this disclosure is not limited to the precise structures described above and shown in the accompanying drawings, and various modifications and changes can be made without departing from its scope. The scope of the invention is limited only by the appended claims.
Claims
1. A function call method, characterized in that, The method includes: The system receives input parameters for a preset framework function sent by the client. The input parameters include: the identifier of the first function, the identifier of the second function, and the sequence of actual parameters of the second function. Based on the input parameters, a preset framework function is called to obtain the first return value of the first function, and the first return value is returned to the client. When the preset framework function is called, it is used for: The first function is determined from the function library based on its identifier; The second function is determined from the function library based on the identifier of the second function, and the second function is called based on the actual parameter sequence if the actual parameter sequence satisfies the first calling condition, thereby obtaining the second return value sequence of the second function; wherein, the first calling condition is that for each actual parameter in the actual parameter sequence, the type of the actual parameter is the same as the type of the formal parameter of the second function corresponding to the actual parameter; If the second return value sequence satisfies the second calling condition, the first function is called based on the second return value sequence to obtain the first return value of the first function; wherein, the second calling condition is that for each second return value in the second return value sequence, the type of the second return value is the same as the type of the parameter corresponding to the second return value in the parameter type sequence of the first function.
2. The method according to claim 1, characterized in that, Based on the second return value sequence, calling the first function yields the following first return value: Generate a data structure that includes the second return value sequence; Call the preset parameter passing function, and through the preset parameter passing function, traverse each second return value in the data structure, and pass the traversed second return value to the formal parameter corresponding to the first function; Call the first function and obtain the first return value of the first function.
3. The method according to claim 2, characterized in that, The method further includes: If the argument sequence does not meet the first calling condition, the problematic argument in the argument sequence is returned to the client.
4. The method according to claim 2, characterized in that, The method further includes: If the second return value sequence does not meet the second calling condition, the second return value of the second return value sequence is returned to the client.
5. A function call device, characterized in that, The device includes: The receiving module is configured to receive input parameters of a preset framework function sent by the client. The input parameters include: the identifier of the first function, the identifier of the second function, and the sequence of actual parameters of the second function. The calling module is configured to, based on the input parameters, invoke a preset framework function to obtain a first return value of the first function, and return the first return value to the client. When the preset framework function is invoked, it is used to: determine a first function from a function library based on the identifier of the first function; determine a second function from a function library based on the identifier of a second function, and, if the actual parameter sequence satisfies a first calling condition, invoke the second function based on the actual parameter sequence to obtain a second return value sequence of the second function; wherein, the first calling condition is that for each actual parameter in the actual parameter sequence, the type of the actual parameter is the same as the type of the formal parameter of the second function corresponding to the actual parameter; and, if the second return value sequence satisfies a second calling condition, invoke the first function based on the second return value sequence to obtain a first return value of the first function; wherein, the second calling condition is that for each second return value in the second return value sequence, the type of the second return value is the same as the type of the formal parameter in the parameter type sequence of the first function corresponding to the second return value.
6. The apparatus according to claim 5, characterized in that, The calling module is further configured to generate a data structure including the second return value sequence; call a preset parameter passing function, traverse each second return value in the data structure through the preset parameter passing function, and pass the traversed second return value to the formal parameter corresponding to the first function; Call the first function and obtain the first return value of the first function.
7. The apparatus according to claim 6, characterized in that, The device further includes: The first feedback module is configured to return the problematic actual parameter in the actual parameter sequence to the client if the actual parameter sequence does not meet the first calling condition.
8. The apparatus according to claim 6, characterized in that, The device further includes: The second feedback module is configured to return a second return value from the second return value sequence to the client if the second return value sequence does not meet the second calling condition.
9. An electronic device, characterized in that, include: processor; Memory used to store the processor's executable instructions; The processor is configured to execute the instructions to implement the method as described in any one of claims 1 to 4.
10. A computer-readable storage medium, wherein instructions in the computer-readable storage medium, when executed by a processor of an electronic device, enable the electronic device to perform the method as described in any one of claims 1 to 4.
11. A computer program product comprising computer-readable code that, when executed on an electronic device, causes the electronic device to perform the method as described in any one of claims 1 to 4.
Citation Information
Patent Citations
Method for recording C language function call chain and C language general log framework
CN110134385A
Program running method and device and computing device
CN111610966A