1 /*
2  * pyx.auto.c
3  *
4  * Copyright (C) 2002 Maurizio Umberto Puxeddu, Michael Gogins
5  *
6  * This software is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU Lesser General Public
8  * License as published by the Free Software Foundation; either
9  * version 2.1 of the License, or (at your option) any later version.
10  *
11  * This software is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14  * Lesser General Public License for more details.
15  *
16  * You should have received a copy of the GNU Lesser General Public
17  * License along with this software; if not, write to the Free Software
18  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301 USA
19  */
20 
21 /* Modified from BSD sources for strlcpy */
22 /*
23  * Copyright (c) 1998 Todd C. Miller <Todd.Miller@courtesan.com>
24  *
25  * Permission to use, copy, modify, and distribute this software for any
26  * purpose with or without fee is hereby granted, provided that the above
27  * copyright notice and this permission notice appear in all copies.
28  */
29 /* modifed for speed -- JPff */
30 char *
strNcpy(char * dst,const char * src,size_t siz)31 strNcpy(char *dst, const char *src, size_t siz)
32 {
33     char *d = dst;
34     const char *s = src;
35     size_t n = siz;
36 
37     /* Copy as many bytes as will fit or until NULL */
38     if (n != 0) {
39       while (--n != 0) {
40         if ((*d++ = *s++) == '\0')
41           break;
42       }
43     }
44 
45     /* Not enough room in dst, add NUL */
46     if (n == 0) {
47       if (siz != 0)
48         *d = '\0';                /* NUL-terminate dst */
49 
50       //while (*s++) ;
51     }
52     return dst;        /* count does not include NUL */
53 }
54 
55 
pyexec_krate(CSOUND * csound,PYEXEC * p)56 static int pyexec_krate(CSOUND *csound, PYEXEC *p)
57 {
58     char      source[1024];
59     PyObject  *result  = NULL;
60     int *py_initialize_done;
61     if ((py_initialize_done =
62          csound->QueryGlobalVariable(csound,"PY_INITIALIZE")) == NULL ||
63         *py_initialize_done == 0)
64       return NOTOK;
65 
66     strNcpy(source, (char*) p->string->data,1024); //source[1023] = '\0';
67 
68     result = exec_file_in_given_context(csound, source, 0);
69     if (result == NULL) {
70       return pyErrMsg(p, "python exception");
71     }
72     Py_DECREF(result);
73     return OK;
74 }
75 
76 #if 0
77 static int pyexeci_irate(CSOUND *csound, PYEXEC *p)
78 {
79     char      source[1024];
80     PyObject  *result;
81     int *py_initialize_done;
82     if((py_initialize_done =
83         csound->QueryGlobalVariable(csound,"PY_INITIALIZE")) == NULL ||
84        *py_initialize_done == 0)
85       return NOTOK;
86 
87     strNcpy(source, (char*) p->string->data, 1024); //source[1023] = '\0';
88 
89     result = exec_file_in_given_context(csound, source, 0);
90     if (result == NULL) {
91       return pyErrMsg(p, "python exception");
92     }
93     Py_DECREF(result);
94   return OK;
95 }
96 #endif
97 
pylexec_irate(CSOUND * csound,PYEXEC * p)98 static int pylexec_irate(CSOUND *csound, PYEXEC *p)
99 {
100     int *py_initialize_done;
101     if((py_initialize_done =
102         csound->QueryGlobalVariable(csound,"PY_INITIALIZE")) == NULL ||
103        *py_initialize_done == 0)
104       return NOTOK;
105     create_private_namespace_if_needed(&p->h);
106     return OK;
107 }
108 
pylexec_krate(CSOUND * csound,PYEXEC * p)109 static int pylexec_krate(CSOUND *csound, PYEXEC *p)
110 {
111     char      source[1024];
112     PyObject  *result;
113     int *py_initialize_done;
114     if((py_initialize_done =
115         csound->QueryGlobalVariable(csound,"PY_INITIALIZE")) == NULL ||
116        *py_initialize_done == 0)
117       return NOTOK;
118 
119     strNcpy(source, (char*) p->string->data, 1024); //source[1023]='\0';
120 
121     result = exec_file_in_given_context(csound, source, GETPYLOCAL(p->h.insdshead));
122     if (result == NULL) {
123       return pyErrMsg(p, "python exception");
124     }
125     Py_DECREF(result);
126     return OK;
127 }
128 
pylexeci_irate(CSOUND * csound,PYEXEC * p)129 static int pylexeci_irate(CSOUND *csound, PYEXEC *p)
130 {
131     char      source[1024];
132     PyObject  *result;
133     int *py_initialize_done;
134     if((py_initialize_done =
135         csound->QueryGlobalVariable(csound,"PY_INITIALIZE")) == NULL ||
136        *py_initialize_done == 0)
137       return NOTOK;
138 
139     create_private_namespace_if_needed(&p->h);
140 
141     strNcpy(source, (char*) p->string->data, 1024); //source[1023]='\0';
142 
143     result = exec_file_in_given_context(csound, source, GETPYLOCAL(p->h.insdshead));
144     if (result == NULL) {
145       return pyErrMsg(p, "python exception");
146     }
147     Py_DECREF(result);
148     return OK;
149 }
150 
pyexect_krate(CSOUND * csound,PYEXECT * p)151 static int pyexect_krate(CSOUND *csound, PYEXECT *p)
152 {
153     char      source[1024];
154     PyObject  *result;
155     int *py_initialize_done;
156     if((py_initialize_done =
157         csound->QueryGlobalVariable(csound,"PY_INITIALIZE")) == NULL ||
158        *py_initialize_done == 0)
159       return NOTOK;
160 
161     if (!*p->trigger)
162       return OK;
163 
164     strNcpy(source, (char*) p->string->data, 1024); //source[1023]='\0';
165 
166     result = exec_file_in_given_context(csound, source, 0);
167     if (result == NULL) {
168       return pyErrMsg(p, "python exception");
169     }
170     Py_DECREF(result);
171     return OK;
172 }
173 
pylexect_irate(CSOUND * csound,PYEXECT * p)174 static int pylexect_irate(CSOUND *csound, PYEXECT *p)
175 {
176     int *py_initialize_done;
177     if((py_initialize_done =
178         csound->QueryGlobalVariable(csound,"PY_INITIALIZE")) == NULL ||
179        *py_initialize_done == 0)
180       return NOTOK;
181     create_private_namespace_if_needed(&p->h);
182     return OK;
183 }
184 
pylexect_krate(CSOUND * csound,PYEXECT * p)185 static int pylexect_krate(CSOUND *csound, PYEXECT *p)
186 {
187     char      source[1024];
188     PyObject  *result;
189     int *py_initialize_done;
190     if((py_initialize_done =
191         csound->QueryGlobalVariable(csound,"PY_INITIALIZE")) == NULL ||
192        *py_initialize_done == 0)
193       return NOTOK;
194 
195     if (!*p->trigger)
196       return OK;
197 
198     strNcpy(source, (char*) p->string->data, 1024); //source[1023]='\0';
199 
200     result = exec_file_in_given_context(csound, source, GETPYLOCAL(p->h.insdshead));
201     if (result == NULL) {
202       return pyErrMsg(p, "python exception");
203     }
204     Py_DECREF(result);
205     return OK;
206 }
207 
pyrun_krate(CSOUND * csound,PYRUN * p)208 static int pyrun_krate(CSOUND *csound, PYRUN *p)
209 {
210     char      source[40960];
211     PyObject  *result;
212     int *py_initialize_done;
213     if((py_initialize_done =
214         csound->QueryGlobalVariable(csound,"PY_INITIALIZE")) == NULL ||
215        *py_initialize_done == 0)
216       return NOTOK;
217 
218     strNcpy(source, (char*) p->string->data, 40960); //source[40959]='\0';
219 
220     result = run_statement_in_given_context(source, 0);
221     if (result == NULL) {
222       return pyErrMsg(p, "python exception");
223     }
224     Py_DECREF(result);
225     return OK;
226 }
227 
pyruni_irate(CSOUND * csound,PYRUN * p)228 static int pyruni_irate(CSOUND *csound, PYRUN *p)
229 {
230     char      source[40960];
231     PyObject  *result;
232     int *py_initialize_done;
233     if((py_initialize_done =
234         csound->QueryGlobalVariable(csound,"PY_INITIALIZE")) == NULL ||
235        *py_initialize_done == 0)
236       return NOTOK;
237 
238     strNcpy(source, (char*) p->string->data, 40960);//source[40959]='\0';
239 
240     result = run_statement_in_given_context(source, 0);
241     if (result == NULL) {
242       return pyErrMsg(p, "python exception");
243     }
244     Py_DECREF(result);
245     return OK;
246 }
247 
pylrun_irate(CSOUND * csound,PYRUN * p)248 static int pylrun_irate(CSOUND *csound, PYRUN *p)
249 {
250     int *py_initialize_done;
251     if((py_initialize_done =
252         csound->QueryGlobalVariable(csound,"PY_INITIALIZE")) == NULL ||
253        *py_initialize_done == 0)
254       return NOTOK;
255     create_private_namespace_if_needed(&p->h);
256     return OK;
257 }
258 
pylrun_krate(CSOUND * csound,PYRUN * p)259 static int pylrun_krate(CSOUND *csound, PYRUN *p)
260 {
261     char      source[40960];
262     PyObject  *result;
263     int *py_initialize_done;
264     if((py_initialize_done =
265         csound->QueryGlobalVariable(csound,"PY_INITIALIZE")) == NULL ||
266        *py_initialize_done == 0)
267       return NOTOK;
268 
269     strNcpy(source, (char*) p->string->data, 40960); //source[40959]='\0';
270 
271     result = run_statement_in_given_context(source, GETPYLOCAL(p->h.insdshead));
272     if (result == NULL) {
273       return pyErrMsg(p, "python exception");
274     }
275     Py_DECREF(result);
276     return OK;
277 }
278 
pylruni_irate(CSOUND * csound,PYRUN * p)279 static int pylruni_irate(CSOUND *csound, PYRUN *p)
280 {
281     char      source[40960];
282     PyObject  *result;
283     int *py_initialize_done;
284     if((py_initialize_done =
285         csound->QueryGlobalVariable(csound,"PY_INITIALIZE")) == NULL ||
286        *py_initialize_done == 0)
287       return NOTOK;
288     create_private_namespace_if_needed(&p->h);
289 
290     strNcpy(source, (char*) p->string->data, 40960); //source[40959]='\0';
291 
292     result = run_statement_in_given_context(source, GETPYLOCAL(p->h.insdshead));
293     if (result == NULL) {
294       return pyErrMsg(p, "python exception");
295     }
296     Py_DECREF(result);
297     return OK;
298 }
299 
pyrunt_krate(CSOUND * csound,PYRUNT * p)300 static int pyrunt_krate(CSOUND *csound, PYRUNT *p)
301 {
302     char      source[40960];
303     PyObject  *result;
304     int *py_initialize_done;
305     if((py_initialize_done =
306         csound->QueryGlobalVariable(csound,"PY_INITIALIZE")) == NULL ||
307        *py_initialize_done == 0)
308       return NOTOK;
309     if (!*p->trigger)
310       return OK;
311 
312     strNcpy(source, (char*) p->string->data, 40960); //source[40959]='\0';
313 
314     result = run_statement_in_given_context(source, 0);
315     if (result == NULL) {
316       return pyErrMsg(p, "python exception");
317     }
318     Py_DECREF(result);
319     return OK;
320 }
321 
pylrunt_irate(CSOUND * csound,PYRUNT * p)322 static int pylrunt_irate(CSOUND *csound, PYRUNT *p)
323 {
324     int *py_initialize_done;
325     if((py_initialize_done =
326         csound->QueryGlobalVariable(csound,"PY_INITIALIZE")) == NULL ||
327        *py_initialize_done == 0)
328       return NOTOK;
329     create_private_namespace_if_needed(&p->h);
330     return OK;
331 }
332 
pylrunt_krate(CSOUND * csound,PYRUNT * p)333 static int pylrunt_krate(CSOUND *csound, PYRUNT *p)
334 {
335     char      source[40960];
336     PyObject  *result;
337     int *py_initialize_done;
338     if((py_initialize_done =
339         csound->QueryGlobalVariable(csound,"PY_INITIALIZE")) == NULL ||
340        *py_initialize_done == 0)
341       return NOTOK;
342     if (!*p->trigger)
343       return OK;
344 
345     strNcpy(source, (char*) p->string->data, 40960); //source[40959]='\0';
346 
347     result = run_statement_in_given_context(source, GETPYLOCAL(p->h.insdshead));
348     if (result == NULL) {
349       return pyErrMsg(p, "python exception");
350     }
351     Py_DECREF(result);
352     return OK;
353 }
354 
pyeval_krate(CSOUND * csound,PYEVAL * p)355 static int pyeval_krate(CSOUND *csound, PYEVAL *p)
356 {
357     char      source[1024];
358     PyObject  *result;
359     int *py_initialize_done;
360     if((py_initialize_done =
361         csound->QueryGlobalVariable(csound,"PY_INITIALIZE")) == NULL ||
362        *py_initialize_done == 0)
363       return NOTOK;
364     strNcpy(source, (char*) p->string->data, 1024);//source[1023]='\0';
365 
366     result = eval_string_in_given_context(source, 0);
367     if (result == NULL) {
368       return pyErrMsg(p, "python exception");
369     }
370     else if (!PyFloat_Check(result)) {
371       errMsg(p, "expression must evaluate in a float");
372     }
373     else {
374       *p->result = PyFloat_AsDouble(result);
375     }
376     Py_DECREF(result);
377     return OK;
378 }
379 
380 #if 0
381 static int pyevali_irate(CSOUND *csound, PYEVAL *p)
382 {
383     char      source[1024];
384     PyObject  *result;
385     int *py_initialize_done;
386     if((py_initialize_done =
387         csound->QueryGlobalVariable(csound,"PY_INITIALIZE")) == NULL ||
388        *py_initialize_done == 0)
389       return NOTOK;
390     strNcpy(source, (char*) p->string->data, 1024); //source[1023]='\0';
391 
392     result = eval_string_in_given_context(source, 0);
393     if (result == NULL) {
394       return pyErrMsg(p, "python exception");
395     }
396     else if (!PyFloat_Check(result)) {
397       errMsg(p, "expression must evaluate in a float");
398     }
399     else {
400       *p->result = PyFloat_AsDouble(result);
401     }
402     Py_DECREF(result);
403     return OK;
404 }
405 #endif
406 
pyleval_irate(CSOUND * csound,PYEVAL * p)407 static int pyleval_irate(CSOUND *csound, PYEVAL *p)
408 {
409     int *py_initialize_done;
410     if((py_initialize_done =
411         csound->QueryGlobalVariable(csound,"PY_INITIALIZE")) == NULL ||
412        *py_initialize_done == 0)
413       return NOTOK;
414     create_private_namespace_if_needed(&p->h);
415     return OK;
416 }
417 
pyleval_krate(CSOUND * csound,PYEVAL * p)418 static int pyleval_krate(CSOUND *csound, PYEVAL *p)
419 {
420     char      source[1024];
421     PyObject  *result;
422     int *py_initialize_done;
423     if((py_initialize_done =
424         csound->QueryGlobalVariable(csound,"PY_INITIALIZE")) == NULL ||
425        *py_initialize_done == 0)
426       return NOTOK;
427     strNcpy(source, (char*) p->string->data, 1024); //source[1023]='\0';
428 
429     result = eval_string_in_given_context(source, GETPYLOCAL(p->h.insdshead));
430     if (result == NULL) {
431       return pyErrMsg(p, "python exception");
432     }
433     else if (!PyFloat_Check(result)) {
434       errMsg(p, "expression must evaluate in a float");
435     }
436     else {
437       *p->result = PyFloat_AsDouble(result);
438     }
439     Py_DECREF(result);
440     return OK;
441 }
442 
pylevali_irate(CSOUND * csound,PYEVAL * p)443 static int pylevali_irate(CSOUND *csound, PYEVAL *p)
444 {
445     char      source[1024];
446     PyObject  *result = NULL;
447     int *py_initialize_done;
448     if((py_initialize_done =
449         csound->QueryGlobalVariable(csound,"PY_INITIALIZE")) == NULL ||
450        *py_initialize_done == 0)
451       return NOTOK;
452     create_private_namespace_if_needed(&p->h);
453 
454     strNcpy(source, (char*) p->string->data, 1024); //source[1023]='\0';
455     result = eval_string_in_given_context(source, GETPYLOCAL(p->h.insdshead));
456     if (result == NULL) {
457       return pyErrMsg(p, "python exception");
458     }
459     else if (!PyFloat_Check(result)) {
460       errMsg(p, "expression must evaluate in a float");
461     }
462     else {
463       *p->result = PyFloat_AsDouble(result);
464     }
465     Py_DECREF(result);
466     return OK;
467 }
468 
pyevalt_krate(CSOUND * csound,PYEVALT * p)469 static int pyevalt_krate(CSOUND *csound, PYEVALT *p)
470 {
471     char      source[1024];
472     PyObject  *result  = NULL;
473     int *py_initialize_done;
474     if((py_initialize_done =
475         csound->QueryGlobalVariable(csound,"PY_INITIALIZE")) == NULL ||
476        *py_initialize_done == 0)
477       return NOTOK;
478     if (!*p->trigger) {
479       *p->result = p->oresult;
480       return OK;
481     }
482 
483     strNcpy(source, (char*) p->string->data, 1024); //source[1023]='\0';
484     result = eval_string_in_given_context(source, 0);
485     if (result == NULL) {
486       return pyErrMsg(p, "python exception");
487     }
488     else if (!PyFloat_Check(result)) {
489       errMsg(p, "expression must evaluate in a float");
490     }
491     else {
492       *p->result = PyFloat_AsDouble(result);
493       p->oresult = *p->result;
494     }
495     Py_DECREF(result);
496     return OK;
497 }
498 
pylevalt_irate(CSOUND * csound,PYEVALT * p)499 static int pylevalt_irate(CSOUND *csound, PYEVALT *p)
500 {
501     int *py_initialize_done;
502     if((py_initialize_done =
503         csound->QueryGlobalVariable(csound,"PY_INITIALIZE")) == NULL ||
504        *py_initialize_done == 0)
505       return NOTOK;
506     create_private_namespace_if_needed(&p->h);
507     return OK;
508 }
509 
pylevalt_krate(CSOUND * csound,PYEVALT * p)510 static int pylevalt_krate(CSOUND *csound, PYEVALT *p)
511 {
512     char      source[1024];
513     PyObject  *result  = NULL;
514     int *py_initialize_done;
515     if((py_initialize_done =
516         csound->QueryGlobalVariable(csound,"PY_INITIALIZE")) == NULL ||
517        *py_initialize_done == 0)
518       return NOTOK;
519     if (!*p->trigger) {
520       *p->result = p->oresult;
521       return OK;
522     }
523 
524     strNcpy(source, (char*) p->string->data, 1024); //source[1023]='\0';
525     result = eval_string_in_given_context(source, GETPYLOCAL(p->h.insdshead));
526     if (result == NULL) {
527       return pyErrMsg(p, "python exception");
528     }
529     else if (!PyFloat_Check(result)) {
530       errMsg(p, "expression must evaluate in a float");
531     }
532     else {
533       *p->result = PyFloat_AsDouble(result);
534       p->oresult = *p->result;
535     }
536     Py_DECREF(result);
537     return OK;
538 }
539 
pyassign_krate(CSOUND * csound,PYASSIGN * p)540 static int pyassign_krate(CSOUND *csound, PYASSIGN *p)
541 {
542     char      source[1024];
543     PyObject  *result = NULL;
544     int *py_initialize_done;
545     if((py_initialize_done =
546         csound->QueryGlobalVariable(csound,"PY_INITIALIZE")) == NULL ||
547        *py_initialize_done == 0)
548       return NOTOK;
549     snprintf(source, 1024, "%s = %f", (char*) p->string->data, *p->value);
550 
551     result = run_statement_in_given_context(source, 0);
552     if (result == NULL) {
553       return pyErrMsg(p, "python exception");
554     }
555     Py_DECREF(result);
556     return OK;
557 }
558 
559 #if 0
560 static int pyassigni_irate(CSOUND *csound, PYASSIGN *p)
561 {
562     char      source[1024];
563     PyObject  *result = NULL;
564     int *py_initialize_done;
565     if((py_initialize_done =
566         csound->QueryGlobalVariable(csound,"PY_INITIALIZE")) == NULL ||
567        *py_initialize_done == 0)
568       return NOTOK;
569     snprintf(source, 1024, "%s = %f", (char*) p->string->data, *p->value);
570 
571     result = run_statement_in_given_context(source, 0);
572     if (result == NULL) {
573       return pyErrMsg(p, "python exception");
574     }
575     Py_DECREF(result);
576     return OK;
577 }
578 #endif
579 
pylassign_irate(CSOUND * csound,PYASSIGN * p)580 static int pylassign_irate(CSOUND *csound, PYASSIGN *p)
581 {
582     int *py_initialize_done;
583     if((py_initialize_done =
584         csound->QueryGlobalVariable(csound,"PY_INITIALIZE")) == NULL ||
585        *py_initialize_done == 0)
586       return NOTOK;
587     create_private_namespace_if_needed(&p->h);
588     return OK;
589 }
590 
pylassign_krate(CSOUND * csound,PYASSIGN * p)591 static int pylassign_krate(CSOUND *csound, PYASSIGN *p)
592 {
593     char      source[1024];
594     PyObject  *result = NULL;
595     int *py_initialize_done;
596     if((py_initialize_done =
597         csound->QueryGlobalVariable(csound,"PY_INITIALIZE")) == NULL ||
598        *py_initialize_done == 0)
599       return NOTOK;
600     snprintf(source, 1024, "%s = %f", (char*) p->string->data, *p->value);
601 
602     result = run_statement_in_given_context(source, GETPYLOCAL(p->h.insdshead));
603     if (result == NULL) {
604       return pyErrMsg(p, "python exception");
605     }
606     Py_DECREF(result);
607     return OK;
608 }
609 
pylassigni_irate(CSOUND * csound,PYASSIGN * p)610 static int pylassigni_irate(CSOUND *csound, PYASSIGN *p)
611 {
612     char      source[1024];
613     PyObject  *result = NULL;
614     int *py_initialize_done;
615     if((py_initialize_done =
616         csound->QueryGlobalVariable(csound,"PY_INITIALIZE")) == NULL ||
617        *py_initialize_done == 0)
618       return NOTOK;
619     create_private_namespace_if_needed(&p->h);
620 
621     snprintf(source, 1024, "%s = %f", (char*) p->string->data, *p->value);
622 
623     result = run_statement_in_given_context(source, GETPYLOCAL(p->h.insdshead));
624     if (result == NULL) {
625       return pyErrMsg(p, "python exception");
626     }
627     Py_DECREF(result);
628     return OK;
629 }
630 
pyassignt_krate(CSOUND * csound,PYASSIGNT * p)631 static int pyassignt_krate(CSOUND *csound, PYASSIGNT *p)
632 {
633     char      source[1024];
634     PyObject  *result = NULL;
635     int *py_initialize_done;
636     if((py_initialize_done =
637         csound->QueryGlobalVariable(csound,"PY_INITIALIZE")) == NULL ||
638        *py_initialize_done == 0)
639       return NOTOK;
640     if (!*p->trigger)
641       return OK;
642 
643     snprintf(source, 1024, "%s = %f", (char*) p->string->data, *p->value);
644 
645     result = run_statement_in_given_context(source, 0);
646     if (result == NULL) {
647       return pyErrMsg(p, "python exception");
648     }
649     Py_DECREF(result);
650     return OK;
651 }
652 
pylassignt_irate(CSOUND * csound,PYASSIGNT * p)653 static int pylassignt_irate(CSOUND *csound, PYASSIGNT *p)
654 {
655     int *py_initialize_done;
656     if((py_initialize_done =
657         csound->QueryGlobalVariable(csound,"PY_INITIALIZE")) == NULL ||
658        *py_initialize_done == 0)
659       return NOTOK;
660     create_private_namespace_if_needed(&p->h);
661     return OK;
662 }
663 
pylassignt_krate(CSOUND * csound,PYASSIGNT * p)664 static int pylassignt_krate(CSOUND *csound, PYASSIGNT *p)
665 {
666     char      source[1024];
667     PyObject  *result = NULL;
668     int *py_initialize_done;
669     if ((py_initialize_done =
670          csound->QueryGlobalVariable(csound,"PY_INITIALIZE")) == NULL ||
671         *py_initialize_done == 0)
672       return NOTOK;
673     if (!*p->trigger)
674       return OK;
675 
676     snprintf(source, 1024, "%s = %f", (char*) p->string->data, *p->value);
677 
678     result = run_statement_in_given_context(source, GETPYLOCAL(p->h.insdshead));
679     if (result == NULL) {
680       return pyErrMsg(p, "python exception");
681     }
682     Py_DECREF(result);
683     return OK;
684 }
685