1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698
|
/* ------------------------------------------------------------
* go.swg
*
* Go configuration module.
* ------------------------------------------------------------ */
%include <gostring.swg>
/* Code insertion directives */
#define %go_import(...) %insert(go_imports) %{__VA_ARGS__%}
/* Basic types */
%typemap(gotype) bool, const bool & "bool"
%typemap(gotype) char, const char & "byte"
%typemap(gotype) signed char, const signed char & "int8"
%typemap(gotype) unsigned char, const unsigned char & "byte"
%typemap(gotype) short, const short & "int16"
%typemap(gotype) unsigned short, const unsigned short & "uint16"
%typemap(gotype) int, const int & "int"
%typemap(gotype) unsigned int, const unsigned int & "uint"
%typemap(gotype) long, const long & "int64"
%typemap(gotype) unsigned long, const unsigned long & "uint64"
%typemap(gotype) long long, const long long & "int64"
%typemap(gotype) unsigned long long, const unsigned long long & "uint64"
%typemap(gotype) float, const float & "float32"
%typemap(gotype) double, const double & "float64"
%typemap(in) bool,
char,
signed char,
unsigned char,
short,
unsigned short,
int,
unsigned int,
long,
unsigned long,
long long,
unsigned long long,
float,
double
%{ $1 = ($1_ltype)$input; %}
%typemap(in) const bool &,
const char &,
const signed char &,
const unsigned char &,
const short &,
const unsigned short &,
const int &,
const unsigned int &,
const long long &,
const unsigned long long &,
const float &,
const double &
%{ $1 = ($1_ltype)&$input; %}
%typemap(in) const long & ($*1_ltype temp),
const unsigned long & ($*1_ltype temp)
%{ temp = ($*1_ltype)$input;
$1 = ($1_ltype)&temp; %}
%typemap(out) bool,
char,
signed char,
unsigned char,
short,
unsigned short,
int,
unsigned int,
long,
unsigned long,
long long,
unsigned long long,
float,
double
%{ $result = $1; %}
%typemap(goout) bool,
char,
signed char,
unsigned char,
short,
unsigned short,
int,
unsigned int,
long,
unsigned long,
long long,
unsigned long long,
float,
double
""
%typemap(out) const bool &,
const char &,
const signed char &,
const unsigned char &,
const short &,
const unsigned short &,
const int &,
const unsigned int &,
const long &,
const unsigned long &,
const long long &,
const unsigned long long &,
const float &,
const double &
%{ $result = ($*1_ltype)*$1; %}
%typemap(goout) const bool &,
const char &,
const signed char &,
const unsigned char &,
const short &,
const unsigned short &,
const int &,
const unsigned int &,
const long &,
const unsigned long &,
const long long &,
const unsigned long long &,
const float &,
const double &
""
%typemap(out) void ""
%typemap(goout) void ""
%typemap(directorin) bool,
char,
signed char,
unsigned char,
short,
unsigned short,
int,
unsigned int,
long,
unsigned long,
long long,
unsigned long long,
float,
double
%{ $input = ($1_ltype)$1; %}
%typemap(godirectorin) bool,
char,
signed char,
unsigned char,
short,
unsigned short,
int,
unsigned int,
long,
unsigned long,
long long,
unsigned long long,
float,
double
""
%typemap(directorin) const bool &,
const char &,
const signed char &,
const unsigned char &,
const short &,
const unsigned short &,
const int &,
const unsigned int &,
const long &,
const unsigned long &,
const long long &,
const unsigned long long &,
const float &,
const double &
%{ $input = ($*1_ltype)$1; %}
%typemap(godirectorin) const bool &,
const char &,
const signed char &,
const unsigned char &,
const short &,
const unsigned short &,
const int &,
const unsigned int &,
const long &,
const unsigned long &,
const long long &,
const unsigned long long &,
const float &,
const double &
""
%typemap(directorout) bool,
char,
signed char,
unsigned char,
short,
unsigned short,
int,
unsigned int,
long,
unsigned long,
long long,
unsigned long long,
float,
double
%{ $result = ($1_ltype)$input; %}
%typemap(directorout,warning=SWIGWARN_TYPEMAP_DIRECTOROUT_PTR_MSG) const bool &,
const char &,
const signed char &,
const unsigned char &,
const short &,
const unsigned short &,
const int &,
const unsigned int &,
const long &,
const unsigned long &,
const long long &,
const unsigned long long &,
const float &,
const double &
%{
$result = new $*1_ltype($input);
swig_acquire_pointer(&swig_mem, $result);
%}
/* The size_t type. */
%typemap(gotype) size_t, const size_t & %{int64%}
%typemap(in) size_t
%{ $1 = (size_t)$input; %}
%typemap(in) const size_t &
%{ $1 = ($1_ltype)&$input; %}
%typemap(out) size_t
%{ $result = $1; %}
%typemap(goout) size_t ""
%typemap(out) const size_t &
%{ $result = ($*1_ltype)*$1; %}
%typemap(goout) const size_t & ""
%typemap(directorin) size_t
%{ $input = (size_t)$1; %}
%typemap(godirectorin) size_t ""
%typemap(directorin) const size_t &
%{ $input = ($*1_ltype)$1; %}
%typemap(godirectorin) const size_t & ""
%typemap(directorout) size_t
%{ $result = ($1_ltype)$input; %}
%typemap(directorout,warning=SWIGWARN_TYPEMAP_DIRECTOROUT_PTR_MSG) const size_t &
%{
$result = new $*1_ltype($input);
swig_acquire_pointer(&swig_mem, $result);
%}
/* Member pointers. */
%typemap(gotype) SWIGTYPE (CLASS::*)
%{$gotypename%}
%typemap(in) SWIGTYPE (CLASS::*)
%{ $1 = *($&1_ltype)$input; %}
%typemap(out) SWIGTYPE (CLASS::*)
%{
struct swig_out_type { intgo size; void* val; } *swig_out;
swig_out = (struct swig_out_type*)malloc(sizeof(*swig_out));
if (swig_out) {
swig_out->size = sizeof($1_ltype);
swig_out->val = malloc(swig_out->size);
if (swig_out->val) {
*($&1_ltype)(swig_out->val) = $1;
}
}
$result = swig_out;
%}
%typemap(goout) SWIGTYPE (CLASS::*)
%{
{
type swig_out_type struct { size int; val uintptr }
p := (*swig_out_type)(unsafe.Pointer($1))
if p == nil || p.val == 0 {
$result = nil
} else {
m := make([]byte, p.size)
a := (*[1024]byte)(unsafe.Pointer(p.val))[:p.size]
copy(m, a)
Swig_free(p.val)
Swig_free(uintptr(unsafe.Pointer(p)))
$result = &m[0]
}
}
%}
%typemap(directorin) SWIGTYPE (CLASS::*)
%{ $input = *($&1_ltype)$1; %}
%typemap(godirectorin) SWIGTYPE (CLASS::*) ""
%typemap(directorout) SWIGTYPE (CLASS::*)
%{
$result = new $1_ltype($input);
swig_acquire_pointer(&swig_mem, $result);
%}
/* Pointers. */
/* We can't translate pointers using a typemap, so that is handled in
the C++ code. */
%typemap(gotype) SWIGTYPE *
%{$gotypename%}
%typemap(in) SWIGTYPE *
%{ $1 = *($&1_ltype)&$input; %}
%typemap(out) SWIGTYPE *
%{ *($&1_ltype)&$result = ($1_ltype)$1; %}
%typemap(goout) SWIGTYPE * ""
%typemap(directorin) SWIGTYPE *
%{ *($&1_ltype)&$input = ($1_ltype)$1; %}
%typemap(godirectorin) SWIGTYPE * ""
%typemap(directorout) SWIGTYPE *
%{ $result = *($&1_ltype)&$input; %}
%apply SWIGTYPE * { SWIGTYPE *const }
/* Pointer references. */
%typemap(gotype) SWIGTYPE *const&
%{$gotypename%}
%typemap(in) SWIGTYPE *const& ($*1_ltype temp = 0)
%{
temp = *($1_ltype)&$input;
$1 = ($1_ltype)&temp;
%}
%typemap(out) SWIGTYPE *const&
%{ *($1_ltype)&$result = *$1; %}
%typemap(goout) SWIGTYPE *const& ""
/* References. */
/* Converting a C++ reference to Go has to be handled in the C++
code. */
%typemap(gotype) SWIGTYPE &
%{$gotypename%}
%typemap(in) SWIGTYPE &
%{ $1 = *($&1_ltype)&$input; %}
%typemap(out) SWIGTYPE &
%{ *($&1_ltype)&$result = $1; %}
%typemap(goout) SWIGTYPE & ""
%typemap(directorin) SWIGTYPE &
%{ $input = ($1_ltype)&$1; %}
%typemap(godirectorin) SWIGTYPE & ""
%typemap(directorout) SWIGTYPE &
%{ *($&1_ltype)&$result = $input; %}
%typemap(gotype) SWIGTYPE &&
%{$gotypename%}
%typemap(in) SWIGTYPE &&
%{ $1 = *($&1_ltype)&$input; %}
%typemap(out) SWIGTYPE &&
%{ *($&1_ltype)&$result = $1; %}
%typemap(goout) SWIGTYPE && ""
%typemap(directorin) SWIGTYPE &&
%{ $input = ($1_ltype)&$1_name; %}
%typemap(godirectorin) SWIGTYPE && ""
%typemap(directorout) SWIGTYPE &&
%{ *($&1_ltype)&$result = $input; %}
/* C arrays turn into Go pointers. If we know the length we can use a
slice. */
%typemap(gotype) SWIGTYPE []
%{$gotypename%}
%typemap(in) SWIGTYPE []
%{ $1 = *($&1_ltype)&$input; %}
%typemap(out) SWIGTYPE []
%{ *($&1_ltype)&$result = $1; %}
%typemap(goout) SWIGTYPE [] ""
%typemap(directorin) SWIGTYPE []
%{ $input = *($1_ltype)&$1; %}
%typemap(godirectorin) SWIGTYPE [] ""
%typemap(directorout) SWIGTYPE []
%{ *($&1_ltype)&$result = $input; %}
/* Strings. */
%typemap(gotype)
char *, char *&, char[ANY], char[] "string"
/* Needed to avoid confusion with the way the go module handles
references. */
%typemap(gotype) char&, unsigned char& "*byte"
%typemap(gotype) signed char& "*int8"
%typemap(in)
char *, char[ANY], char[]
%{
$1 = ($1_ltype)malloc($input.n + 1);
memcpy($1, $input.p, $input.n);
$1[$input.n] = '\0';
%}
%typemap(in) char *& (char *temp)
%{
temp = (char *)malloc($input.n + 1);
memcpy(temp, $input.p, $input.n);
temp[$input.n] = '\0';
$1 = ($1_ltype)&temp;
%}
%typemap(freearg)
char *, char *&, char[ANY], char[]
%{ free($1); %}
%typemap(out,fragment="AllocateString")
char *, char *&, char[ANY], char[]
%{ $result = Swig_AllocateString((char*)$1, $1 ? strlen((char*)$1) : 0); %}
%typemap(goout,fragment="CopyString")
char *, char *&, char[ANY], char[]
%{ $result = swigCopyString($1) %}
%typemap(directorin,fragment="AllocateString")
char *, char *&, char[ANY], char[]
%{
$input = Swig_AllocateString((char*)$1, $1 ? strlen((char*)$1) : 0);
%}
%typemap(godirectorin,fragment="CopyString")
char *, char *&, char[ANY], char[]
%{
$result = swigCopyString($input)
%}
%typemap(godirectorout)
char *, char *&, char[ANY], char[]
%{
{
p := Swig_malloc(len($input) + 1)
s := (*[1<<30]byte)(unsafe.Pointer(p))[:len($input) + 1]
copy(s, $input)
s[len($input)] = 0
$result = *(*string)(unsafe.Pointer(&s))
}
%}
%typemap(directorout, warning=SWIGWARN_TYPEMAP_DIRECTOROUT_PTR_MSG)
char *, char *&, char[ANY], char[]
%{ $result = ($1_ltype)$input.p; %}
/* String & length */
%typemap(gotype) (char *STRING, size_t LENGTH) "string"
%typemap(in) (char *STRING, size_t LENGTH)
%{
$1 = ($1_ltype)$input.p;
$2 = ($2_ltype)$input.n;
%}
%typemap(out,fragment="AllocateString") (char *STRING, size_t LENGTH)
%{ $result = Swig_AllocateString((char*)$1, (size_t)$2); %}
%typemap(goout,fragment="CopyString") (char *STRING, size_t LENGTH)
%{ $result = swigCopyString($1) %}
%typemap(directorin,fragment="AllocateString") (char *STRING, size_t LENGTH)
%{ $input = Swig_AllocateString((char*)$1, $2); %}
%typemap(godirectorin,fragment="CopyString") (char *STRING, size_t LENGTH)
%{ $result = swigCopyString($input) %}
%typemap(directorout) (char *STRING, size_t LENGTH)
%{
$1 = ($1_ltype)$input.p;
$2 = ($2_ltype)$input.n;
%}
/* Enums. We can't do the right thing for enums in typemap(gotype) so
we deliberately don't define them. The right thing would be to
capitalize the name. This is instead done in go.cxx. */
%typemap(gotype) enum SWIGTYPE
%{$gotypename%}
%typemap(in) enum SWIGTYPE
%{ $1 = ($1_ltype)$input; %}
%typemap(out) enum SWIGTYPE
%{ $result = (intgo)$1; %}
%typemap(goout) enum SWIGTYPE ""
%typemap(directorin) enum SWIGTYPE
%{ $input = (intgo)$1; %}
%typemap(godirectorin) enum SWIGTYPE ""
%typemap(directorout) enum SWIGTYPE
%{ $result = ($1_ltype)$input; %}
%typemap(directorin) enum SWIGTYPE & (intgo e)
%{
e = (intgo)$1;
$input = ($1_ltype)&e;
%}
%typemap(godirectorin) enum SWIGTYPE & ""
%typemap(directorout) enum SWIGTYPE &
%{
$*1_ltype f = ($*1_ltype)*$input;
$result = ($1_ltype)&f;
%}
/* Arbitrary type. This is a type passed by value in the C/C++ code.
We convert it to a pointer for the Go code. Note that all basic
types are explicitly handled above. */
%typemap(gotype) SWIGTYPE
%{$gotypename%}
%typemap(in) SWIGTYPE ($&1_type argp)
%{
argp = ($&1_ltype)$input;
if (argp == NULL) {
_swig_gopanic("Attempt to dereference null $1_type");
}
$1 = ($1_ltype)*argp;
%}
%typemap(out) SWIGTYPE
#ifdef __cplusplus
%{ *($&1_ltype*)&$result = new $1_ltype($1); %}
#else
{
$&1_ltype $1ptr = ($&1_ltype)malloc(sizeof($1_ltype));
memmove($1ptr, &$1, sizeof($1_type));
*($&1_ltype*)&$result = $1ptr;
}
#endif
%typemap(goout) SWIGTYPE ""
%typemap(directorin) SWIGTYPE
%{ $input = new $1_ltype((const $1_ltype &)$1); %}
%typemap(godirectorin) SWIGTYPE ""
%typemap(directorout) SWIGTYPE
%{ $result = *($&1_ltype)$input; %}
/* Exception handling */
%typemap(throws) char *
%{ _swig_gopanic($1); %}
%typemap(throws) SWIGTYPE, SWIGTYPE &, SWIGTYPE &&, SWIGTYPE *, SWIGTYPE [], SWIGTYPE [ANY]
%{
(void)$1;
_swig_gopanic("C++ $1_type exception thrown");
%}
/* Typecheck typemaps. The purpose of these is merely to issue a
warning for overloaded C++ functions that cannot be overloaded in
Go as more than one C++ type maps to a single Go type. */
%typecheck(SWIG_TYPECHECK_BOOL) /* Go bool */
bool,
const bool &
""
%typecheck(SWIG_TYPECHECK_CHAR) /* Go byte */
char,
const char &,
unsigned char,
const unsigned char &
""
%typecheck(SWIG_TYPECHECK_INT8) /* Go int8 */
signed char,
const signed char &
""
%typecheck(SWIG_TYPECHECK_INT16) /* Go int16 */
short,
const short &
""
%typecheck(SWIG_TYPECHECK_INT16) /* Go uint16 */
unsigned short,
const unsigned short &
""
%typecheck(SWIG_TYPECHECK_INT32) /* Go int */
int,
const int &
""
%typecheck(SWIG_TYPECHECK_INT32) /* Go uint */
unsigned int,
const unsigned int &
""
%typecheck(SWIG_TYPECHECK_INT64) /* Go int64 */
long,
const long &,
long long,
const long long &
""
%typecheck(SWIG_TYPECHECK_INT64) /* Go uint64 */
unsigned long,
const unsigned long &,
unsigned long long,
const unsigned long long &
""
%typecheck(SWIG_TYPECHECK_FLOAT) /* Go float32 */
float,
const float &
""
%typecheck(SWIG_TYPECHECK_DOUBLE) /* Go float64 */
double,
const double &
""
%typecheck(SWIG_TYPECHECK_STRING) /* Go string */
char *,
char *&,
char[ANY],
char [],
signed char *,
signed char *&,
signed char[ANY],
signed char [],
unsigned char *,
unsigned char *&,
unsigned char[ANY],
unsigned char []
""
%typecheck(SWIG_TYPECHECK_POINTER)
SWIGTYPE,
SWIGTYPE *,
SWIGTYPE &,
SWIGTYPE &&,
SWIGTYPE *const&,
SWIGTYPE [],
SWIGTYPE (CLASS::*)
""
/* Go keywords. */
%include <gokw.swg>
%include <goruntime.swg>
|