@@ -358,80 +358,6 @@ static void slib_import_routines(slib_t *lib, int comp) {
358358 }
359359}
360360
361- //
362- // build parameter table
363- //
364- static int slib_build_ptable (slib_par_t * ptable ) {
365- int pcount = 0 ;
366- var_t * arg ;
367- bcip_t ofs ;
368-
369- if (code_peek () == kwTYPE_LEVEL_BEGIN ) {
370- code_skipnext ();
371- byte ready = 0 ;
372- do {
373- byte code = code_peek ();
374- switch (code ) {
375- case kwTYPE_EOC :
376- code_skipnext ();
377- break ;
378- case kwTYPE_SEP :
379- code_skipsep ();
380- break ;
381- case kwTYPE_LEVEL_END :
382- ready = 1 ;
383- break ;
384- case kwTYPE_VAR :
385- // variable
386- ofs = prog_ip ;
387- if (code_isvar ()) {
388- // push parameter
389- ptable [pcount ].var_p = code_getvarptr ();
390- ptable [pcount ].byref = 1 ;
391- pcount ++ ;
392- break ;
393- }
394-
395- // restore IP
396- prog_ip = ofs ;
397- // no 'break' here
398- default :
399- // default --- expression (BYVAL ONLY)
400- arg = v_new ();
401- eval (arg );
402- if (!prog_error ) {
403- // push parameter
404- ptable [pcount ].var_p = arg ;
405- ptable [pcount ].byref = 0 ;
406- pcount ++ ;
407- } else {
408- v_free (arg );
409- v_detach (arg );
410- return pcount ;
411- }
412- }
413- if (pcount == MAX_PARAM ) {
414- err_parm_limit (MAX_PARAM );
415- }
416- } while (!ready && !prog_error );
417- // kwTYPE_LEVEL_END
418- code_skipnext ();
419- }
420- return pcount ;
421- }
422-
423- //
424- // free parameter table
425- //
426- static void slib_free_ptable (slib_par_t * ptable , int pcount ) {
427- for (int i = 0 ; i < pcount ; i ++ ) {
428- if (ptable [i ].byref == 0 ) {
429- v_free (ptable [i ].var_p );
430- v_detach (ptable [i ].var_p );
431- }
432- }
433- }
434-
435361//
436362// execute a function or procedure
437363//
@@ -440,13 +366,13 @@ static int slib_exec(slib_t *lib, var_t *ret, int index, int proc) {
440366 int pcount ;
441367 if (code_peek () == kwTYPE_LEVEL_BEGIN ) {
442368 ptable = (slib_par_t * )malloc (sizeof (slib_par_t ) * MAX_PARAM );
443- pcount = slib_build_ptable (ptable );
369+ pcount = plugin_build_ptable (ptable , MAX_PARAM );
444370 } else {
445371 ptable = NULL ;
446372 pcount = 0 ;
447373 }
448374 if (prog_error ) {
449- slib_free_ptable (ptable , pcount );
375+ plugin_free_ptable (ptable , pcount );
450376 free (ptable );
451377 return 0 ;
452378 }
@@ -470,7 +396,7 @@ static int slib_exec(slib_t *lib, var_t *ret, int index, int proc) {
470396
471397 // clean-up
472398 if (ptable ) {
473- slib_free_ptable (ptable , pcount );
399+ plugin_free_ptable (ptable , pcount );
474400 free (ptable );
475401 }
476402
@@ -643,3 +569,71 @@ int plugin_funcexec(int lib_id, int index, var_t *ret) { return -1; }
643569void plugin_free (int lib_id , int cls_id , int id ) {}
644570void plugin_close () {}
645571#endif
572+
573+ int plugin_build_ptable (slib_par_t * ptable , int size ) {
574+ int pcount = 0 ;
575+ var_t * arg ;
576+ bcip_t ofs ;
577+
578+ if (code_peek () == kwTYPE_LEVEL_BEGIN ) {
579+ code_skipnext ();
580+ byte ready = 0 ;
581+ do {
582+ byte code = code_peek ();
583+ switch (code ) {
584+ case kwTYPE_EOC :
585+ code_skipnext ();
586+ break ;
587+ case kwTYPE_SEP :
588+ code_skipsep ();
589+ break ;
590+ case kwTYPE_LEVEL_END :
591+ ready = 1 ;
592+ break ;
593+ case kwTYPE_VAR :
594+ // variable
595+ ofs = prog_ip ;
596+ if (code_isvar ()) {
597+ // push parameter
598+ ptable [pcount ].var_p = code_getvarptr ();
599+ ptable [pcount ].byref = 1 ;
600+ pcount ++ ;
601+ break ;
602+ }
603+
604+ // restore IP
605+ prog_ip = ofs ;
606+ // no 'break' here
607+ default :
608+ // default --- expression (BYVAL ONLY)
609+ arg = v_new ();
610+ eval (arg );
611+ if (!prog_error ) {
612+ // push parameter
613+ ptable [pcount ].var_p = arg ;
614+ ptable [pcount ].byref = 0 ;
615+ pcount ++ ;
616+ } else {
617+ v_free (arg );
618+ v_detach (arg );
619+ return pcount ;
620+ }
621+ }
622+ if (pcount == size ) {
623+ err_parm_limit (size );
624+ }
625+ } while (!ready && !prog_error );
626+ // kwTYPE_LEVEL_END
627+ code_skipnext ();
628+ }
629+ return pcount ;
630+ }
631+
632+ void plugin_free_ptable (slib_par_t * ptable , int pcount ) {
633+ for (int i = 0 ; i < pcount ; i ++ ) {
634+ if (ptable [i ].byref == 0 ) {
635+ v_free (ptable [i ].var_p );
636+ v_detach (ptable [i ].var_p );
637+ }
638+ }
639+ }
0 commit comments