comparison plugins/perl/perl-handlers.c @ 6921:11d05ddf30a3

[gaim-migrate @ 7468] Eh, okay, some more new perl code. You still can't modify signal params, but this is more correct and less leaky. committer: Tailor Script <tailor@pidgin.im>
author Christian Hammond <chipx86@chipx86.com>
date Wed, 24 Sep 2003 00:52:16 +0000
parents 13f78c350cd3
children d69bc8debac7
comparison
equal deleted inserted replaced
6920:13f78c350cd3 6921:11d05ddf30a3
59 destroy_timeout_handler(handler); 59 destroy_timeout_handler(handler);
60 60
61 return 0; 61 return 0;
62 } 62 }
63 63
64 typedef void *DATATYPE;
65
64 static void * 66 static void *
65 perl_signal_cb(va_list args, void *data) 67 perl_signal_cb(va_list args, void *data)
66 { 68 {
67 GaimPerlSignalHandler *handler = (GaimPerlSignalHandler *)data; 69 GaimPerlSignalHandler *handler = (GaimPerlSignalHandler *)data;
68 void *ret_val = NULL; 70 void *ret_val = NULL;
69 int i; 71 int i;
70 int count; 72 int count;
71 int value_count; 73 int value_count;
72 GaimValue *ret_value, **values; 74 GaimValue *ret_value, **values;
73 SV **sv_args; 75 SV **sv_args;
74 void **copy_args; 76 DATATYPE **copy_args;
77 STRLEN na;
75 78
76 dSP; 79 dSP;
77 ENTER; 80 ENTER;
78 SAVETMPS; 81 SAVETMPS;
79 PUSHMARK(sp); 82 PUSHMARK(sp);
80 83
81 gaim_signal_get_values(handler->instance, handler->signal, 84 gaim_signal_get_values(handler->instance, handler->signal,
82 &ret_value, &value_count, &values); 85 &ret_value, &value_count, &values);
83 86
84 sv_args = g_new(SV *, value_count); 87 sv_args = g_new(SV *, value_count);
85 copy_args = g_new(void *, value_count); 88 copy_args = g_new(void **, value_count);
86 89
87 for (i = 0; i < value_count; i++) 90 for (i = 0; i < value_count; i++)
88 { 91 {
89 sv_args[i] = gaim_perl_sv_from_vargs(values[i], &args, &copy_args[i]); 92 sv_args[i] = sv_2mortal(gaim_perl_sv_from_vargs(values[i],
93 &args, &copy_args[i]));
90 94
91 XPUSHs(sv_args[i]); 95 XPUSHs(sv_args[i]);
92 } 96 }
93 97
94 XPUSHs((SV *)handler->data); 98 XPUSHs((SV *)handler->data);
95 99
96 PUTBACK; 100 PUTBACK;
97 101
98 if (ret_value != NULL) 102 if (ret_value != NULL)
99 { 103 {
100 count = call_sv(handler->callback, G_SCALAR); 104 count = call_sv(handler->callback, G_EVAL | G_SCALAR);
101 105
102 SPAGAIN; 106 SPAGAIN;
103 107
104 if (count != 1) 108 if (count != 1)
105 croak("Uh oh! call_sv returned %i != 1", i); 109 croak("Uh oh! call_sv returned %i != 1", i);
106 else 110 else
107 ret_val = gaim_perl_data_from_sv(ret_value, POPs); 111 ret_val = gaim_perl_data_from_sv(ret_value, POPs);
108 } 112 }
109 else 113 else
114 {
110 call_sv(handler->callback, G_SCALAR); 115 call_sv(handler->callback, G_SCALAR);
116
117 SPAGAIN;
118 }
119
120 if (SvTRUE(ERRSV))
121 {
122 gaim_debug_error("perl", "Perl function exited abnormally: %s\n",
123 SvPV(ERRSV, na));
124 }
111 125
112 /* See if any parameters changed. */ 126 /* See if any parameters changed. */
113 for (i = 0; i < value_count; i++) 127 for (i = 0; i < value_count; i++)
114 { 128 {
115 if (gaim_value_is_outgoing(values[i])) 129 if (gaim_value_is_outgoing(values[i]))
116 { 130 {
131 switch (gaim_value_get_type(values[i]))
132 {
133 case GAIM_TYPE_BOOLEAN:
134 *((gboolean *)copy_args[i]) = SvIV(sv_args[i]);
135 break;
136
137 case GAIM_TYPE_INT:
138 *((int *)copy_args[i]) = SvIV(sv_args[i]);
139 break;
140
141 case GAIM_TYPE_UINT:
142 *((unsigned int *)copy_args[i]) = SvUV(sv_args[i]);
143 break;
144
145 case GAIM_TYPE_LONG:
146 *((long *)copy_args[i]) = SvIV(sv_args[i]);
147 break;
148
149 case GAIM_TYPE_ULONG:
150 *((unsigned long *)copy_args[i]) = SvUV(sv_args[i]);
151 break;
152
153 case GAIM_TYPE_INT64:
154 *((gint64 *)copy_args[i]) = SvIV(sv_args[i]);
155 break;
156
157 case GAIM_TYPE_UINT64:
158 *((guint64 *)copy_args[i]) = SvUV(sv_args[i]);
159 break;
160
161 case GAIM_TYPE_STRING:
162 gaim_debug_misc("perl", "Copying over %s\n",
163 *((char **)copy_args[i]));
164 g_free(*((char **)copy_args[i]));
165 *((char **)copy_args[i]) = g_strdup(SvPV(sv_args[i], na));
166 gaim_debug_misc("perl", "New value: %s\n",
167 *((char **)copy_args[i]));
168 break;
169
170 case GAIM_TYPE_POINTER:
171 *((void **)copy_args[i]) = (void *)SvIV(sv_args[i]);
172 break;
173
174 case GAIM_TYPE_BOXED:
175 *((void **)copy_args[i]) = (void *)SvIV(sv_args[i]);
176 break;
177
178 default:
179 break;
180 }
181
182 #if 0
117 *((void **)copy_args[i]) = gaim_perl_data_from_sv(values[i], 183 *((void **)copy_args[i]) = gaim_perl_data_from_sv(values[i],
118 sv_args[i]); 184 sv_args[i]);
185 #endif
119 } 186 }
120 } 187 }
121 188
189 PUTBACK;
122 FREETMPS; 190 FREETMPS;
123 LEAVE; 191 LEAVE;
124 192
125 g_free(sv_args); 193 g_free(sv_args);
126 g_free(copy_args); 194 g_free(copy_args);