mirror of https://github.com/swig/swig
Reorganise raw data typemap,
so typemaps folder contain only common part. Improve document. Signed-off-by: Erez Geva <ErezGeva2@gmail.com>
This commit is contained in:
parent
81345bd3a5
commit
affbd5893d
|
@ -7,6 +7,22 @@ the issue number to the end of the URL: https://github.com/swig/swig/issues/
|
|||
Version 4.3.0 (in progress)
|
||||
===========================
|
||||
|
||||
2024-02-29: erezgeva
|
||||
#2609 Fix Java typemap (char *STRING, size_t LENGTH) to use string type.
|
||||
Add STRING-LENGTH typemap to most languages.
|
||||
All languages uses string type for STRING-LENGTH typemap.
|
||||
Add char_binary test to most languages and
|
||||
director_binary test to languages supporting director class.
|
||||
Add new typemap BYTES-LENGTH to use with cdata.
|
||||
Add BYTES-LENGTH typemap to most languages.
|
||||
Rebase cdata typemap to improve coherent among different languages.
|
||||
Add li_cdata test to most languages.
|
||||
Languages with static type use byte array for cdata.
|
||||
While dynamic type languages retain string.
|
||||
incompatibilities:
|
||||
* STRING-LENGTH: Java uses String
|
||||
* cdata: Go uses byte array and int64 for size
|
||||
|
||||
2024-02-28: wsfulton
|
||||
Fix compilation errors in generated code when instantiating a templated
|
||||
static method within a template (non-static methods and constructors were
|
||||
|
|
|
@ -728,7 +728,7 @@ Target dynamic typed language must support strings with embedded binary data
|
|||
in order for benefit from this module, and should support a 'pack' and 'unpack'
|
||||
functions to convert string to array of numbers and via versa.
|
||||
Most static typed languages uses string with defined encoding,
|
||||
which means the content of the String will be different from the original raw C data.
|
||||
which does not make them suitable for holding raw data.
|
||||
Yet most dynamic typed language do not support arrays of bytes and
|
||||
do not have a defined encoding of strings, which make them proper for holding raw data.
|
||||
</p>
|
||||
|
|
|
@ -6,7 +6,7 @@ func main() {
|
|||
s := []byte("ABC\x00abc")
|
||||
m := Malloc(256)
|
||||
Memmove(m, s)
|
||||
ss := Cdata(m, 7)
|
||||
ss := Cdata(m, int64(7))
|
||||
if string(ss) != "ABC\x00abc" {
|
||||
panic("failed")
|
||||
}
|
||||
|
|
|
@ -6,7 +6,7 @@ func main() {
|
|||
s := []byte("ABC\x00abc")
|
||||
m := Malloc(256)
|
||||
Memmove(m, s)
|
||||
ss := Cdata(m, 7)
|
||||
ss := Cdata(m, int64(7))
|
||||
if string(ss) != "ABC\x00abc" {
|
||||
panic("failed")
|
||||
}
|
||||
|
|
49
Lib/cdata.i
49
Lib/cdata.i
|
@ -4,5 +4,52 @@
|
|||
* SWIG library file containing macros for manipulating raw C data.
|
||||
* ----------------------------------------------------------------------------- */
|
||||
|
||||
%include <typemaps/cdata.swg>
|
||||
%typemap(in,noblock=0,fragment="SWIG_AsCharPtrAndSize")
|
||||
(const void *BYTES, size_t LENGTH) (int res, void *buf = 0, size_t len = 0, int alloc = 0)
|
||||
{
|
||||
res = SWIG_AsCharPtrAndSize($input, (char **)&buf, &len, &alloc);
|
||||
if (!SWIG_IsOK(res)) {
|
||||
%argument_fail(res,"$type",$symname, $argnum);
|
||||
}
|
||||
$1 = %reinterpret_cast(buf, $1_ltype);
|
||||
$2 = %numeric_cast(len, $2_ltype);
|
||||
}
|
||||
|
||||
%typemap(freearg,noblock=1,match="in")
|
||||
(const void *BYTES, size_t LENGTH)
|
||||
{
|
||||
if (alloc$argnum == SWIG_NEWOBJ) {
|
||||
%delete_array((char*)(buf$argnum));
|
||||
}
|
||||
}
|
||||
|
||||
%typemap(directorin,noblock=1,fragment="SWIG_FromCharPtrAndSize")
|
||||
(const void *BYTES, size_t LENGTH)
|
||||
{
|
||||
if ($1 && $2 > 0) {
|
||||
$input = SWIG_FromCharPtrAndSize((const char*)$1, (size_t)$2);
|
||||
} else {
|
||||
$input = SWIG_FromCharPtrAndSize("", 0);
|
||||
}
|
||||
}
|
||||
|
||||
%typemap(in) (void *BYTES, size_t LENGTH) = (const void *BYTES, size_t LENGTH);
|
||||
%typemap(freearg) (void *BYTES, size_t LENGTH) = (const void *BYTES, size_t LENGTH);
|
||||
%typemap(directorin) (void *BYTES, size_t LENGTH) = (const void *BYTES, size_t LENGTH);
|
||||
%typemap(in) (const void *BYTES, int LENGTH) = (const void *BYTES, size_t LENGTH);
|
||||
%typemap(freearg) (const void *BYTES, int LENGTH) = (const void *BYTES, size_t LENGTH);
|
||||
%typemap(directorin) (const void *BYTES, int LENGTH) = (const void *BYTES, size_t LENGTH);
|
||||
%typemap(in) (void *BYTES, int LENGTH) = (const void *BYTES, int LENGTH);
|
||||
%typemap(freearg) (void *BYTES, int LENGTH) = (const void *BYTES, int LENGTH);
|
||||
%typemap(directorin) (void *BYTES, int LENGTH) = (const void *BYTES, int LENGTH);
|
||||
%typemap(in) (const void *indata, size_t inlen) = (const void *BYTES, size_t LENGTH);
|
||||
%typemap(freearg) (const void *indata, size_t inlen) = (const void *BYTES, size_t LENGTH);
|
||||
%typemap(directorin) (const void *indata, size_t inlen) = (const void *BYTES, size_t LENGTH);
|
||||
|
||||
%include <typemaps/cdata_struct.swg>
|
||||
|
||||
%typemap(out,noblock=1,fragment="SWIG_FromCharPtrAndSize") SWIGCDATA {
|
||||
%set_output(SWIG_FromCharPtrAndSize($1.data,$1.len));
|
||||
}
|
||||
|
||||
%include <typemaps/cdata.swg>
|
||||
|
|
|
@ -79,6 +79,58 @@ SWIGEXPORT void* SWIGSTDCALL SWIG_csharp_bytes_to_c(int len, void *ptr) {
|
|||
%}
|
||||
|
||||
%apply (const void *BYTES, size_t LENGTH) { (void *BYTES, size_t LENGTH) }
|
||||
%include <typemaps/cdata_apply.swg>
|
||||
|
||||
%include <typemaps/cdata_struct.swg>
|
||||
|
||||
%pragma(csharp) imclasscode=%{
|
||||
[global::System.Runtime.InteropServices.DllImport("$module", EntryPoint="SWIG_csharp_data")]
|
||||
public static extern int SWIG_csharp_data(global::System.IntPtr data, ref global::System.IntPtr m);
|
||||
%}
|
||||
|
||||
%fragment("SWIG_csharp_data", "header") %{
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
SWIGEXPORT int SWIGSTDCALL SWIG_csharp_data(SWIGCDATA *d, void **ptr) {
|
||||
int ret;
|
||||
ret = 0;
|
||||
if (d != SWIG_NULLPTR) {
|
||||
if (d->len > 0 && d->data != SWIG_NULLPTR) {
|
||||
*ptr = (void *)d->data;
|
||||
ret = (int)d->len;
|
||||
}
|
||||
free(d); /* allocated in 'out' typemap */
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
%}
|
||||
|
||||
%typemap(ctype) SWIGCDATA "SWIGCDATA *"
|
||||
%typemap(imtype) SWIGCDATA "global::System.IntPtr"
|
||||
%typemap(cstype) SWIGCDATA "byte[]"
|
||||
%typemap(out) SWIGCDATA %{
|
||||
$result = (SWIGCDATA*)malloc(sizeof($1));
|
||||
if($result != SWIG_NULLPTR) {
|
||||
memcpy($result, &$1, sizeof($1));
|
||||
}
|
||||
%}
|
||||
%typemap(csout, fragment="SWIG_csharp_data") SWIGCDATA {
|
||||
global::System.IntPtr mm;
|
||||
byte[] ret;
|
||||
int size;
|
||||
mm = global::System.IntPtr.Zero;
|
||||
size = $modulePINVOKE.SWIG_csharp_data($imcall, ref mm);
|
||||
ret = new byte[size];
|
||||
if (size > 0) {
|
||||
System.Runtime.InteropServices.Marshal.Copy(mm, ret, 0, size);
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
%include <typemaps/cdata.swg>
|
||||
|
||||
|
|
|
@ -16,5 +16,17 @@
|
|||
$2 = ($2_ltype)$input.len;
|
||||
%}
|
||||
%apply (const void *BYTES, size_t LENGTH) { (void *BYTES, size_t LENGTH) }
|
||||
%include <typemaps/cdata_apply.swg>
|
||||
|
||||
%include <typemaps/cdata_struct.swg>
|
||||
|
||||
%typemap(dtype) SWIGCDATA "ubyte[]"
|
||||
%typemap(imtype) SWIGCDATA "ubyte[]"
|
||||
%typemap(ctype) SWIGCDATA "SWIG_c_array"
|
||||
%typemap(out) SWIGCDATA %{
|
||||
$result.array = $1.data;
|
||||
$result.len = $1.len;
|
||||
%}
|
||||
%typemap(dout) SWIGCDATA { return $imcall; }
|
||||
|
||||
%include <typemaps/cdata.swg>
|
||||
|
|
|
@ -4,13 +4,6 @@
|
|||
* SWIG library file containing macros for manipulating raw C data.
|
||||
* ----------------------------------------------------------------------------- */
|
||||
|
||||
%fragment("cdata", "header") %{
|
||||
struct swigcdata {
|
||||
intgo size;
|
||||
void *data;
|
||||
};
|
||||
%}
|
||||
|
||||
/* ------------------------------------------------------------
|
||||
* Typemap for passing bytes with length
|
||||
* ------------------------------------------------------------ */
|
||||
|
@ -22,6 +15,47 @@ struct swigcdata {
|
|||
$2 = ($2_ltype)$input.len;
|
||||
%}
|
||||
%apply (const void *BYTES, size_t LENGTH) { (void *BYTES, size_t LENGTH) }
|
||||
%include <typemaps/cdata_apply.swg>
|
||||
|
||||
%include <typemaps/cdata_struct.swg>
|
||||
|
||||
%fragment("cdata", "header") %{
|
||||
struct swigcdata {
|
||||
uintgo size;
|
||||
void *data;
|
||||
};
|
||||
%}
|
||||
|
||||
%typemap(gotype) SWIGCDATA "[]byte"
|
||||
%typemap(imtype) SWIGCDATA "uint64"
|
||||
|
||||
%typemap(out, fragment="cdata") SWIGCDATA(struct swigcdata *swig_out) %{
|
||||
swig_out = (struct swigcdata *)malloc(sizeof(*swig_out));
|
||||
if (swig_out) {
|
||||
swig_out->size = $1.len;
|
||||
swig_out->data = malloc(swig_out->size);
|
||||
if (swig_out->data) {
|
||||
memcpy(swig_out->data, $1.data, swig_out->size);
|
||||
}
|
||||
}
|
||||
$result = *(long long *)(void **)&swig_out;
|
||||
%}
|
||||
|
||||
%typemap(goout) SWIGCDATA %{
|
||||
{
|
||||
type swigcdata struct { size int; data uintptr }
|
||||
p := (*swigcdata)(unsafe.Pointer(uintptr($1)))
|
||||
if p == nil || p.data == 0 {
|
||||
$result = nil
|
||||
} else {
|
||||
b := make([]byte, p.size)
|
||||
a := (*[0x7fffffff]byte)(unsafe.Pointer(p.data))[:p.size]
|
||||
copy(b, a)
|
||||
Swig_free(p.data)
|
||||
Swig_free(uintptr(unsafe.Pointer(p)))
|
||||
$result = b
|
||||
}
|
||||
}
|
||||
%}
|
||||
|
||||
%include <typemaps/cdata.swg>
|
||||
|
||||
|
|
|
@ -14,6 +14,12 @@
|
|||
$2 = ($2_ltype) temp;
|
||||
}
|
||||
%apply (const void *BYTES, size_t LENGTH) { (void *BYTES, size_t LENGTH) }
|
||||
%include <typemaps/cdata_apply.swg>
|
||||
|
||||
%include <typemaps/cdata_struct.swg>
|
||||
|
||||
%typemap(out) SWIGCDATA {
|
||||
$result = scm_from_locale_stringn($1.data,$1.len);
|
||||
}
|
||||
|
||||
%include <typemaps/cdata.swg>
|
||||
|
||||
|
|
|
@ -43,5 +43,37 @@
|
|||
}
|
||||
%typemap(directorargout, noblock=1) (void *BYTES, size_t LENGTH)
|
||||
{ if ($input && $1) JCALL4(GetByteArrayRegion, jenv, $input, 0, (jsize)$2, (jbyte *)$1); }
|
||||
%include <typemaps/cdata_apply.swg>
|
||||
|
||||
%include <typemaps/cdata_struct.swg>
|
||||
|
||||
%typemap(jni) SWIGCDATA "jbyteArray"
|
||||
%typemap(jtype) SWIGCDATA "byte[]"
|
||||
%typemap(jstype) SWIGCDATA "byte[]"
|
||||
%fragment("SWIG_JavaArrayOutCDATA", "header") {
|
||||
static jbyteArray SWIG_JavaArrayOutCDATA(JNIEnv *jenv, char *result, jsize sz) {
|
||||
jbyteArray jresult;
|
||||
jbyte *arr;
|
||||
int i;
|
||||
jresult = JCALL1(NewByteArray, jenv, sz);
|
||||
if (!jresult) {
|
||||
return SWIG_NULLPTR;
|
||||
}
|
||||
arr = JCALL2(GetByteArrayElements, jenv, jresult, 0);
|
||||
if (!arr) {
|
||||
return SWIG_NULLPTR;
|
||||
}
|
||||
for (i=0; i<sz; i++) {
|
||||
arr[i] = (jbyte)result[i];
|
||||
}
|
||||
JCALL3(ReleaseByteArrayElements, jenv, jresult, arr, 0);
|
||||
return jresult;
|
||||
}
|
||||
}
|
||||
%typemap(out, fragment="SWIG_JavaArrayOutCDATA") SWIGCDATA
|
||||
%{$result = SWIG_JavaArrayOutCDATA(jenv, (char *)$1.data, $1.len); %}
|
||||
%typemap(javaout) SWIGCDATA {
|
||||
return $jnicall;
|
||||
}
|
||||
|
||||
%include <typemaps/cdata.swg>
|
||||
|
|
|
@ -1 +0,0 @@
|
|||
%include <typemaps/cdata.swg>
|
|
@ -1 +0,0 @@
|
|||
%include <typemaps/cdata.swg>
|
|
@ -1 +0,0 @@
|
|||
%include <typemaps/cdata.swg>
|
|
@ -4,7 +4,6 @@
|
|||
* SWIG library file containing macros for manipulating raw C data.
|
||||
* ----------------------------------------------------------------------------- */
|
||||
|
||||
|
||||
/* ------------------------------------------------------------
|
||||
* Typemap for passing bytes with length
|
||||
* ------------------------------------------------------------ */
|
||||
|
@ -16,6 +15,10 @@
|
|||
$2 = ($2_ltype)len;
|
||||
}
|
||||
%apply (const void *BYTES, size_t LENGTH) { (void *BYTES, size_t LENGTH) }
|
||||
%include <typemaps/cdata_apply.swg>
|
||||
|
||||
%include <typemaps/cdata_struct.swg>
|
||||
|
||||
%typemap(out) SWIGCDATA %{lua_pushlstring(L, $1.data,$1.len); SWIG_arg++;%}
|
||||
|
||||
%include <typemaps/cdata.swg>
|
||||
|
||||
|
|
|
@ -0,0 +1,10 @@
|
|||
/* -----------------------------------------------------------------------------
|
||||
* cdata.i
|
||||
*
|
||||
* SWIG library file containing macros for manipulating raw C data.
|
||||
*
|
||||
* TODO:
|
||||
* Use generic cdata bu deleting this file and implementing
|
||||
* SWIG_AsCharPtrAndSize() and SWIG_FromCharPtrAndSize()
|
||||
* Or implement (void *BYTES, size_t LENGTH) and SWIGCDATA typemaps
|
||||
* ----------------------------------------------------------------------------- */
|
|
@ -0,0 +1,10 @@
|
|||
/* -----------------------------------------------------------------------------
|
||||
* cdata.i
|
||||
*
|
||||
* SWIG library file containing macros for manipulating raw C data.
|
||||
*
|
||||
* TODO:
|
||||
* Use generic cdata bu deleting this file and implementing
|
||||
* SWIG_AsCharPtrAndSize() and SWIG_FromCharPtrAndSize()
|
||||
* Or implement (void *BYTES, size_t LENGTH) and SWIGCDATA typemaps
|
||||
* ----------------------------------------------------------------------------- */
|
|
@ -14,6 +14,12 @@
|
|||
$2 = ($2_ltype) Z_STRLEN($input);
|
||||
%}
|
||||
%apply (const void *BYTES, size_t LENGTH) { (void *BYTES, size_t LENGTH) }
|
||||
%include <typemaps/cdata_apply.swg>
|
||||
|
||||
%include <typemaps/cdata_struct.swg>
|
||||
|
||||
%typemap(out) SWIGCDATA {
|
||||
ZVAL_STRINGL($result, $1.data, $1.len);
|
||||
}
|
||||
|
||||
%include <typemaps/cdata.swg>
|
||||
|
||||
|
|
|
@ -4,241 +4,12 @@
|
|||
* This library file contains macros for manipulating raw C data.
|
||||
* ----------------------------------------------------------------------------- */
|
||||
|
||||
#ifdef SWIGGO
|
||||
#define swig_cdata_nelems_type int
|
||||
#else
|
||||
#define swig_cdata_nelems_type size_t
|
||||
#endif
|
||||
|
||||
%{
|
||||
typedef struct SWIGCDATA {
|
||||
char *data;
|
||||
#ifdef SWIGGO
|
||||
intgo len;
|
||||
#else
|
||||
size_t len;
|
||||
#endif
|
||||
} SWIGCDATA;
|
||||
%}
|
||||
|
||||
/* ------------------------------------------------------------
|
||||
* Typemap for passing bytes with length
|
||||
* ------------------------------------------------------------ */
|
||||
|
||||
#if !defined SWIGJAVA && !defined SWIGGO && !defined SWIGD && !defined SWIGPHP &&\
|
||||
!defined SWIGGUILE && !defined SWIGCSHARP && !defined SWIGLUA &&\
|
||||
!defined SWIGMZSCHEME
|
||||
|
||||
%typemap(in,noblock=0,fragment="SWIG_AsCharPtrAndSize")
|
||||
(const void *BYTES, size_t LENGTH) (int res, void *buf = 0, size_t len = 0, int alloc = 0)
|
||||
{
|
||||
res = SWIG_AsCharPtrAndSize($input, (char **)&buf, &len, &alloc);
|
||||
if (!SWIG_IsOK(res)) {
|
||||
%argument_fail(res,"$type",$symname, $argnum);
|
||||
}
|
||||
$1 = %reinterpret_cast(buf, $1_ltype);
|
||||
$2 = %numeric_cast(len, $2_ltype);
|
||||
}
|
||||
|
||||
%typemap(freearg,noblock=1,match="in")
|
||||
(const void *BYTES, size_t LENGTH)
|
||||
{
|
||||
if (alloc$argnum == SWIG_NEWOBJ) {
|
||||
%delete_array((char*)(buf$argnum));
|
||||
}
|
||||
}
|
||||
|
||||
%typemap(directorin,noblock=1,fragment="SWIG_FromCharPtrAndSize")
|
||||
(const void *BYTES, size_t LENGTH)
|
||||
{
|
||||
if ($1 && $2 > 0) {
|
||||
$input = SWIG_FromCharPtrAndSize((const char*)$1, (size_t)$2);
|
||||
} else {
|
||||
$input = SWIG_FromCharPtrAndSize("", 0);
|
||||
}
|
||||
}
|
||||
|
||||
%typemap(in) (void *BYTES, size_t LENGTH) = (const void *BYTES, size_t LENGTH);
|
||||
%typemap(freearg) (void *BYTES, size_t LENGTH) = (const void *BYTES, size_t LENGTH);
|
||||
%typemap(directorin) (void *BYTES, size_t LENGTH) = (const void *BYTES, size_t LENGTH);
|
||||
%typemap(in) (const void *BYTES, int LENGTH) = (const void *BYTES, size_t LENGTH);
|
||||
%typemap(freearg) (const void *BYTES, int LENGTH) = (const void *BYTES, size_t LENGTH);
|
||||
%typemap(directorin) (const void *BYTES, int LENGTH) = (const void *BYTES, size_t LENGTH);
|
||||
%typemap(in) (void *BYTES, int LENGTH) = (const void *BYTES, int LENGTH);
|
||||
%typemap(freearg) (void *BYTES, int LENGTH) = (const void *BYTES, int LENGTH);
|
||||
%typemap(directorin) (void *BYTES, int LENGTH) = (const void *BYTES, int LENGTH);
|
||||
%typemap(in) (const void *indata, size_t inlen) = (const void *BYTES, size_t LENGTH);
|
||||
%typemap(freearg) (const void *indata, size_t inlen) = (const void *BYTES, size_t LENGTH);
|
||||
%typemap(directorin) (const void *indata, size_t inlen) = (const void *BYTES, size_t LENGTH);
|
||||
|
||||
#else
|
||||
|
||||
%apply (const void *BYTES, size_t LENGTH) { (const void *BYTES, int LENGTH) }
|
||||
%apply (void *BYTES, size_t LENGTH) { (void *BYTES, int LENGTH) }
|
||||
%apply (const void *BYTES, size_t LENGTH) { (const void *indata, size_t inlen) }
|
||||
|
||||
#endif
|
||||
|
||||
/* -----------------------------------------------------------------------------
|
||||
* Typemaps for returning binary data
|
||||
* ----------------------------------------------------------------------------- */
|
||||
|
||||
#ifdef SWIGJAVA
|
||||
|
||||
%typemap(jni) SWIGCDATA "jbyteArray"
|
||||
%typemap(jtype) SWIGCDATA "byte[]"
|
||||
%typemap(jstype) SWIGCDATA "byte[]"
|
||||
%fragment("SWIG_JavaArrayOutCDATA", "header") {
|
||||
static jbyteArray SWIG_JavaArrayOutCDATA(JNIEnv *jenv, char *result, jsize sz) {
|
||||
jbyteArray jresult;
|
||||
jbyte *arr;
|
||||
int i;
|
||||
jresult = JCALL1(NewByteArray, jenv, sz);
|
||||
if (!jresult) {
|
||||
return SWIG_NULLPTR;
|
||||
}
|
||||
arr = JCALL2(GetByteArrayElements, jenv, jresult, 0);
|
||||
if (!arr) {
|
||||
return SWIG_NULLPTR;
|
||||
}
|
||||
for (i=0; i<sz; i++) {
|
||||
arr[i] = (jbyte)result[i];
|
||||
}
|
||||
JCALL3(ReleaseByteArrayElements, jenv, jresult, arr, 0);
|
||||
return jresult;
|
||||
}
|
||||
}
|
||||
%typemap(out, fragment="SWIG_JavaArrayOutCDATA") SWIGCDATA
|
||||
%{$result = SWIG_JavaArrayOutCDATA(jenv, (char *)$1.data, $1.len); %}
|
||||
%typemap(javaout) SWIGCDATA {
|
||||
return $jnicall;
|
||||
}
|
||||
|
||||
#elif SWIGGO
|
||||
|
||||
%typemap(gotype) SWIGCDATA "[]byte"
|
||||
%typemap(imtype) SWIGCDATA "uint64"
|
||||
|
||||
%typemap(out, fragment="cdata") SWIGCDATA(struct swigcdata *swig_out) %{
|
||||
swig_out = (struct swigcdata *)malloc(sizeof(*swig_out));
|
||||
if (swig_out) {
|
||||
swig_out->size = $1.len;
|
||||
swig_out->data = malloc(swig_out->size);
|
||||
if (swig_out->data) {
|
||||
memcpy(swig_out->data, $1.data, swig_out->size);
|
||||
}
|
||||
}
|
||||
$result = *(long long *)(void **)&swig_out;
|
||||
%}
|
||||
|
||||
%typemap(goout) SWIGCDATA %{
|
||||
{
|
||||
type swigcdata struct { size int; data uintptr }
|
||||
p := (*swigcdata)(unsafe.Pointer(uintptr($1)))
|
||||
if p == nil || p.data == 0 {
|
||||
$result = nil
|
||||
} else {
|
||||
b := make([]byte, p.size)
|
||||
a := (*[0x7fffffff]byte)(unsafe.Pointer(p.data))[:p.size]
|
||||
copy(b, a)
|
||||
Swig_free(p.data)
|
||||
Swig_free(uintptr(unsafe.Pointer(p)))
|
||||
$result = b
|
||||
}
|
||||
}
|
||||
%}
|
||||
|
||||
#elif SWIGD
|
||||
|
||||
%typemap(dtype) SWIGCDATA "ubyte[]"
|
||||
%typemap(imtype) SWIGCDATA "ubyte[]"
|
||||
%typemap(ctype) SWIGCDATA "SWIG_c_array"
|
||||
%typemap(out) SWIGCDATA %{
|
||||
$result.array = $1.data;
|
||||
$result.len = $1.len;
|
||||
%}
|
||||
%typemap(dout) SWIGCDATA { return $imcall; }
|
||||
|
||||
#elif SWIGPHP
|
||||
|
||||
%typemap(out) SWIGCDATA {
|
||||
ZVAL_STRINGL($result, $1.data, $1.len);
|
||||
}
|
||||
|
||||
#elif SWIGGUILE
|
||||
|
||||
%typemap(out) SWIGCDATA {
|
||||
$result = scm_from_locale_stringn($1.data,$1.len);
|
||||
}
|
||||
|
||||
#elif SWIGCSHARP
|
||||
|
||||
%pragma(csharp) imclasscode=%{
|
||||
[global::System.Runtime.InteropServices.DllImport("$module", EntryPoint="SWIG_csharp_data")]
|
||||
public static extern int SWIG_csharp_data(global::System.IntPtr data, ref global::System.IntPtr m);
|
||||
%}
|
||||
|
||||
%fragment("SWIG_csharp_data", "header") %{
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
SWIGEXPORT int SWIGSTDCALL SWIG_csharp_data(SWIGCDATA *d, void **ptr) {
|
||||
int ret;
|
||||
ret = 0;
|
||||
if (d != SWIG_NULLPTR) {
|
||||
if (d->len > 0 && d->data != SWIG_NULLPTR) {
|
||||
*ptr = (void *)d->data;
|
||||
ret = (int)d->len;
|
||||
}
|
||||
free(d); /* allocated in 'out' typemap */
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
%}
|
||||
|
||||
%typemap(ctype) SWIGCDATA "SWIGCDATA *"
|
||||
%typemap(imtype) SWIGCDATA "global::System.IntPtr"
|
||||
%typemap(cstype) SWIGCDATA "byte[]"
|
||||
%typemap(out) SWIGCDATA %{
|
||||
$result = (SWIGCDATA*)malloc(sizeof($1));
|
||||
if($result != SWIG_NULLPTR) {
|
||||
memcpy($result, &$1, sizeof($1));
|
||||
}
|
||||
%}
|
||||
%typemap(csout, fragment="SWIG_csharp_data") SWIGCDATA {
|
||||
global::System.IntPtr mm;
|
||||
byte[] ret;
|
||||
int size;
|
||||
mm = global::System.IntPtr.Zero;
|
||||
size = $modulePINVOKE.SWIG_csharp_data($imcall, ref mm);
|
||||
ret = new byte[size];
|
||||
if (size > 0) {
|
||||
System.Runtime.InteropServices.Marshal.Copy(mm, ret, 0, size);
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
#elif SWIGLUA
|
||||
|
||||
%typemap(out) SWIGCDATA %{lua_pushlstring(L, $1.data,$1.len); SWIG_arg++;%}
|
||||
|
||||
#elif SWIGMZSCHEME
|
||||
|
||||
#else
|
||||
|
||||
%typemap(out,noblock=1,fragment="SWIG_FromCharPtrAndSize") SWIGCDATA {
|
||||
%set_output(SWIG_FromCharPtrAndSize($1.data,$1.len));
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
/* -----------------------------------------------------------------------------
|
||||
* %cdata(TYPE [, NAME])
|
||||
* %cdata(TYPE [, NAME])
|
||||
*
|
||||
* Convert raw C data to binary
|
||||
* ----------------------------------------------------------------------------- */
|
||||
|
@ -247,12 +18,12 @@ SWIGEXPORT int SWIGSTDCALL SWIG_csharp_data(SWIGCDATA *d, void **ptr) {
|
|||
|
||||
%insert("header") {
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
extern "C" {
|
||||
#endif
|
||||
#if #NAME == ""
|
||||
static SWIGCDATA cdata_##TYPE(TYPE *ptr, swig_cdata_nelems_type nelements)
|
||||
static SWIGCDATA cdata_##TYPE(TYPE *ptr, size_t nelements)
|
||||
#else
|
||||
static SWIGCDATA cdata_##NAME(TYPE *ptr, swig_cdata_nelems_type nelements)
|
||||
static SWIGCDATA cdata_##NAME(TYPE *ptr, size_t nelements)
|
||||
#endif
|
||||
{
|
||||
SWIGCDATA d;
|
||||
|
@ -273,20 +44,16 @@ static SWIGCDATA cdata_##NAME(TYPE *ptr, swig_cdata_nelems_type nelements)
|
|||
extern "C"
|
||||
#endif
|
||||
#if #NAME == ""
|
||||
SWIGCDATA cdata_##TYPE(TYPE *ptr, swig_cdata_nelems_type nelements = 1);
|
||||
SWIGCDATA cdata_##TYPE(TYPE *ptr, size_t nelements = 1);
|
||||
#else
|
||||
SWIGCDATA cdata_##NAME(TYPE *ptr, swig_cdata_nelems_type nelements = 1);
|
||||
SWIGCDATA cdata_##NAME(TYPE *ptr, size_t nelements = 1);
|
||||
#endif
|
||||
%enddef
|
||||
|
||||
%rename(cdata) ::cdata_void(void *ptr, swig_cdata_nelems_type nelements = 1);
|
||||
%rename(cdata) ::cdata_void(void *ptr, size_t nelements = 1);
|
||||
|
||||
%cdata(void);
|
||||
|
||||
/* Memory move function. Due to multi-argument typemaps this appears to be wrapped as
|
||||
void memmove(void *data, const char *s); */
|
||||
void memmove(void *data, const void *indata, size_t inlen);
|
||||
|
||||
|
||||
|
||||
|
||||
|
|
|
@ -0,0 +1,14 @@
|
|||
/* -----------------------------------------------------------------------------
|
||||
* cdata.swg
|
||||
*
|
||||
* apply raw C data typemaps.
|
||||
* ----------------------------------------------------------------------------- */
|
||||
|
||||
/* ------------------------------------------------------------
|
||||
* Typemap for passing bytes with length
|
||||
* ------------------------------------------------------------ */
|
||||
|
||||
%apply (const void *BYTES, size_t LENGTH) { (const void *BYTES, int LENGTH) }
|
||||
%apply (void *BYTES, size_t LENGTH) { (void *BYTES, int LENGTH) }
|
||||
/* type map for memmove() function */
|
||||
%apply (const void *BYTES, size_t LENGTH) { (const void *indata, size_t inlen) }
|
|
@ -0,0 +1,12 @@
|
|||
/* -----------------------------------------------------------------------------
|
||||
* cdata.swg
|
||||
*
|
||||
* raw C data struct.
|
||||
* ----------------------------------------------------------------------------- */
|
||||
|
||||
%{
|
||||
typedef struct SWIGCDATA {
|
||||
char *data;
|
||||
size_t len;
|
||||
} SWIGCDATA;
|
||||
%}
|
Loading…
Reference in New Issue