Skip to main content

A library that simplifies proxying stub functions in c

Project description

k3stubproxy

An proxy implementation to be used by embedded c stub implementations

Stub generation

Use the cli tool k3stubproxy-generate-stub included in this package.

Requirements:

  • Stub functions begin with extern
  • In the code documnetation a parameter is labled in/out in the following style
    • param [in] variableName
    • param [out] variableName

Example CLI Usage

k3stubproxy-generate-stub -v ../Code/HAL/HAL_*.c --func_prefix HAL_ -o ../Code/HAL/high_level_stub/ --filename_suffix _teststub --file_header defheader.txt --stub_function_definition_out stub_function_definition.json

Other CLI Tools (Version 0.2.1)

  • k3stubproxy-generate-target-stub (Generate a python target stub using the stub function definition created by k3stubproxy-generate-stub
  • k3stubproxy-analyse-stub-function-definition (Given the stub function definition, show stub functions and used input, output and return types)

Example usage within C

C API usage

#include "Stub_Connector_Interface.h"
...
if initStubConnector(NULL) != 0
{
    // error
    return 1;
}

Provide Implementations for the following functions:

PyObject* convert_input_to_python_object(va_list valist, int parameterPos, char* typeString);
int convert_python_object_to_output(va_list valist, int parameterPos, char* typeString, PyObject* outputObject);

And include the files Stub_Connector_Implementation.c,Stub_Connector_Interface.h from within k3stubproxy/c_stub and the replace the standard implementation with generated stub when compiling and linking.

General Information About Embedding Python Within C

char* phDir = "/some/path/to/a/venv";
printf("INFO: Using virutalenv: %s", phDir);
// This should not be some hard code palth like /home/annoying_user/temp/project123
// For example in some usages of the k3stubproxy this is set dynamically to look
// beside the exe vor the venv

// Note: Need to check return of Py_DecodeLocale is != NULL
Py_SetPythonHome(Py_DecodeLocale(phDir, NULL));

//optional but recommended
wchar_t *program = Py_DecodeLocale("stub_program", NULL);
Py_SetProgramName(program);

Py_Initialize();

// Then any lib within the venv can be used via cpython
PyRun_SimpleString("import k3stubproxy;");

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

k3stubproxy-0.2.2.tar.gz (9.5 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

k3stubproxy-0.2.2-py3-none-any.whl (12.6 kB view details)

Uploaded Python 3

File details

Details for the file k3stubproxy-0.2.2.tar.gz.

File metadata

  • Download URL: k3stubproxy-0.2.2.tar.gz
  • Upload date:
  • Size: 9.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.23.0 setuptools/46.4.0 requests-toolbelt/0.9.1 tqdm/4.46.0 CPython/3.7.3

File hashes

Hashes for k3stubproxy-0.2.2.tar.gz
Algorithm Hash digest
SHA256 123f093a687edc2e9430926d243acdb8057d51d43f2c64623663eb8066b9ddc9
MD5 940a04fcdbd401fda0d7b0e85eed94e6
BLAKE2b-256 8a8e4058b8cd2212045012d359fc9f69bacc55a564530eddd4cd08a23776e89e

See more details on using hashes here.

File details

Details for the file k3stubproxy-0.2.2-py3-none-any.whl.

File metadata

  • Download URL: k3stubproxy-0.2.2-py3-none-any.whl
  • Upload date:
  • Size: 12.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.23.0 setuptools/46.4.0 requests-toolbelt/0.9.1 tqdm/4.46.0 CPython/3.7.3

File hashes

Hashes for k3stubproxy-0.2.2-py3-none-any.whl
Algorithm Hash digest
SHA256 3a583569cca481e76fc2b75a45befc0219b501980f9301e75ce4c2e15f30bccd
MD5 654b13d8393641ea00d037b7f814b156
BLAKE2b-256 a2d61ef9493ba80228a76c03c39c9b26354852cd6f07896d7092499135889c6d

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page