Header tweaking.

pull/13171/head
Joshua Haberman 13 years ago
parent f226554fa5
commit 2054853964
  1. 30
      bindings/cpp/upb/def.hpp
  2. 16
      upb/def.h

@ -6,6 +6,36 @@
* *
* The set of upb::*Def classes and upb::SymbolTable allow for defining and * The set of upb::*Def classes and upb::SymbolTable allow for defining and
* manipulating schema information (as defined in .proto files). * manipulating schema information (as defined in .proto files).
*
* Defs go through two distinct phases of life:
*
* 1. MUTABLE: when first created, the properties of the def can be set freely
* (for example a message's name, its list of fields, the name/number of
* fields, etc). During this phase the def is *not* thread-safe, and may
* not be used for any purpose except to set its properties (it can't be
* used to parse anything, create any messages in memory, etc).
*
* 2. FINALIZED: after being added to a symtab (which links the defs together)
* the defs become finalized (thread-safe and immutable). Programs may only
* access defs through a CONST POINTER during this stage -- upb_symtab will
* help you out with this requirement by only vending const pointers, but
* you need to make sure not to use any non-const pointers you still have
* sitting around. In practice this means that you may not call any setters
* on the defs (or functions that themselves call the setters). If you want
* to modify an existing immutable def, copy it with upb_*_dup(), modify the
* copy, and add the modified def to the symtab (replacing the existing
* def).
*
* You can test for which stage of life a def is in by calling
* upb::Def::IsMutable(). This is particularly useful for dynamic language
* bindings, which must properly guarantee that the dynamic language cannot
* break the rules laid out above.
*
* It would be possible to make the defs thread-safe during stage 1 by using
* mutexes internally and changing any methods returning pointers to return
* copies instead. This could be important if we are integrating with a VM or
* interpreter that does not naturally serialize access to wrapped objects (for
* example, in the case of Python this is not necessary because of the GIL).
*/ */
#ifndef UPB_DEF_HPP #ifndef UPB_DEF_HPP

@ -20,14 +20,14 @@
* not be used for any purpose except to set its properties (it can't be * not be used for any purpose except to set its properties (it can't be
* used to parse anything, create any messages in memory, etc). * used to parse anything, create any messages in memory, etc).
* *
* 2. IMMUTABLE: after being added to a symtab (which links the defs together) * 2. FINALIZED: after being added to a symtab (which links the defs together)
* the defs become thread-safe and immutable. Programs may only access defs * the defs become finalized (thread-safe and immutable). Programs may only
* through a CONST POINTER during this stage -- upb_symtab will help you out * access defs through a CONST POINTER during this stage -- upb_symtab will
* with this requirement by only vending const pointers, but you need to * help you out with this requirement by only vending const pointers, but
* make sure not to use any non-const pointers you still have sitting * you need to make sure not to use any non-const pointers you still have
* around. In practice this means that you may not call any setters on the * sitting around. In practice this means that you may not call any setters
* defs (or functions that themselves call the setters). If you want to * on the defs (or functions that themselves call the setters). If you want
* modify an existing immutable def, copy it with upb_*_dup(), modify the * to modify an existing immutable def, copy it with upb_*_dup(), modify the
* copy, and add the modified def to the symtab (replacing the existing * copy, and add the modified def to the symtab (replacing the existing
* def). * def).
* *

Loading…
Cancel
Save