RPA Toolkit
Modified documentation and exaples. Removed RPA_RECORD_INVALID_UID.
authorMartin Stoilov <martin@rpasearch.com>
Sat, 2 Jul 2011 05:11:03 +0000 (22:11 -0700)
committerMartin Stoilov <martin@rpasearch.com>
Sat, 2 Jul 2011 05:11:03 +0000 (22:11 -0700)
rpa/doc/example/personname.c
rpa/rpadbex.c
rpa/rparecord.h

index 0742eee..0eda53e 100644 (file)
@@ -58,8 +58,12 @@ int main(int argc, char *argv[])
                        fprintf(stdout, "RPA_RECORD_START   (UID: %d)  ", record->ruleuid);
                if (record->type == RPA_RECORD_END)
                        fprintf(stdout, "RPA_RECORD_END     (UID: %d)  ", record->ruleuid);
-               fprintf(stdout, "%s: ", rpa_dbex_name(dbex, record->ruleid));
-               fwrite(&name[record->inputoff], 1, record->inputsiz, stdout);
+               /*
+                * record->rule points to memory allocated by rpadbex_t,
+                * make sure rpadbex_t object is not destroyed while accessing this pointer.
+                */
+               fprintf(stdout, "%s: ", record->rule);
+               fwrite(record->input, 1, record->inputsiz, stdout);
                fprintf(stdout, "\n");
        }
        rpa_records_destroy(records);
index 5eeded7..f85e7c1 100644 (file)
@@ -1245,11 +1245,11 @@ static rlong rpa_dbex_copy_handler(rarray_t *records, rlong rec, rpointer userda
                lastrec = r_array_length(dbex->records) - 1;
                if (lastrec >= 0)
                        rpa_record_setusertype(dbex->records, lastrec, usertype, RVALSET_OR);
-       } else if (prec->ruleuid != RPA_RECORD_INVALID_UID) {
+       } else if (prec->ruleuid) {
                index = r_array_add(dbex->records, prec);
                /*
                 * Optimizations. Lets apply the optimizations while we copy the records.
-                * This is probably not the most clean way to apply optimizations, in the future
+                * This is probably not the most clean way to apply optimizations. In the future
                 * we should probably think of optimization pass right before compiling.
                 */
                if (dbex->optimizations) {
index aaabd87..89f9b8f 100644 (file)
@@ -75,7 +75,6 @@ extern "C" {
 #define RPA_RECORD_NONE (0)                                            /**< No record type - the record type is not initialized */
 #define RPA_RECORD_START (1 << 0)                              /**< Start record - the parser generates this record before evaluating the rule. */
 #define RPA_RECORD_END (1 << 1)                                        /**< End record - the parser generates this record after evaluating the rule and the rule matched some input. */
-#define RPA_RECORD_INVALID_UID ((ruint32)-1)
 
 /**
  * typedef rparecord_t
@@ -95,8 +94,10 @@ typedef rlong (*rpa_recordtree_callback)(rarray_t *records, rlong rec, rpointer
 struct rparecord_s {
        ruint32 top;                    /**< This is a private member, used by the engine and is not significant to the user */
        ruint32 size;                   /**< This is a private member, used by the engine and is not significant to the user */
-       const rchar *rule;              /**< Name of the rule that generated this record */
-       const rchar *input;             /**< Pointer in the input stream */
+       const rchar *rule;              /**< Name of the rule that generated this record. This pointer points to memory allocated
+                                                        *   inside @ref rpadbex_t, so make sure rpadbex_t object is still valid while accessing this pointer. */
+       const rchar *input;             /**< Pointer in the input stream. This pointer points to memory inside the input buffer
+                                                        *   passed to @ref rpa_stat_parse, make sure this memory is still valid while accessing this pointer. */
        rsize_t inputoff;               /**< Input offset, calculated from the start parameter passed to @ref rpa_stat_parse */
        rsize_t inputsiz;               /**< Size of input */
        ruint32 type;                   /**< Record Type: @ref RPA_RECORD_START or @ref RPA_RECORD_END */