I learned about extern C

This commit is contained in:
dancoffman 2022-11-01 21:39:04 -07:00
parent 2846d0b470
commit 203033613f
No known key found for this signature in database
GPG Key ID: 47B1F53E36A9B3CC
7 changed files with 28 additions and 4 deletions

View File

@ -7,7 +7,9 @@
'ckzg_wrap.cxx',
],
'include_dirs': ['../../inc', '../../src'],
'libraries': ['/Users/coffman@coinbase.com/src/c-kzg/bindings/node.js/libckzg.a'],
'libraries': [
'/Users/coffman@coinbase.com/src/c-kzg/bindings/node.js/c_kzg_4844.o'
],
}
]
}

View File

@ -3,7 +3,9 @@
#include <stdlib.h>
#include "ckzg.h"
void testFunction() {}
void testFunction() {
return test_function();
}
KZGSettings* loadTrustSetup(const char* file) {
KZGSettings* out = (KZGSettings*)malloc(sizeof(KZGSettings));

View File

@ -1,6 +1,8 @@
/* File : ckzg.swg */
%module ckzg
%include <typemaps.i>
%{
#include "ckzg.h"
%}

View File

@ -8,4 +8,5 @@ console.log(kzg);
console.log('Invoking function...', kzg.testFunction());
console.log('Invoking freeTrustedSetup...', kzg.freeTrustedSetup(null));
let config = {};
console.log('Invoking freeTrustedSetup...', kzg.freeTrustedSetup(config));

View File

@ -2,4 +2,8 @@ INCLUDE_DIRS = ../inc
CFLAGS += -O2
c_kzg_4844.o: c_kzg_4844.c Makefile
clang -Wall -I$(INCLUDE_DIRS) $(CFLAGS) -c $<
clang -Wall -I$(INCLUDE_DIRS) $(CFLAGS) -mmacosx-version-min=10.15 -c $<
lib: c_kzg_4844.c Makefile
clang -Wall -I$(INCLUDE_DIRS) $(CFLAGS) -mmacosx-version-min=10.15 -c c_kzg_4844.c
mv c_kzg_4844.o ../bindings/node.js

View File

@ -20,6 +20,9 @@
#include <stdlib.h>
#include <string.h>
void test_function() {}
/**
* Wrapped `malloc()` that reports failures to allocate.
*

View File

@ -54,6 +54,12 @@ typedef enum {
C_KZG_MALLOC, /**< Could not allocate memory */
} C_KZG_RET;
#ifdef __cplusplus
extern "C" {
#endif
void test_function();
/**
* KZGCommitment and KZGProof can be recovered as 48 bytes
*/
@ -118,4 +124,8 @@ C_KZG_RET verify_kzg_proof(bool *out,
const KZGProof *kzg_proof,
const KZGSettings *s);
#ifdef __cplusplus
}
#endif
#endif // C_KZG_4844_H