Skip to content

Commit c125832

Browse files
committed
Fix missing include in SWIG typemap
1 parent 0c4491e commit c125832

File tree

4 files changed

+35
-17
lines changed

4 files changed

+35
-17
lines changed

Lib/carrays.i

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,12 @@
55
* pointers as arrays.
66
* ----------------------------------------------------------------------------- */
77

8+
#ifndef __cplusplus
9+
// C uses free/calloc/malloc
10+
%include "swigfragments.swg"
11+
%fragment("<stdlib.h>");
12+
#endif
13+
814
/* -----------------------------------------------------------------------------
915
* %array_functions(TYPE,NAME)
1016
*

Lib/cdata.i

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ static jbyteArray SWIG_JavaArrayOutCDATA(JNIEnv *jenv, char *result, jsize sz) {
6868

6969

7070
/* -----------------------------------------------------------------------------
71-
* %cdata(TYPE [, NAME])
71+
* %cdata(TYPE [, NAME])
7272
*
7373
* Convert raw C data to a binary string.
7474
* ----------------------------------------------------------------------------- */
@@ -107,6 +107,8 @@ SWIGCDATA cdata_##NAME(TYPE *ptr, int nelements);
107107

108108
%cdata(void);
109109

110+
%fragment("<string.h>");
111+
110112
/* Memory move function. Due to multi-argument typemaps this appears to be wrapped as
111113
void memmove(void *data, const char *s); */
112114
void memmove(void *data, const void *indata, int inlen);

Lib/cpointer.i

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,12 @@
55
* pointer objects.
66
* ----------------------------------------------------------------------------- */
77

8+
#ifndef __cplusplus
9+
// C uses free/calloc/malloc
10+
%include "swigfragments.swg"
11+
%fragment("<stdlib.h>");
12+
#endif
13+
814
/* -----------------------------------------------------------------------------
915
* %pointer_class(type,name)
1016
*

Lib/swig.swg

Lines changed: 20 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -442,6 +442,10 @@ namespace std {
442442
* Default char * and C array typemaps
443443
* ----------------------------------------------------------------------------- */
444444

445+
%fragment("<string.h>", "runtime") %{
446+
#include <string.h>
447+
%}
448+
445449
/* Set up the typemap for handling new return strings */
446450

