@@ -16,7 +16,7 @@ namespace nd {
1616 {
1717 if (ufunc != NULL ) {
1818 // Acquire the GIL for the python decref
19- PyGILState_RAII pgs;
19+ with_gil pgs;
2020 Py_DECREF (ufunc);
2121 }
2222 }
@@ -26,8 +26,7 @@ namespace nd {
2626 struct scalar_ufunc_ck ;
2727
2828 template <>
29- struct scalar_ufunc_ck <false >
30- : dynd::nd::base_strided_kernel<scalar_ufunc_ck<false >, 1 > {
29+ struct scalar_ufunc_ck <false > : dynd::nd::base_strided_kernel<scalar_ufunc_ck<false >, 1 > {
3130 typedef scalar_ufunc_ck self_type;
3231
3332 const scalar_ufunc_data *data;
@@ -47,46 +46,34 @@ namespace nd {
4746 data->funcptr (args, &dimsize, strides, data->ufunc_data );
4847 }
4948
50- void strided (char *dst, intptr_t dst_stride, char *const *src,
51- const intptr_t *src_stride, size_t count)
49+ void strided (char *dst, intptr_t dst_stride, char *const *src, const intptr_t *src_stride, size_t count)
5250 {
5351 char *args[NPY_MAXARGS ];
5452 // Set up the args array the way the numpy ufunc wants it
5553 memcpy (&args[0 ], &src[0 ], data->param_count * sizeof (void *));
5654 args[data->param_count ] = dst;
5755 // Call the ufunc loop with a dim size of 1
5856 intptr_t strides[NPY_MAXARGS ];
59- memcpy (&strides[0 ], &src_stride[0 ],
60- data->param_count * sizeof (intptr_t ));
57+ memcpy (&strides[0 ], &src_stride[0 ], data->param_count * sizeof (intptr_t ));
6158 strides[data->param_count ] = dst_stride;
62- data->funcptr (args, reinterpret_cast <intptr_t *>(&count), strides,
63- data->ufunc_data );
59+ data->funcptr (args, reinterpret_cast <intptr_t *>(&count), strides, data->ufunc_data );
6460 }
6561
66- static void
67- instantiate (char *static_data, char *DYND_UNUSED (data),
68- kernel_builder *ckb, intptr_t ckb_offset,
69- const dynd::ndt::type &dst_tp,
70- const char *DYND_UNUSED (dst_arrmeta),
71- intptr_t DYND_UNUSED (nsrc), const dynd::ndt::type *src_tp,
72- const char *const *DYND_UNUSED(src_arrmeta),
73- dynd::kernel_request_t kernreq,
74- const dynd::eval::eval_context *DYND_UNUSED(ectx),
75- intptr_t nkwd, const dynd::nd::array *kwds,
76- const std::map<std::string, dynd::ndt::type> &tp_vars)
62+ static void instantiate (char *static_data, char *DYND_UNUSED (data), kernel_builder *ckb, intptr_t ckb_offset,
63+ const dynd::ndt::type &dst_tp, const char *DYND_UNUSED(dst_arrmeta),
64+ intptr_t DYND_UNUSED(nsrc), const dynd::ndt::type *src_tp,
65+ const char *const *DYND_UNUSED(src_arrmeta), dynd::kernel_request_t kernreq,
66+ const dynd::eval::eval_context *DYND_UNUSED(ectx), intptr_t nkwd,
67+ const dynd::nd::array *kwds, const std::map<std::string, dynd::ndt::type> &tp_vars)
7768 {
7869 // Acquire the GIL for creating the ckernel
79- PyGILState_RAII pgs;
80- self_type::make (
81- ckb, kernreq,
82- reinterpret_cast <std::shared_ptr<scalar_ufunc_data> *>(static_data)
83- ->get ());
70+ with_gil pgs;
71+ self_type::make (ckb, kernreq, reinterpret_cast <std::shared_ptr<scalar_ufunc_data> *>(static_data)->get ());
8472 }
8573 };
8674
8775 template <>
88- struct scalar_ufunc_ck <true >
89- : dynd::nd::base_strided_kernel<scalar_ufunc_ck<true >, 1 > {
76+ struct scalar_ufunc_ck <true > : dynd::nd::base_strided_kernel<scalar_ufunc_ck<true >, 1 > {
9077 typedef scalar_ufunc_ck self_type;
9178
9279 const scalar_ufunc_data *data;
@@ -104,47 +91,38 @@ namespace nd {
10491 intptr_t strides[NPY_MAXARGS ];
10592 memset (strides, 0 , (data->param_count + 1 ) * sizeof (void *));
10693 {
107- PyGILState_RAII pgs;
94+ with_gil pgs;
10895 data->funcptr (args, &dimsize, strides, data->ufunc_data );
10996 }
11097 }
11198
112- void strided (char *dst, intptr_t dst_stride, char *const *src,
113- const intptr_t *src_stride, size_t count)
99+ void strided (char *dst, intptr_t dst_stride, char *const *src, const intptr_t *src_stride, size_t count)
114100 {
115101 char *args[NPY_MAXARGS ];
116102 // Set up the args array the way the numpy ufunc wants it
117103 memcpy (&args[0 ], &src[0 ], data->param_count * sizeof (void *));
118104 args[data->param_count ] = dst;
119105 // Call the ufunc loop with a dim size of 1
120106 intptr_t strides[NPY_MAXARGS ];
121- memcpy (&strides[0 ], &src_stride[0 ],
122- data->param_count * sizeof (intptr_t ));
107+ memcpy (&strides[0 ], &src_stride[0 ], data->param_count * sizeof (intptr_t ));
123108 strides[data->param_count ] = dst_stride;
124109 {
125- PyGILState_RAII pgs;
126- data->funcptr (args, reinterpret_cast <intptr_t *>(&count), strides,
127- data->ufunc_data );
110+ with_gil pgs;
111+ data->funcptr (args, reinterpret_cast <intptr_t *>(&count), strides, data->ufunc_data );
128112 }
129113 }
130114
131- static intptr_t
132- instantiate (char *static_data, char *DYND_UNUSED (data), void *ckb,
133- intptr_t ckb_offset, const dynd::ndt::type &dst_tp,
134- const char *DYND_UNUSED (dst_arrmeta),
135- intptr_t DYND_UNUSED (nsrc), const dynd::ndt::type *src_tp,
136- const char *const *DYND_UNUSED(src_arrmeta),
137- dynd::kernel_request_t kernreq,
138- const dynd::eval::eval_context *DYND_UNUSED(ectx),
139- intptr_t nkwd, const dynd::nd::array *kwds,
140- const std::map<std::string, dynd::ndt::type> &tp_vars)
115+ static intptr_t instantiate (char *static_data, char *DYND_UNUSED (data), void *ckb, intptr_t ckb_offset,
116+ const dynd::ndt::type &dst_tp, const char *DYND_UNUSED(dst_arrmeta),
117+ intptr_t DYND_UNUSED(nsrc), const dynd::ndt::type *src_tp,
118+ const char *const *DYND_UNUSED(src_arrmeta), dynd::kernel_request_t kernreq,
119+ const dynd::eval::eval_context *DYND_UNUSED(ectx), intptr_t nkwd,
120+ const dynd::nd::array *kwds, const std::map<std::string, dynd::ndt::type> &tp_vars)
141121 {
142122 // Acquire the GIL for creating the ckernel
143- PyGILState_RAII pgs;
144- self_type::make (
145- ckb, kernreq, ckb_offset,
146- reinterpret_cast <std::shared_ptr<scalar_ufunc_data> *>(static_data)
147- ->get ());
123+ with_gil pgs;
124+ self_type::make (ckb, kernreq, ckb_offset,
125+ reinterpret_cast <std::shared_ptr<scalar_ufunc_data> *>(static_data)->get ());
148126 return ckb_offset;
149127 }
150128 };
0 commit comments