  Definition of the partition function of U(1) gauge theory is extended to a
class of four-manifolds containing all compact spaces and certain
asymptotically locally flat (ALF) ones including the multi-Taub--NUT spaces.
The partition function is calculated via zeta-function regularization with
special attention to its modular properties. In the compact case, compared with
the purely topological result of Witten, we find a non-trivial curvature
correction to the modular weights of the partition function. But S-duality can
be restored by adding gravitational counter terms to the Lagrangian in the
usual way. In the ALF case however we encounter non-trivial difficulties
stemming from original non-compact ALF phenomena. Fortunately our careful
definition of the partition function makes it possible to circumnavigate them
and conclude that the partition function has the same modular properties as in
the compact case.