447451
#ifdef __cplusplus
@@ -453,7 +457,7 @@ namespace std {
453457
/* Default typemap for handling char * members */
454458

455459
#ifdef __cplusplus
456-
%typemap(memberin) char * {
460+
%typemap(memberin,fragment="<string.h>") char * {
457461
delete [] $1;
458462
if ($input) {
459463
$1 = ($1_type) (new char[strlen((const char *)$input)+1]);
@@ -462,15 +466,15 @@ namespace std {
462466
$1 = 0;
463467
}
464468
}
465-
%typemap(memberin,warning=SWIGWARN_TYPEMAP_CHARLEAK_MSG) const char * {
469+
%typemap(memberin,warning=SWIGWARN_TYPEMAP_CHARLEAK_MSG,fragment="<string.h>") const char * {
466470
if ($input) {
467471
$1 = ($1_type) (new char[strlen((const char *)$input)+1]);
468472
strcpy((char *)$1, (const char *)$input);
469473
} else {
470474
$1 = 0;
471475
}
472476
}
473-
%typemap(globalin) char * {
477+
%typemap(globalin,fragment="<string.h>") char * {
474478
delete [] $1;
475479
if ($input) {
476480
$1 = ($1_type) (new char[strlen((const char *)$input)+1]);
@@ -479,7 +483,7 @@ namespace std {
479483
$1 = 0;
480484
}
481485
}
482-
%typemap(globalin,warning=SWIGWARN_TYPEMAP_CHARLEAK_MSG) const char * {
486+
%typemap(globalin,warning=SWIGWARN_TYPEMAP_CHARLEAK_MSG,fragment="<string.h>") const char * {
483487
if ($input) {
484488
$1 = ($1_type) (new char[strlen((const char *)$input)+1]);
485489
strcpy((char *)$1, (const char *)$input);
@@ -488,7 +492,7 @@ namespace std {
488492
}
489493
}
490494
#else
491-
%typemap(memberin) char * {
495+
%typemap(memberin,fragment="<string.h>") char * {
492496
free($1);
493497
if ($input) {
494498
$1 = ($1_type) malloc(strlen((const char *)$input)+1);
@@ -497,15 +501,15 @@ namespace std {
497501
$1 = 0;
498502
}
499503
}
500-
%typemap(memberin,warning=SWIGWARN_TYPEMAP_CHARLEAK_MSG) const char * {
504+
%typemap(memberin,warning=SWIGWARN_TYPEMAP_CHARLEAK_MSG,fragment="<string.h>") const char * {
501505
if ($input) {
502506
$1 = ($1_type) malloc(strlen((const char *)$input)+1);
503507
strcpy((char *)$1, (const char *)$input);
504508
} else {
505509
$1 = 0;
506510
}
507511
}
508-
%typemap(globalin) char * {
512+
%typemap(globalin,fragment="<string.h>") char * {
509513
free($1);
510514
if ($input) {
511515
$1 = ($1_type) malloc(strlen((const char *)$input)+1);
@@ -514,7 +518,7 @@ namespace std {
514518
$1 = 0;
515519
}
516520
}
517-
%typemap(globalin,warning=SWIGWARN_TYPEMAP_CHARLEAK_MSG) const char * {
521+
%typemap(globalin,warning=SWIGWARN_TYPEMAP_CHARLEAK_MSG,fragment="<string.h>") const char * {
518522
if ($input) {
519523
$1 = ($1_type) malloc(strlen((const char *)$input)+1);
520524
strcpy((char *)$1, (const char *)$input);
@@ -527,7 +531,7 @@ namespace std {
527531

528532
/* Character array handling */
529533

530-
%typemap(memberin) char [ANY] {
534+
%typemap(memberin,fragment="<string.h>") char [ANY] {
531535
if($input) {
532536
strncpy((char*)$1, (const char *)$input, $1_dim0-1);
533537
$1[$1_dim0-1] = 0;
@@ -536,7 +540,7 @@ namespace std {
536540
}
537541
}
538542

539-
%typemap(globalin) char [ANY] {
543+
%typemap(globalin,fragment="<string.h>") char [ANY] {
540544
if($input) {
541545
strncpy((char*)$1, (const char *)$input, $1_dim0-1);
542546
$1[$1_dim0-1] = 0;
@@ -545,33 +549,33 @@ namespace std {
545549
}
546550
}
547551

548-
%typemap(memberin) char [] {
552+
%typemap(memberin,fragment="<string.h>") char [] {
549553
if ($input) strcpy((char *)$1, (const char *)$input);
550554
else $1[0] = 0;
551555
}
552556

553-
%typemap(globalin) char [] {
557+
%typemap(globalin,fragment="<string.h>") char [] {
554558
if ($input) strcpy((char *)$1, (const char *)$input);
555559
else $1[0] = 0;
556560
}
557561

558562
/* memberin/globalin typemap for arrays. */
559563

560-
%typemap(memberin) SWIGTYPE [ANY] {
564+
%typemap(memberin,fragment="<string.h>") SWIGTYPE [ANY] {
561565
size_t ii;
562566
$1_basetype *b = ($1_basetype *) $1;
563567
for (ii = 0; ii < (size_t)$1_size; ii++) b[ii] = *(($1_basetype *) $input + ii);
564568
}
565569

566-
%typemap(globalin) SWIGTYPE [ANY] {
570+
%typemap(globalin,fragment="<string.h>") SWIGTYPE [ANY] {
567571
size_t ii;
568572
$1_basetype *b = ($1_basetype *) $1;
569573
for (ii = 0; ii < (size_t)$1_size; ii++) b[ii] = *(($1_basetype *) $input + ii);
570574
}
571575

572576
/* memberin/globalin typemap for double arrays. */
573577

574-
%typemap(memberin) SWIGTYPE [ANY][ANY] {
578+
%typemap(memberin,fragment="<string.h>") SWIGTYPE [ANY][ANY] {
575579
$basetype (*inp)[$1_dim1] = ($basetype (*)[$1_dim1])($input);
576580
$basetype (*dest)[$1_dim1] = ($basetype (*)[$1_dim1])($1);
577581
size_t ii = 0;
@@ -583,7 +587,7 @@ namespace std {
583587
}
584588
}
585589

586-
%typemap(globalin) SWIGTYPE [ANY][ANY] {
590+
%typemap(globalin,fragment="<string.h>") SWIGTYPE [ANY][ANY] {
587591
$basetype (*inp)[$1_dim1] = ($basetype (*)[$1_dim1])($input);
588592
$basetype (*dest)[$1_dim1] = ($basetype (*)[$1_dim1])($1);
589593
size_t ii = 0;

0 commit comments

Comments
 (0)