@@ -349,8 +349,10 @@ class Function(object):
349349 elif type_ == lib.TA_OptInput_IntegerRange or type_ == lib.TA_OptInput_IntegerList:
350350 __ta_setOptInputParamInteger(holder, i, value)
351351
352- lookback = __ta_getLookback(holder)
353- __ta_paramHolderFree(holder)
352+ try :
353+ lookback = __ta_getLookback(holder)
354+ finally :
355+ __ta_paramHolderFree(holder)
354356 return lookback
355357
356358 @property
@@ -566,23 +568,39 @@ def _ta_getGroupTable():
566568 Returns the list of available TALIB function group names. *slow*
567569 """
568570 cdef lib.TA_StringTable * table
569- _ta_check_success(' TA_GroupTableAlloc' , lib.TA_GroupTableAlloc(& table))
570- groups = []
571- for i in xrange (table.size):
572- groups.append(deref(& table.string[i]))
573- _ta_check_success(' TA_GroupTableFree' , lib.TA_GroupTableFree(table))
571+ cdef TA_RetCode retCode
572+ with _TA_ReadLease():
573+ with nogil:
574+ retCode = lib.TA_GroupTableAlloc(& table)
575+ _ta_check_success(' TA_GroupTableAlloc' , retCode)
576+ try :
577+ groups = []
578+ for i in xrange (table.size):
579+ groups.append(deref(& table.string[i]))
580+ finally :
581+ with nogil:
582+ retCode = lib.TA_GroupTableFree(table)
583+ _ta_check_success(' TA_GroupTableFree' , retCode)
574584 return groups
575585
576586def _ta_getFuncTable (char *group ):
577587 """
578588 Returns a list of the functions for the specified group name. *slow*
579589 """
580590 cdef lib.TA_StringTable * table
581- _ta_check_success(' TA_FuncTableAlloc' , lib.TA_FuncTableAlloc(group, & table))
582- functions = []
583- for i in xrange (table.size):
584- functions.append(deref(& table.string[i]))
585- _ta_check_success(' TA_FuncTableFree' , lib.TA_FuncTableFree(table))
591+ cdef TA_RetCode retCode
592+ with _TA_ReadLease():
593+ with nogil:
594+ retCode = lib.TA_FuncTableAlloc(group, & table)
595+ _ta_check_success(' TA_FuncTableAlloc' , retCode)
596+ try :
597+ functions = []
598+ for i in xrange (table.size):
599+ functions.append(deref(& table.string[i]))
600+ finally :
601+ with nogil:
602+ retCode = lib.TA_FuncTableFree(table)
603+ _ta_check_success(' TA_FuncTableFree' , retCode)
586604 return functions
587605
588606def __get_flags (int flag , dict flags_lookup_dict ):
@@ -644,7 +662,11 @@ def _ta_getFuncInfo(char *function_name):
644662 group, help, flags, num_inputs, num_opt_inputs and num_outputs.
645663 """
646664 cdef const lib.TA_FuncInfo * info
647- retCode = lib.TA_GetFuncInfo(__ta_getFuncHandle(function_name), & info)
665+ cdef const lib.TA_FuncHandle * handle = __ta_getFuncHandle(function_name)
666+ cdef TA_RetCode retCode
667+ with _TA_ReadLease():
668+ with nogil:
669+ retCode = lib.TA_GetFuncInfo(handle, & info)
648670 _ta_check_success(' TA_GetFuncInfo' , retCode)
649671
650672 return {
@@ -663,7 +685,11 @@ def _ta_getInputParameterInfo(char *function_name, int idx):
663685 keys: name and flags.
664686 """
665687 cdef const lib.TA_InputParameterInfo * info
666- retCode = lib.TA_GetInputParameterInfo(__ta_getFuncHandle(function_name), idx, & info)
688+ cdef const lib.TA_FuncHandle * handle = __ta_getFuncHandle(function_name)
689+ cdef TA_RetCode retCode
690+ with _TA_ReadLease():
691+ with nogil:
692+ retCode = lib.TA_GetInputParameterInfo(handle, idx, & info)
667693 _ta_check_success(' TA_GetInputParameterInfo' , retCode)
668694
669695 name = bytes2str(info.paramName)
@@ -684,7 +710,11 @@ def _ta_getOptInputParameterInfo(char *function_name, int idx):
684710 following keys: name, display_name, type, help, default_value and value.
685711 """
686712 cdef const lib.TA_OptInputParameterInfo * info
687- retCode = lib.TA_GetOptInputParameterInfo(__ta_getFuncHandle(function_name), idx, & info)
713+ cdef const lib.TA_FuncHandle * handle = __ta_getFuncHandle(function_name)
714+ cdef TA_RetCode retCode
715+ with _TA_ReadLease():
716+ with nogil:
717+ retCode = lib.TA_GetOptInputParameterInfo(handle, idx, & info)
688718 _ta_check_success(' TA_GetOptInputParameterInfo' , retCode)
689719
690720 name = bytes2str(info.paramName)
@@ -706,7 +736,11 @@ def _ta_getOutputParameterInfo(char *function_name, int idx):
706736 keys: name and flags.
707737 """
708738 cdef const lib.TA_OutputParameterInfo * info
709- retCode = lib.TA_GetOutputParameterInfo(__ta_getFuncHandle(function_name), idx, & info)
739+ cdef const lib.TA_FuncHandle * handle = __ta_getFuncHandle(function_name)
740+ cdef TA_RetCode retCode
741+ with _TA_ReadLease():
742+ with nogil:
743+ retCode = lib.TA_GetOutputParameterInfo(handle, idx, & info)
710744 _ta_check_success(' TA_GetOutputParameterInfo' , retCode)
711745
712746 name = bytes2str(info.paramName)
@@ -778,15 +812,23 @@ cdef const lib.TA_FuncHandle* __ta_getFuncHandle(char *function_name):
778812 Returns a pointer to a function handle for the given function name
779813 """
780814 cdef const lib.TA_FuncHandle * handle
781- _ta_check_success(' TA_GetFuncHandle' , lib.TA_GetFuncHandle(function_name, & handle))
815+ cdef TA_RetCode retCode
816+ with _TA_ReadLease():
817+ with nogil:
818+ retCode = lib.TA_GetFuncHandle(function_name, & handle)
819+ _ta_check_success(' TA_GetFuncHandle' , retCode)
782820 return handle
783821
784822cdef lib.TA_ParamHolder* __ta_paramHolderAlloc(char * function_name):
785823 """
786824 Returns a pointer to a parameter holder for the given function name
787825 """
788826 cdef lib.TA_ParamHolder * holder
789- retCode = lib.TA_ParamHolderAlloc(__ta_getFuncHandle(function_name), & holder)
827+ cdef const lib.TA_FuncHandle * handle = __ta_getFuncHandle(function_name)
828+ cdef TA_RetCode retCode
829+ with _TA_ReadLease():
830+ with nogil:
831+ retCode = lib.TA_ParamHolderAlloc(handle, & holder)
790832 _ta_check_success(' TA_ParamHolderAlloc' , retCode)
791833 return holder
792834
@@ -795,18 +837,28 @@ cdef int __ta_paramHolderFree(lib.TA_ParamHolder *params):
795837 Frees the memory allocated by __ta_paramHolderAlloc (call when done with the parameter holder)
796838 WARNING: Not properly calling this function will cause memory leaks!
797839 """
798- _ta_check_success(' TA_ParamHolderFree' , lib.TA_ParamHolderFree(params))
840+ cdef TA_RetCode retCode
841+ with nogil:
842+ retCode = lib.TA_ParamHolderFree(params)
843+ _ta_check_success(' TA_ParamHolderFree' , retCode)
799844
800845cdef int __ta_setOptInputParamInteger(lib.TA_ParamHolder * holder, int idx, int value):
801- retCode = lib.TA_SetOptInputParamInteger(holder, idx, value)
846+ cdef TA_RetCode retCode
847+ with nogil:
848+ retCode = lib.TA_SetOptInputParamInteger(holder, idx, value)
802849 _ta_check_success(' TA_SetOptInputParamInteger' , retCode)
803850
804851cdef int __ta_setOptInputParamReal(lib.TA_ParamHolder * holder, int idx, double value):
805- retCode = lib.TA_SetOptInputParamReal(holder, idx, value)
852+ cdef TA_RetCode retCode
853+ with nogil:
854+ retCode = lib.TA_SetOptInputParamReal(holder, idx, value)
806855 _ta_check_success(' TA_SetOptInputParamReal' , retCode)
807856
808857cdef int __ta_getLookback(lib.TA_ParamHolder * holder):
809858 cdef int lookback
810- retCode = lib.TA_GetLookback(holder, & lookback)
859+ cdef TA_RetCode retCode
860+ with _TA_ReadLease():
861+ with nogil:
862+ retCode = lib.TA_GetLookback(holder, & lookback)
811863 _ta_check_success(' TA_GetLookback' , retCode)
812864 return lookback
0 commit comments