Mercurial > pidgin.yaz
comparison plugins/perl/perl-handlers.c @ 6919:1aa771990188
[gaim-migrate @ 7466]
Added support for return values in perl plugin signal callbacks, and for
modifying parameters, in theory (but apparently not in practice. Darn you
perl! Darn you to Dell!)
committer: Tailor Script <tailor@pidgin.im>
author | Christian Hammond <chipx86@chipx86.com> |
---|---|
date | Tue, 23 Sep 2003 22:35:00 +0000 |
parents | 33486b749aa9 |
children | 13f78c350cd3 |
comparison
equal
deleted
inserted
replaced
6918:d4b53b3d20eb | 6919:1aa771990188 |
---|---|
68 void *ret_val = NULL; | 68 void *ret_val = NULL; |
69 int i; | 69 int i; |
70 int count; | 70 int count; |
71 int value_count; | 71 int value_count; |
72 GaimValue *ret_value, **values; | 72 GaimValue *ret_value, **values; |
73 SV **sv_args; | |
74 STRLEN na; | |
73 | 75 |
74 dSP; | 76 dSP; |
75 ENTER; | 77 ENTER; |
76 SAVETMPS; | 78 SAVETMPS; |
77 PUSHMARK(sp); | 79 PUSHMARK(sp); |
78 | 80 |
79 gaim_signal_get_values(handler->instance, handler->signal, | 81 gaim_signal_get_values(handler->instance, handler->signal, |
80 &ret_value, &value_count, &values); | 82 &ret_value, &value_count, &values); |
81 | 83 |
84 sv_args = g_new(SV *, value_count); | |
85 | |
82 for (i = 0; i < value_count; i++) | 86 for (i = 0; i < value_count; i++) |
83 { | 87 { |
84 SV *sv = gaim_perl_sv_from_vargs(values[i], args); | 88 SV *sv = gaim_perl_sv_from_vargs(values[i], args); |
85 | 89 |
86 gaim_debug(GAIM_DEBUG_INFO, "perl", "Pushing arg %p\n", sv); | 90 sv_args[i] = sv; |
87 | 91 |
88 XPUSHs(sv); | 92 XPUSHs(sv); |
89 } | 93 } |
90 | 94 |
91 gaim_debug(GAIM_DEBUG_INFO, "perl", "Pushing data %p\n", handler->data); | |
92 XPUSHs((SV *)handler->data); | 95 XPUSHs((SV *)handler->data); |
93 | 96 |
94 PUTBACK; | 97 PUTBACK; |
95 | 98 |
96 if (ret_value != NULL) | 99 if (ret_value != NULL) |
100 SPAGAIN; | 103 SPAGAIN; |
101 | 104 |
102 if (count != 1) | 105 if (count != 1) |
103 croak("Uh oh! call_sv returned %i != 1", i); | 106 croak("Uh oh! call_sv returned %i != 1", i); |
104 else | 107 else |
105 ret_val = POPs; | 108 { |
109 SV *temp_ret_val = POPs; | |
110 | |
111 switch (gaim_value_get_type(ret_value)) | |
112 { | |
113 case GAIM_TYPE_BOOLEAN: | |
114 ret_val = (void *)SvIV(temp_ret_val); | |
115 break; | |
116 | |
117 case GAIM_TYPE_INT: | |
118 ret_val = (void *)SvIV(temp_ret_val); | |
119 break; | |
120 | |
121 case GAIM_TYPE_UINT: | |
122 ret_val = (void *)SvUV(temp_ret_val); | |
123 break; | |
124 | |
125 case GAIM_TYPE_LONG: | |
126 ret_val = (void *)SvIV(temp_ret_val); | |
127 break; | |
128 | |
129 case GAIM_TYPE_ULONG: | |
130 ret_val = (void *)SvUV(temp_ret_val); | |
131 break; | |
132 | |
133 case GAIM_TYPE_INT64: | |
134 ret_val = (void *)SvIV(temp_ret_val); | |
135 break; | |
136 | |
137 case GAIM_TYPE_UINT64: | |
138 ret_val = (void *)SvUV(temp_ret_val); | |
139 break; | |
140 | |
141 case GAIM_TYPE_STRING: | |
142 ret_val = (void *)SvPV(temp_ret_val, na); | |
143 break; | |
144 | |
145 case GAIM_TYPE_POINTER: | |
146 ret_val = (void *)SvIV(temp_ret_val); | |
147 break; | |
148 | |
149 case GAIM_TYPE_BOXED: | |
150 ret_val = (void *)SvIV(temp_ret_val); | |
151 break; | |
152 | |
153 default: | |
154 ret_val = NULL; | |
155 } | |
156 } | |
106 } | 157 } |
107 else | 158 else |
108 call_sv(handler->callback, G_SCALAR); | 159 call_sv(handler->callback, G_SCALAR); |
109 | 160 |
161 /* See if any parameters changed. */ | |
162 for (i = 0; i < value_count; i++) | |
163 { | |
164 if (gaim_value_is_outgoing(values[i])) | |
165 { | |
166 switch (gaim_value_get_type(values[i])) | |
167 { | |
168 case GAIM_TYPE_BOOLEAN: | |
169 *va_arg(args, gboolean *) = SvIV(sv_args[i]); | |
170 break; | |
171 | |
172 case GAIM_TYPE_INT: | |
173 *va_arg(args, int *) = SvIV(sv_args[i]); | |
174 break; | |
175 | |
176 case GAIM_TYPE_UINT: | |
177 *va_arg(args, unsigned int *) = SvUV(sv_args[i]); | |
178 break; | |
179 | |
180 case GAIM_TYPE_LONG: | |
181 *va_arg(args, long *) = SvIV(sv_args[i]); | |
182 break; | |
183 | |
184 case GAIM_TYPE_ULONG: | |
185 *va_arg(args, unsigned long *) = SvUV(sv_args[i]); | |
186 break; | |
187 | |
188 case GAIM_TYPE_INT64: | |
189 *va_arg(args, gint64 *) = SvIV(sv_args[i]); | |
190 break; | |
191 | |
192 case GAIM_TYPE_UINT64: | |
193 *va_arg(args, guint64 *) = SvUV(sv_args[i]); | |
194 break; | |
195 | |
196 case GAIM_TYPE_STRING: | |
197 /* XXX Memory leak! */ | |
198 *va_arg(args, char **) = SvPV(sv_args[i], na); | |
199 break; | |
200 | |
201 case GAIM_TYPE_POINTER: | |
202 /* XXX Possible memory leak! */ | |
203 *va_arg(args, void **) = (void *)SvIV(sv_args[i]); | |
204 break; | |
205 | |
206 case GAIM_TYPE_BOXED: | |
207 /* Uh.. I dunno. Try this? Likely won't work. Heh. */ | |
208 /* XXX Possible memory leak! */ | |
209 *va_arg(args, void **) = (void *)SvIV(sv_args[i]); | |
210 break; | |
211 | |
212 default: | |
213 return FALSE; | |
214 } | |
215 } | |
216 } | |
217 | |
110 FREETMPS; | 218 FREETMPS; |
111 LEAVE; | 219 LEAVE; |
220 | |
221 g_free(sv_args); | |
222 | |
223 gaim_debug_misc("perl", "ret_val = %p\n", ret_val); | |
112 | 224 |
113 return ret_val; | 225 return ret_val; |
114 } | 226 } |
115 | 227 |
116 static GaimPerlSignalHandler * | 228 static GaimPerlSignalHandler * |