fcmpact

addPrototypes

L'essentiel
At a glance
Bridging the gap between distributed analytics and low-level programming, the addPrototypes command empowers developers to integrate external C/C++ logic directly into the CAS runtime. Part of the FCMP suite, this utility functions as a registry service, mapping shared library executables to SAS function signatures so they can be invoked seamlessly within DS2 or DATA Step operations. The comprehensive Q&A section below explores the intricacies of defining these function interfaces, managing binary dependencies, and troubleshooting linkage errors when extending native SAS capabilities.

Description

The `addPrototypes` action from the `fcmpact` action set allows for the dynamic definition and registration of external function prototypes within a CAS session. These prototypes, defined using the PROTO statement, are then stored in a specified CAS table, making them available for use in other CASL programs or actions. This is particularly useful for integrating external C/C++ functions into the CAS environment without pre-compilation into a library.

fcmpact.addPrototypes <result=results> <status=rc> / bridgeCatchSignals=TRUE | FALSE, bridgeFile="string", encode=TRUE | FALSE, funcTable={...}, library="string", package="string", routineCode={"string-1" <, "string-2", ...>}, saveTable=TRUE | FALSE, stdcall=TRUE | FALSE;
Settings
ParameterDescription
bridgeCatchSignals Specifies that the bridge file should contain code to install and handle signals. Default: FALSE.
bridgeFile Specifies the path to the PROTO bridge file source module.
encode Specifies that the prototype definitions are encoded in the saved function table. Aliases: encrypt, hide. Default: FALSE.
funcTable Specifies the output table where the PROTO definitions are written. This is a required parameter.
library Specifies an existing FCMP library to load.
package Specifies the FCMP package name used for storing PROTO definitions.
routineCode Specifies the PROTO definition's code that is saved to the table. This is a required parameter. Alias: code.
saveTable Specifies if the FCMP table should be saved to disk. Default: FALSE.
stdcall Specifies that functions should be called using the __stdcall convention (Windows PC only). Default: FALSE.
Data Preparation View data prep sheet
No Data Creation

The `addPrototypes` action does not create a standard dataset. Instead, it populates a special CAS table with function prototype definitions, making them accessible within the CAS session. The following code demonstrates how to set up the action, but it does not generate a dataset in the traditional sense.

Copied!
1/* This action does not create
2data directly. See examples below. */

Examples

This example defines a single external C function prototype named `mycfunc` and stores it in a CAS table named `myprotos` within the `casuser` caslib.

SAS® / CAS Code Code awaiting community validation
Copied!
1PROC CAS;
2 fcmpact.addPrototypes
3 routineCode={"proto mycfunc(double) returns double;"},
4 funcTable={name="myprotos", caslib="casuser", replace=true};
5QUIT;
Result :
The action will create a table named `myprotos` in the `casuser` library containing the prototype definition for `mycfunc`. A confirmation message will be displayed in the log.

This example defines two prototypes for external C functions, `c_sum` and `c_multiply`. It groups them into a package named `myExternalTools`, encodes the definitions for security, and saves the resulting table `myprotos` permanently in the `casuser` caslib.

SAS® / CAS Code Code awaiting community validation
Copied!
1PROC CAS;
2 fcmpact.addPrototypes
3 routineCode={
4 "proto c_sum(double, double) returns double;",
5 "proto c_multiply(double, double) returns double;"
6 },
7 package="myExternalTools",
8 encode=true,
9 saveTable=true,
10 funcTable={name="myprotos", caslib="casuser", replace=true};
11QUIT;
Result :
A permanent CAS table named `myprotos.sashdat` will be saved in the `casuser` caslib. This table will contain the encoded prototype definitions for `c_sum` and `c_multiply` under the package name `myExternalTools`. The log will indicate the successful creation and saving of the table.

This example demonstrates how to generate a C bridge file. This file contains the necessary C code to link your external functions with the SAS FCMP environment. The `bridgeFile` parameter specifies the path where the C source file will be created.

SAS® / CAS Code Code awaiting community validation
Copied!
1PROC CAS;
2 fcmpact.addPrototypes
3 routineCode={"proto my_c_function(double) returns double;"},
4 package="mycpackage",
5 bridgeFile="/cas/data/mycfuncs.c",
6 funcTable={name="myprotos", caslib="casuser", replace=true};
7QUIT;
Result :
In addition to creating the `myprotos` table, this action will generate a C source file named `mycfuncs.c` in the specified path on the CAS server. This file will contain the bridging code needed to compile and link `my_c_function` for use within CAS.

FAQ

What is the purpose of the addPrototypes action in the FCMP action set?
What are the required parameters for the addPrototypes action?
How can I specify the output table for the PROTO definitions?
What is the 'encode' parameter used for?
Can I load an existing FCMP library when using addPrototypes?
What does the 'bridgeFile' parameter do?

Associated Scenarios

Use Case
Standard Integration of External C Functions for Financial Modeling

A financial institution needs to integrate its proprietary, high-performance C-based risk calculation algorithms into its SAS Viya environment. This scenario tests the basic reg...

Use Case
Bulk Registration and Encoding of a Large Bioinformatics C-Function Library

A research institute is migrating a large library of proprietary C functions for genomic sequence analysis to SAS Viya. This test validates the action's ability to handle a larg...

Use Case
Edge Case: Generating a C Bridge File for Custom Signal Handling

An engineering team is integrating a legacy C simulation library that is known to be unstable and can cause segmentation faults. They need to use the `addPrototypes` action to g...