Skip to content

Commit

Permalink
Step 1 in splitting PR 3068
Browse files Browse the repository at this point in the history
re: PR Unidata#3068

Update the ncjson and ncproplist code to lastest.
  • Loading branch information
DennisHeimbigner committed Feb 5, 2025
1 parent 909d7e4 commit b6c3485
Show file tree
Hide file tree
Showing 7 changed files with 182 additions and 110 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/main-cmake.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name: NetCDF-C CMake CI - Windows

on: [ pull_request, workflow_dispatch]
on: [push, pull_request, workflow_dispatch]

env:
REMOTETESTDOWN: ${{ vars.REMOTETESTDOWN }}
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/run_tests_osx.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

name: Run macOS-based netCDF Tests

on: [pull_request,workflow_dispatch]
on: [push,pull_request,workflow_dispatch]

concurrency:
group: ${{ github.workflow}}-${{ github.head_ref }}
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/run_tests_ubuntu.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

name: Run Ubuntu/Linux netCDF Tests

on: [pull_request,workflow_dispatch]
on: [push,pull_request,workflow_dispatch]

env:
REMOTETESTDOWN: ${{ vars.REMOTETESTDOWN }}
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/run_tests_win_cygwin.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name: Run Cygwin-based tests

on: [pull_request,workflow_dispatch]
on: [push,pull_request,workflow_dispatch]

concurrency:
group: ${{ github.workflow}}-${{ github.head_ref }}
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/run_tests_win_mingw.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ env:
CPPFLAGS: "-D_BSD_SOURCE"
REMOTETESTDOWN: ${{ vars.REMOTETESTDOWN }}

on: [pull_request,workflow_dispatch]
on: [push,pull_request,workflow_dispatch]

concurrency:
group: ${{ github.workflow}}-${{ github.head_ref }}
Expand Down
76 changes: 51 additions & 25 deletions include/ncproplist.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,16 @@
/**************************************************/
/*
This is used to store a property list mapping a small number of
fixed-sized key strings to an arbitrary uintptr_t value. The
uintptr_t type is used to ensure that the value can be a pointer or a
small string upto sizeof(uintptr_t) - 1 (for trailing nul). The big
problem is reclaiming the value if it a pointer. The fact that the
number of keys is small makes it feasible to use linear search.
This is currently only used for plugins, but may be extended to other uses.
keys to objects. The uintptr_t type is used to ensure that the value can be a pointer or a
small string upto sizeof(uintptr_t) - 1 (for trailing nul) or an integer constant.
There are two operations that may be defined for the property:
1. reclaiming the value when proplist is free'd and property value points to allocated data of arbitrary complexity.
2. coping the value (for cloning) if it points to allocated data of arbitrary complexity.
The fact that the number of keys is small makes it feasible to use
linear search. This is currently only used for plugins, but may be
extended to other uses.
*/

/*! Proplist-related structs.
Expand All @@ -38,31 +42,48 @@ This is currently only used for plugins, but may be extended to other uses.
1. It is critical that |uintptr_t| == |void*|
*/

#define NCPROPSMAXKEY 31 /* characters assert (NCPROPSMAXKEY+1)/8 == 0*/
#define NCPROPSMAXKEY 31 /* characters; assert (NCPROPSMAXKEY+1)/8 == 0*/

/* Returns 0 => error; 1 => success */
typedef int (*NCPreclaimfcn)(uintptr_t userdata, const char* key, void* value, uintptr_t size);
/* Opaque forward */
struct NCPpair;

/* The property list proper is a sequence of these objects */
typedef struct NCProperty {
/* This function performs all of the following operations on a complex type */
typedef enum NCPtypeop {NCP_RECLAIM=1,NCP_COPY=2} NCPtypeop;

/* There are three possible types for a property value */
typedef enum NCPtype {
NCP_CONST=0, /* Value is a simple uintptr_t constant */
NCP_BYTES=2, /* Value points to a counted sequence of bytes; If a string,
then it includes the nul term character */
NCP_COMPLEX=3 /* Value points to an arbitraryily complex structure */
} NCPtype;

/* (Returns < 0 => error) (>= 0 => success) */
typedef int (*NCPtypefcn)(NCPtypeop op, struct NCPpair* input, struct NCPpair* output);

/* Expose this prefix of NCProperty; used in clone and lookup */
/* Hold just the key+value pair */
typedef struct NCPpair {
char key[NCPROPSMAXKEY+1]; /* copy of the key string; +1 for trailing nul */
uintptr_t flags;
# define NCPF_SIMPLE (1<<0) /* non-reclaimable */
# define NCPF_BYTES (1<<1) /* reclaimable bytes */
# define NCPF_COMPLEX (1<<2) /* extended case */
NCPtype sort;
uintptr_t value;
uintptr_t size; /* size = |value| as ptr to memory, if string, then include trailing nul */
uintptr_t userdata; /* extra data for following functions */
NCPreclaimfcn reclaim;
} NCProperty;
} NCPpair;

/* The property list proper is a sequence of these objects */
typedef struct NCPproperty {
NCPpair pair; /* Allowed by C language standard */
uintptr_t userdata; /* extra data for the type function */
NCPtypefcn typefcn; /* Process type operations */
} NCPproperty;

/*
The property list object.
*/
typedef struct NCproplist {
size_t alloc; /* allocated space to hold properties */
size_t count; /* # of defined properties */
NCProperty* properties;
NCPproperty* properties;
} NCproplist;

/**************************************************/
Expand All @@ -72,19 +93,24 @@ typedef struct NCproplist {
extern "C" {
#endif

/* All int valued functions return < 0 if error; >= 0 otherwise */


/* Create, free, etc. */
OPTEXPORT NCproplist* ncproplistnew(void);
OPTEXPORT int ncproplistfree(NCproplist*);

/* Locate a proplist entry */
OPTEXPORT int ncproplistadd(NCproplist* plist,const char* key, uintptr_t value); /* use when reclaim not needed */

/* Insert properties */
OPTEXPORT int ncproplistadd(NCproplist* plist,const char* key, uintptr_t value); /* use when reclaim not needed */
OPTEXPORT int ncproplistaddstring(NCproplist* plist, const char* key, const char* str); /* use when value is simple string (char*) */
OPTEXPORT int ncproplistaddbytes(NCproplist* plist, const char* key, void* value, uintptr_t size); /* use when value is simple ptr and reclaim is simple free function */
OPTEXPORT int ncproplistaddx(NCproplist* plist, const char* key, void* value, uintptr_t size, uintptr_t userdata, NCPreclaimfcn); /* fully extended case */

/* Insert an instance of type NCP_BYTES */
OPTEXPORT int ncproplistaddbytes(NCproplist* plist, const char* key, void* value, uintptr_t size);

/* Add instance of a complex type */
OPTEXPORT int ncproplistaddx(NCproplist* plist, const char* key, void* value, uintptr_t size, uintptr_t userdata, NCPtypefcn typefcn);

/* clone; keys are copies and values are copied using the NCPtypefcn */
OPTEXPORT int ncproplistclone(const NCproplist* src, NCproplist* clone);

/*
Expand All @@ -105,4 +131,4 @@ OPTEXPORT int ncproplistith(const NCproplist*, size_t i, char* const * keyp, uin
}
#endif

#endif /*NCPROPLIST_H*/
#endif /*!NCPROPLIST_H*/ /* WARNING: Do not remove the !; used in building netcdf_proplist.h */
Loading

0 comments on commit b6c3485

Please sign in to comment.