| 1 | = !PerlSwig = |
| 2 | |
| 3 | == To re-SWIG Mapscript with a different version of SWIG == |
| 4 | <contributed by Stephen Lime>: |
| 5 | |
| 6 | (currently (<=3.6, 3.7?) distributed with 1.1) |
| 7 | |
| 8 | cd mapscript/perl |
| 9 | swig -perl5 -shadow mapscript.i |
| 10 | (thanks Steve Lime) |
| 11 | |
| 12 | Then build as usual. |
| 13 | |
| 14 | [Thu Mar 6 16:04:11 EST 2003] Jason Thaxter notes that the README note for perl says to use SWIG Version 1.1 (Build 883), but that didn't work, while version 1.3.17u (current release) seems to create a working module, though with a number of warnings about deprecated SWIG tags... |
| 15 | |
| 16 | Patch required to eliminate mod_perl & strict fatal errors |
| 17 | |
| 18 | http://mapserver.gis.umn.edu/data2/wilma/mapserver-users/0205/msg00068.html |
| 19 | |
| 20 | or a direct link to the SWIG archives |
| 21 | |
| 22 | http://mailman.cs.uchicago.edu/pipermail/swig/2000-March/001227.html |
| 23 | |
| 24 | Offsite discussion redarding the use of null strings as file names |
| 25 | {{{ |
| 26 | > Steve Lime writes: |
| 27 | > > Um, yup it is. Simply switching: |
| 28 | > > |
| 29 | > > if (arg1->name) free((char*)arg1->name); |
| 30 | > > arg1->name = (char *) malloc(strlen(arg2)+1); |
| 31 | > > strcpy((char*)arg1->name,arg2); |
| 32 | > > |
| 33 | > > to: |
| 34 | > > |
| 35 | > > if (arg1->name) free((char*)arg1->name); |
| 36 | > > if(arg2) { |
| 37 | > > arg1->name = (char *) malloc(strlen(arg2)+1); |
| 38 | > > strcpy((char*)arg1->name,arg2); |
| 39 | > > } else |
| 40 | > > arg1->name = NULL; |
| 41 | > > |
| 42 | > > Seems to fix things. Now, how to get these changes made? |
| 43 | > > |
| 44 | > |
| 45 | > This is probably being controlled by a typemap in Lib/swig.swg. |
| 46 | > I'll take a look. |
| 47 | > |
| 48 | }}} |
| 49 | You can try sticking this in your interface (or making mods in |
| 50 | swig.swg). |
| 51 | |
| 52 | Cheers, |
| 53 | |
| 54 | Dave |
| 55 | {{{ |
| 56 | !#perl |
| 57 | /* Default typemap for handling char * members */ |
| 58 | |
| 59 | #ifdef __cplusplus |
| 60 | %typemap(memberin) char * { |
| 61 | if ($1) delete [] $1; |
| 62 | if ($input) { |
| 63 | $1 = ($1_type) (new char[strlen($input)+1]); |
| 64 | strcpy((char *) $1,$input); |
| 65 | } else { |
| 66 | $1 = 0; |
| 67 | } |
| 68 | } |
| 69 | %typemap(memberin,warning="451:Setting const char * member may leak memory.") const char * { |
| 70 | if ($input) { |
| 71 | $1 = ($1_type) (new char[strlen($input)+1]); |
| 72 | strcpy((char *) $1,$input); |
| 73 | } else { |
| 74 | $1 = 0; |
| 75 | } |
| 76 | } |
| 77 | %typemap(globalin) char * { |
| 78 | if ($1) delete [] $1; |
| 79 | if ($input) { |
| 80 | $1 = ($1_type) (new char[strlen($input)+1]); |
| 81 | strcpy((char *) $1,$input); |
| 82 | } else { |
| 83 | $1 = 0; |
| 84 | } |
| 85 | } |
| 86 | %typemap(globalin,warning="451:Setting const char * variable may leak memory.") const char * { |
| 87 | if ($input) { |
| 88 | $1 = ($1_type) (new char[strlen($input)+1]); |
| 89 | strcpy((char *) $1,$input); |
| 90 | } else { |
| 91 | $1 = 0; |
| 92 | } |
| 93 | } |
| 94 | #else |
| 95 | %typemap(memberin) char * { |
| 96 | if ($1) free((char*)$1); |
| 97 | if ($input) { |
| 98 | $1 = ($1_type) malloc(strlen($input)+1); |
| 99 | strcpy((char*)$1,$input); |
| 100 | } else { |
| 101 | $1 = 0; |
| 102 | } |
| 103 | } |
| 104 | %typemap(memberin,warning="451:Setting const char * member may leak memory.") const char * { |
| 105 | if ($input) { |
| 106 | $1 = ($1_type) malloc(strlen($input)+1); |
| 107 | strcpy((char*)$1,$input); |
| 108 | } else { |
| 109 | $1 = 0; |
| 110 | } |
| 111 | } |
| 112 | %typemap(globalin) char * { |
| 113 | if ($1) free((char*)$1); |
| 114 | if ($input) { |
| 115 | $1 = ($1_type) malloc(strlen($input)+1); |
| 116 | strcpy((char*)$1,$input); |
| 117 | } else { |
| 118 | $1 = 0; |
| 119 | } |
| 120 | } |
| 121 | %typemap(globalin,warning="451:Setting const char * variable may leak memory.") const char * { |
| 122 | if ($input) { |
| 123 | $1 = ($1_type) malloc(strlen($input)+1); |
| 124 | strcpy((char*)$1,$input); |
| 125 | } else { |
| 126 | $1 = 0; |
| 127 | } |
| 128 | } |
| 129 | |
| 130 | #endif |
| 131 | }}} |
| 132 | ---- |
| 133 | back to PerlMapScript |