Commit 48409561 authored by Stefan Behnel's avatar Stefan Behnel

avoid redundantly recreating templated utility code

parent 374eb179
...@@ -393,7 +393,7 @@ class CTypedefType(BaseType): ...@@ -393,7 +393,7 @@ class CTypedefType(BaseType):
base_type = self.typedef_base_type base_type = self.typedef_base_type
if type(base_type) is CIntType: if type(base_type) is CIntType:
self.to_py_function = "__Pyx_PyInt_From_" + self.specialization_name() self.to_py_function = "__Pyx_PyInt_From_" + self.specialization_name()
env.use_utility_code(TempitaUtilityCode.load( env.use_utility_code(TempitaUtilityCode.load_cached(
"CIntToPy", "TypeConversion.c", "CIntToPy", "TypeConversion.c",
context={"TYPE": self.empty_declaration_code(), context={"TYPE": self.empty_declaration_code(),
"TO_PY_FUNCTION": self.to_py_function})) "TO_PY_FUNCTION": self.to_py_function}))
...@@ -415,7 +415,7 @@ class CTypedefType(BaseType): ...@@ -415,7 +415,7 @@ class CTypedefType(BaseType):
base_type = self.typedef_base_type base_type = self.typedef_base_type
if type(base_type) is CIntType: if type(base_type) is CIntType:
self.from_py_function = "__Pyx_PyInt_As_" + self.specialization_name() self.from_py_function = "__Pyx_PyInt_As_" + self.specialization_name()
env.use_utility_code(TempitaUtilityCode.load( env.use_utility_code(TempitaUtilityCode.load_cached(
"CIntFromPy", "TypeConversion.c", "CIntFromPy", "TypeConversion.c",
context={"TYPE": self.empty_declaration_code(), context={"TYPE": self.empty_declaration_code(),
"FROM_PY_FUNCTION": self.from_py_function})) "FROM_PY_FUNCTION": self.from_py_function}))
...@@ -450,17 +450,17 @@ class CTypedefType(BaseType): ...@@ -450,17 +450,17 @@ class CTypedefType(BaseType):
type = self.empty_declaration_code() type = self.empty_declaration_code()
name = self.specialization_name() name = self.specialization_name()
if binop == "lshift": if binop == "lshift":
env.use_utility_code(TempitaUtilityCode.load( env.use_utility_code(TempitaUtilityCode.load_cached(
"LeftShift", "Overflow.c", "LeftShift", "Overflow.c",
context={'TYPE': type, 'NAME': name, 'SIGNED': self.signed})) context={'TYPE': type, 'NAME': name, 'SIGNED': self.signed}))
else: else:
if const_rhs: if const_rhs:
binop += "_const" binop += "_const"
_load_overflow_base(env) _load_overflow_base(env)
env.use_utility_code(TempitaUtilityCode.load( env.use_utility_code(TempitaUtilityCode.load_cached(
"SizeCheck", "Overflow.c", "SizeCheck", "Overflow.c",
context={'TYPE': type, 'NAME': name})) context={'TYPE': type, 'NAME': name}))
env.use_utility_code(TempitaUtilityCode.load( env.use_utility_code(TempitaUtilityCode.load_cached(
"Binop", "Overflow.c", "Binop", "Overflow.c",
context={'TYPE': type, 'NAME': name, 'BINOP': binop})) context={'TYPE': type, 'NAME': name, 'BINOP': binop}))
return "__Pyx_%s_%s_checking_overflow" % (binop, name) return "__Pyx_%s_%s_checking_overflow" % (binop, name)
...@@ -697,10 +697,9 @@ class MemoryViewSliceType(PyrexType): ...@@ -697,10 +697,9 @@ class MemoryViewSliceType(PyrexType):
# We don't have 'code', so use a LazyUtilityCode with a callback. # We don't have 'code', so use a LazyUtilityCode with a callback.
def lazy_utility_callback(code): def lazy_utility_callback(code):
context['dtype_typeinfo'] = Buffer.get_type_information_cname( context['dtype_typeinfo'] = Buffer.get_type_information_cname(code, self.dtype)
code, self.dtype)
return TempitaUtilityCode.load( return TempitaUtilityCode.load(
"ObjectToMemviewSlice", "MemoryView_C.c", context=context) "ObjectToMemviewSlice", "MemoryView_C.c", context=context)
env.use_utility_code(Buffer.acquire_utility_code) env.use_utility_code(Buffer.acquire_utility_code)
env.use_utility_code(MemoryView.memviewslice_init_code) env.use_utility_code(MemoryView.memviewslice_init_code)
...@@ -777,8 +776,8 @@ class MemoryViewSliceType(PyrexType): ...@@ -777,8 +776,8 @@ class MemoryViewSliceType(PyrexType):
error_condition = error_condition, error_condition = error_condition,
) )
utility = TempitaUtilityCode.load( utility = TempitaUtilityCode.load_cached(
utility_name, "MemoryView_C.c", context=context) utility_name, "MemoryView_C.c", context=context)
env.use_utility_code(utility) env.use_utility_code(utility)
return get_function, set_function return get_function, set_function
...@@ -1490,7 +1489,7 @@ class CIntType(CNumericType): ...@@ -1490,7 +1489,7 @@ class CIntType(CNumericType):
def create_to_py_utility_code(self, env): def create_to_py_utility_code(self, env):
if type(self).to_py_function is None: if type(self).to_py_function is None:
self.to_py_function = "__Pyx_PyInt_From_" + self.specialization_name() self.to_py_function = "__Pyx_PyInt_From_" + self.specialization_name()
env.use_utility_code(TempitaUtilityCode.load( env.use_utility_code(TempitaUtilityCode.load_cached(
"CIntToPy", "TypeConversion.c", "CIntToPy", "TypeConversion.c",
context={"TYPE": self.empty_declaration_code(), context={"TYPE": self.empty_declaration_code(),
"TO_PY_FUNCTION": self.to_py_function})) "TO_PY_FUNCTION": self.to_py_function}))
...@@ -1499,7 +1498,7 @@ class CIntType(CNumericType): ...@@ -1499,7 +1498,7 @@ class CIntType(CNumericType):
def create_from_py_utility_code(self, env): def create_from_py_utility_code(self, env):
if type(self).from_py_function is None: if type(self).from_py_function is None:
self.from_py_function = "__Pyx_PyInt_As_" + self.specialization_name() self.from_py_function = "__Pyx_PyInt_As_" + self.specialization_name()
env.use_utility_code(TempitaUtilityCode.load( env.use_utility_code(TempitaUtilityCode.load_cached(
"CIntFromPy", "TypeConversion.c", "CIntFromPy", "TypeConversion.c",
context={"TYPE": self.empty_declaration_code(), context={"TYPE": self.empty_declaration_code(),
"FROM_PY_FUNCTION": self.from_py_function})) "FROM_PY_FUNCTION": self.from_py_function}))
...@@ -1539,18 +1538,18 @@ class CIntType(CNumericType): ...@@ -1539,18 +1538,18 @@ class CIntType(CNumericType):
type = self.empty_declaration_code() type = self.empty_declaration_code()
name = self.specialization_name() name = self.specialization_name()
if binop == "lshift": if binop == "lshift":
env.use_utility_code(TempitaUtilityCode.load( env.use_utility_code(TempitaUtilityCode.load_cached(
"LeftShift", "Overflow.c", "LeftShift", "Overflow.c",
context={'TYPE': type, 'NAME': name, 'SIGNED': self.signed})) context={'TYPE': type, 'NAME': name, 'SIGNED': self.signed}))
else: else:
if const_rhs: if const_rhs:
binop += "_const" binop += "_const"
if type in ('int', 'long', 'long long'): if type in ('int', 'long', 'long long'):
env.use_utility_code(TempitaUtilityCode.load( env.use_utility_code(TempitaUtilityCode.load_cached(
"BaseCaseSigned", "Overflow.c", "BaseCaseSigned", "Overflow.c",
context={'INT': type, 'NAME': name})) context={'INT': type, 'NAME': name}))
elif type in ('unsigned int', 'unsigned long', 'unsigned long long'): elif type in ('unsigned int', 'unsigned long', 'unsigned long long'):
env.use_utility_code(TempitaUtilityCode.load( env.use_utility_code(TempitaUtilityCode.load_cached(
"BaseCaseUnsigned", "Overflow.c", "BaseCaseUnsigned", "Overflow.c",
context={'UINT': type, 'NAME': name})) context={'UINT': type, 'NAME': name}))
elif self.rank <= 1: elif self.rank <= 1:
...@@ -1558,22 +1557,23 @@ class CIntType(CNumericType): ...@@ -1558,22 +1557,23 @@ class CIntType(CNumericType):
return "__Pyx_%s_%s_no_overflow" % (binop, name) return "__Pyx_%s_%s_no_overflow" % (binop, name)
else: else:
_load_overflow_base(env) _load_overflow_base(env)
env.use_utility_code(TempitaUtilityCode.load( env.use_utility_code(TempitaUtilityCode.load_cached(
"SizeCheck", "Overflow.c", "SizeCheck", "Overflow.c",
context={'TYPE': type, 'NAME': name})) context={'TYPE': type, 'NAME': name}))
env.use_utility_code(TempitaUtilityCode.load( env.use_utility_code(TempitaUtilityCode.load_cached(
"Binop", "Overflow.c", "Binop", "Overflow.c",
context={'TYPE': type, 'NAME': name, 'BINOP': binop})) context={'TYPE': type, 'NAME': name, 'BINOP': binop}))
return "__Pyx_%s_%s_checking_overflow" % (binop, name) return "__Pyx_%s_%s_checking_overflow" % (binop, name)
def _load_overflow_base(env): def _load_overflow_base(env):
env.use_utility_code(UtilityCode.load("Common", "Overflow.c")) env.use_utility_code(UtilityCode.load("Common", "Overflow.c"))
for type in ('int', 'long', 'long long'): for type in ('int', 'long', 'long long'):
env.use_utility_code(TempitaUtilityCode.load( env.use_utility_code(TempitaUtilityCode.load_cached(
"BaseCaseSigned", "Overflow.c", "BaseCaseSigned", "Overflow.c",
context={'INT': type, 'NAME': type.replace(' ', '_')})) context={'INT': type, 'NAME': type.replace(' ', '_')}))
for type in ('unsigned int', 'unsigned long', 'unsigned long long'): for type in ('unsigned int', 'unsigned long', 'unsigned long long'):
env.use_utility_code(TempitaUtilityCode.load( env.use_utility_code(TempitaUtilityCode.load_cached(
"BaseCaseUnsigned", "Overflow.c", "BaseCaseUnsigned", "Overflow.c",
context={'UINT': type, 'NAME': type.replace(' ', '_')})) context={'UINT': type, 'NAME': type.replace(' ', '_')}))
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment