| 1 |
|
| |
| 2 |
|
| /* |
| 3 |
|
| * Simple.xs = part of IPC::Shm::Simple |
| 4 |
|
| * |
| 5 |
|
| * Originally part of IPC::ShareLite by Maurice Aubrey |
| 6 |
|
| * |
| 7 |
|
| * Adapted 2/2004 by Kevin Cody-Little <kcody@cpan.org> |
| 8 |
|
| * |
| 9 |
|
| * This code may be modified or redistributed under the terms |
| 10 |
|
| * of either the Artistic or GNU General Public licenses, at |
| 11 |
|
| * the modifier or redistributor's discretion. |
| 12 |
|
| * |
| 13 |
|
| */ |
| 14 |
|
| |
| 15 |
|
| #ifdef __cplusplus |
| 16 |
|
| extern "C" { |
| 17 |
|
| #endif |
| 18 |
|
| #include "EXTERN.h" |
| 19 |
|
| #include "perl.h" |
| 20 |
|
| #include "XSUB.h" |
| 21 |
|
| #ifdef __cplusplus |
| 22 |
|
| } |
| 23 |
|
| #endif |
| 24 |
|
| |
| 25 |
|
| #include <sys/shm.h> |
| 26 |
|
| #include <sys/sem.h> |
| 27 |
|
| #include <sys/ipc.h> |
| 28 |
|
| #include "sharelite.h" |
| 29 |
|
| |
| 30 |
|
| /* |
| 31 |
|
| * Some perl version compatibility stuff. |
| 32 |
|
| * Taken from HTML::Parser |
| 33 |
|
| */ |
| 34 |
|
| #include "patchlevel.h" |
| 35 |
|
| #if PATCHLEVEL <= 4 /* perl5.004_XX */ |
| 36 |
|
| |
| 37 |
|
| #ifndef PL_sv_undef |
| 38 |
|
| #define PL_sv_undef sv_undef |
| 39 |
|
| #define PL_sv_yes sv_yes |
| 40 |
|
| #endif |
| 41 |
|
| |
| 42 |
|
| #ifndef PL_hexdigit |
| 43 |
|
| #define PL_hexdigit hexdigit |
| 44 |
|
| #endif |
| 45 |
|
| |
| 46 |
|
| #if (PATCHLEVEL == 4 && SUBVERSION <= 4) |
| 47 |
|
| /* The newSVpvn function was introduced in perl5.004_05 */ |
| 48 |
|
| static SV * |
| 49 |
|
| newSVpvn(char *s, STRLEN len) |
| 50 |
|
| { |
| 51 |
|
| register SV *sv = newSV(0); |
| 52 |
|
| sv_setpvn(sv,s,len); |
| 53 |
|
| return sv; |
| 54 |
|
| } |
| 55 |
|
| #endif /* not perl5.004_05 */ |
| 56 |
|
| #endif /* perl5.004_XX */ |
| 57 |
|
| |
| 58 |
|
| MODULE = IPC::Shm::Simple PACKAGE = IPC::Shm::Simple |
| 59 |
|
| |
| 60 |
|
| Share* |
| 61 |
|
| sharelite_shmat(shmid) |
| 62 |
|
| int shmid |
| 63 |
|
| |
| 64 |
|
| Share* |
| 65 |
|
| sharelite_create(key, segsize, flags) |
| 66 |
|
| key_t key |
| 67 |
|
| int segsize |
| 68 |
|
| int flags |
| 69 |
|
| |
| 70 |
|
| Share* |
| 71 |
|
| sharelite_attach(key) |
| 72 |
|
| key_t key |
| 73 |
|
| |
| 74 |
|
| int |
| 75 |
|
| sharelite_shmdt(share) |
| 76 |
|
| Share* share |
| 77 |
|
| |
| 78 |
|
| int |
| 79 |
|
| sharelite_remove(share) |
| 80 |
|
| Share* share |
| 81 |
|
| |
| 82 |
|
| int |
| 83 |
|
| sharelite_lock(share, flags) |
| 84 |
|
| Share* share |
| 85 |
|
| int flags |
| 86 |
|
| |
| 87 |
|
| int |
| 88 |
|
| sharelite_locked(share, flags) |
| 89 |
|
| Share* share |
| 90 |
|
| int flags |
| 91 |
|
| |
| 92 |
|
| int |
| 93 |
|
| sharelite_store(share, data, length) |
| 94 |
|
| Share* share |
| 95 |
|
| char* data |
| 96 |
|
| int length |
| 97 |
|
| |
| 98 |
|
| char* |
| 99 |
|
| sharelite_fetch(share) |
| 100 |
|
| Share* share |
| 101 |
|
| PREINIT: |
| 102 |
|
| char* data; |
| 103 |
|
| int length; |
| 104 |
|
| CODE: |
| 105 |
0 |
| share = (Share *)SvIV(ST(0)); |
| 106 |
0 |
| length = sharelite_fetch(share, &data); |
| 107 |
0 |
| ST(0) = sv_newmortal(); |
| 108 |
0 |
▶ | if (length >= 0) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (length >= 0) { |
0 |
0 |
0 |
|
| 109 |
0 |
| sv_usepvn((SV*)ST(0), data, length); |
| 110 |
|
| } else { |
| 111 |
0 |
| sv_setsv(ST(0), &PL_sv_undef); |
| 112 |
|
| } |
| 113 |
|
| |
| 114 |
|
| int |
| 115 |
|
| sharelite_key(share) |
| 116 |
|
| Share* share |
| 117 |
|
| |
| 118 |
|
| int |
| 119 |
|
| sharelite_shmid(share) |
| 120 |
|
| Share* share |
| 121 |
|
| |
| 122 |
|
| int |
| 123 |
|
| sharelite_flags(share) |
| 124 |
|
| Share* share |
| 125 |
|
| |
| 126 |
|
| int |
| 127 |
|
| sharelite_is_valid(share) |
| 128 |
|
| Share* share |
| 129 |
|
| |
| 130 |
|
| int |
| 131 |
|
| sharelite_length(share) |
| 132 |
|
| Share* share |
| 133 |
|
| |
| 134 |
|
| int |
| 135 |
|
| sharelite_serial(share) |
| 136 |
|
| Share* share |
| 137 |
|
| |
| 138 |
|
| int |
| 139 |
|
| sharelite_nsegments(share) |
| 140 |
|
| Share* share |
| 141 |
|
| |
| 142 |
|
| int |
| 143 |
|
| sharelite_top_seg_size(share) |
| 144 |
|
| Share* share |
| 145 |
|
| |
| 146 |
|
| int |
| 147 |
|
| sharelite_chunk_seg_size(share,size) |
| 148 |
|
| Share* share |
| 149 |
|
| int size |
| 150 |
|
| |
| 151 |
|
| int |
| 152 |
|
| sharelite_nconns(share) |
| 153 |
|
| Share* share |
| 154 |
|
| |
| 155 |
|
| int |
| 156 |
|
| sharelite_nrefs(share) |
| 157 |
|
| Share* share |
| 158 |
|
| |
| 159 |
|
| int |
| 160 |
|
| sharelite_incref(share) |
| 161 |
|
| Share* share |
| 162 |
|
| |
| 163 |
|
| int |
| 164 |
|
| sharelite_decref(share) |
| 165 |
|
| Share* share |
| 166 |
|
| |