@@ -176,100 +176,46 @@ ly_err_new(struct ly_err_item **err, LY_ERR ecode, LY_VECODE vecode, char *data_
176176 return e -> err ;
177177}
178178
179- static struct ly_ctx_data_err *
180- ly_err_data_get (const struct ly_ctx * ctx )
181- {
182- struct ly_ctx_data * ctx_data ;
183- pthread_t tid = pthread_self ();
184- uint32_t i ;
185- struct ly_ctx_data_err * data_err = NULL ;
186-
187- /* get context data */
188- ctx_data = ly_ctx_data_get (ctx );
189-
190- /* ERR READ LOCK */
191- pthread_rwlock_rdlock (& ctx_data -> err_rwlock );
192-
193- /* find the thread-specific err */
194- for (i = 0 ; i < ctx_data -> err_count ; ++ i ) {
195- if (!memcmp (& ctx_data -> errs [i ]-> tid , & tid , sizeof tid )) {
196- data_err = ctx_data -> errs [i ];
197- goto cleanup ;
198- }
199- }
200-
201- /* ERR UNLOCK */
202- pthread_rwlock_unlock (& ctx_data -> err_rwlock );
203-
204- /* ERR WRITE LOCK */
205- pthread_rwlock_wrlock (& ctx_data -> err_rwlock );
206-
207- /* no need to retry the search, this thread is executing this function */
208-
209- /* not found, so create it */
210- ctx_data -> errs = ly_realloc (ctx_data -> errs , (ctx_data -> err_count + 1 ) * sizeof * ctx_data -> errs );
211- ctx_data -> errs [ctx_data -> err_count ] = calloc (1 , sizeof * * ctx_data -> errs );
212- memcpy (& ctx_data -> errs [ctx_data -> err_count ]-> tid , & tid , sizeof tid );
213-
214- ++ ctx_data -> err_count ;
215-
216- data_err = ctx_data -> errs [ctx_data -> err_count - 1 ];
217-
218- cleanup :
219- /* ERR UNLOCK */
220- pthread_rwlock_unlock (& ctx_data -> err_rwlock );
221- return data_err ;
222- }
223-
224179LIBYANG_API_DEF const struct ly_err_item *
225180ly_err_first (const struct ly_ctx * ctx )
226181{
227- struct ly_ctx_data_err * err_data ;
228-
229- if (!ctx ) {
230- return NULL ;
231- }
182+ struct ly_ctx_private_data * ctx_data ;
232183
233- /* get context err data */
234- err_data = ly_err_data_get (ctx );
184+ LY_CHECK_ARG_RET (NULL , ctx , NULL );
235185
236- return err_data ? err_data -> err : NULL ;
186+ ctx_data = ly_ctx_private_data_get (ctx );
187+ return ctx_data -> errs ;
237188}
238189
239190LIBYANG_API_DEF const struct ly_err_item *
240191ly_err_last (const struct ly_ctx * ctx )
241192{
242- struct ly_ctx_data_err * err_data ;
243-
244- if (!ctx ) {
245- return NULL ;
246- }
193+ struct ly_ctx_private_data * ctx_data ;
247194
248- /* get context err data */
249- err_data = ly_err_data_get (ctx );
195+ LY_CHECK_ARG_RET (NULL , ctx , NULL );
250196
251- if (!err_data ) {
252- return NULL ;
253- }
254-
255- return err_data -> err ? err_data -> err -> prev : NULL ;
197+ ctx_data = ly_ctx_private_data_get (ctx );
198+ return ctx_data -> errs ? ctx_data -> errs -> prev : NULL ;
256199}
257200
258201void
259202ly_err_move (struct ly_ctx * src_ctx , struct ly_ctx * trg_ctx )
260203{
261- struct ly_ctx_data_err * err_data ;
262- struct ly_err_item * err = NULL ;
204+ struct ly_ctx_private_data * src_data , * trg_data ;
205+ struct ly_err_item * errs = NULL ;
263206
264- /* get src context err data */
265- err_data = ly_err_data_get (src_ctx );
266- err = err_data -> err ;
267- err_data -> err = NULL ;
207+ /* get src context errs */
208+ src_data = ly_ctx_private_data_get (src_ctx );
209+ errs = src_data -> errs ;
210+ src_data -> errs = NULL ;
211+
212+ /* get and free the trg context errs */
213+ trg_data = ly_ctx_private_data_get (trg_ctx );
214+ ly_err_free (trg_data -> errs );
268215
269216 /* set them for trg */
270- err_data = ly_err_data_get (trg_ctx );
271- ly_err_free (err_data -> err );
272- err_data -> err = err ;
217+ ly_err_free (trg_data -> errs );
218+ trg_data -> errs = errs ;
273219}
274220
275221LIBYANG_API_DEF void
@@ -290,24 +236,28 @@ ly_err_free(void *ptr)
290236LIBYANG_API_DEF void
291237ly_err_clean (const struct ly_ctx * ctx , struct ly_err_item * eitem )
292238{
293- struct ly_ctx_data_err * err_data ;
239+ struct ly_ctx_private_data * ctx_data ;
294240 struct ly_err_item * e ;
295241
296- err_data = ly_err_data_get (ctx );
297- if (err_data -> err == eitem ) {
242+ if (!ctx ) {
243+ return ;
244+ }
245+
246+ ctx_data = ly_ctx_private_data_get (ctx );
247+ if (ctx_data -> errs == eitem ) {
298248 eitem = NULL ;
299249 }
300250
301251 if (!eitem ) {
302252 /* free all err */
303- ly_err_free (err_data -> err );
304- err_data -> err = NULL ;
253+ ly_err_free (ctx_data -> errs );
254+ ctx_data -> errs = NULL ;
305255 } else {
306256 /* disconnect the error */
307- for (e = err_data -> err ; e && (e -> next != eitem ); e = e -> next ) {}
257+ for (e = ctx_data -> errs ; e && (e -> next != eitem ); e = e -> next ) {}
308258 assert (e );
309259 e -> next = NULL ;
310- err_data -> err -> prev = e ;
260+ ctx_data -> errs -> prev = e ;
311261
312262 /* free this err and newer */
313263 ly_err_free (eitem );
@@ -456,15 +406,15 @@ static LY_ERR
456406log_store (const struct ly_ctx * ctx , LY_LOG_LEVEL level , LY_ERR err , LY_VECODE vecode , char * msg , char * data_path ,
457407 char * schema_path , uint64_t line , char * apptag )
458408{
459- struct ly_ctx_data_err * err_data ;
409+ struct ly_ctx_private_data * ctx_data ;
460410 struct ly_err_item * e , * last ;
461411
462412 assert (ctx && (level < LY_LLVRB ));
463413
464- /* get context err data */
465- err_data = ly_err_data_get (ctx );
414+ /* get context private data */
415+ ctx_data = ly_ctx_private_data_get (ctx );
466416
467- e = err_data -> err ;
417+ e = ctx_data -> errs ;
468418 if (!e ) {
469419 /* if we are only to fill in path, there must have been an error stored */
470420 assert (msg );
@@ -473,7 +423,7 @@ log_store(const struct ly_ctx *ctx, LY_LOG_LEVEL level, LY_ERR err, LY_VECODE ve
473423 e -> prev = e ;
474424 e -> next = NULL ;
475425
476- err_data -> err = e ;
426+ ctx_data -> errs = e ;
477427 } else if (!msg ) {
478428 /* only filling the path */
479429 assert (data_path || schema_path );
0 commit comments